mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-07 07:48:10 +01:00
Use natural sorting for trees and others repository functions
This commit is contained in:
@@ -42,7 +42,7 @@ class NamedDBElementRepository extends DBElementRepository
|
||||
{
|
||||
$result = [];
|
||||
|
||||
$entities = $this->findBy([], ['name' => 'ASC']);
|
||||
$entities = $this->getFlatList();
|
||||
foreach ($entities as $entity) {
|
||||
/** @var AbstractNamedDBElement $entity */
|
||||
$node = new TreeViewNode($entity->getName(), null, null);
|
||||
@@ -65,13 +65,17 @@ class NamedDBElementRepository extends DBElementRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a flattened list of all nodes.
|
||||
* Returns a flattened list of all nodes, sorted by name in natural order.
|
||||
* @return AbstractNamedDBElement[]
|
||||
* @phpstan-return array<int, AbstractNamedDBElement>
|
||||
*/
|
||||
public function getFlatList(): array
|
||||
{
|
||||
//All nodes are sorted by name
|
||||
return $this->findBy([], ['name' => 'ASC']);
|
||||
$qb = $this->createQueryBuilder('e');
|
||||
$q = $qb->select('e')
|
||||
->orderBy('NATSORT(e.name)', 'ASC')
|
||||
->getQuery();
|
||||
|
||||
return $q->getResult();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user