Use natural sorting for trees and others repository functions

This commit is contained in:
Jan Böhmer 2024-06-17 22:33:40 +02:00
parent 9db822eabd
commit 8bb8118d9f
13 changed files with 71 additions and 44 deletions

View file

@ -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();
}
}