mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-15 07:22:40 +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
src/Repository
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue