mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-27 06:14:45 +02:00
Use natural sorting for trees and others repository functions
This commit is contained in:
parent
9db822eabd
commit
8bb8118d9f
13 changed files with 71 additions and 44 deletions
|
@ -30,12 +30,7 @@ use InvalidArgumentException;
|
|||
|
||||
class StorelocationRepository extends AbstractPartsContainingRepository
|
||||
{
|
||||
/**
|
||||
* @param object $element
|
||||
* @param array $order_by
|
||||
* @return array
|
||||
*/
|
||||
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
|
||||
public function getParts(object $element, string $nameOrderDirection = "ASC"): array
|
||||
{
|
||||
if (!$element instanceof StorageLocation) {
|
||||
throw new InvalidArgumentException('$element must be an Storelocation!');
|
||||
|
@ -47,11 +42,9 @@ class StorelocationRepository extends AbstractPartsContainingRepository
|
|||
->from(Part::class, 'part')
|
||||
->leftJoin('part.partLots', 'lots')
|
||||
->where('lots.storage_location = ?1')
|
||||
->setParameter(1, $element);
|
||||
|
||||
foreach ($order_by as $field => $order) {
|
||||
$qb->addOrderBy('part.'.$field, $order);
|
||||
}
|
||||
->setParameter(1, $element)
|
||||
->orderBy('NATSORT(part.name)', $nameOrderDirection)
|
||||
;
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue