mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Added custom choice form type for tree structure entities.
This commit is contained in:
parent
568367b59e
commit
cfa807c621
7 changed files with 203 additions and 16 deletions
|
@ -46,7 +46,27 @@ class StructuralDBElementRepository extends EntityRepository
|
|||
*/
|
||||
public function findRootNodes() : array
|
||||
{
|
||||
return $this->findBy(['parent' => null]);
|
||||
return $this->findBy(['parent' => null], ['name' => 'ASC']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a flattened hierachical tree. Useful for generating option lists.
|
||||
* @param StructuralDBElement|null $parent This entity will be used as root element. Set to null, to use global root
|
||||
* @return StructuralDBElement[] A flattened list containing the tree elements.
|
||||
*/
|
||||
public function toNodesList(?StructuralDBElement $parent = null): array
|
||||
{
|
||||
$result = array();
|
||||
|
||||
$entities = $this->findBy(['parent' => $parent], ['name' => 'ASC']);
|
||||
|
||||
foreach ($entities as $entity) {
|
||||
/** @var StructuralDBElement $entity */
|
||||
$result[] = $entity;
|
||||
$result = array_merge($result, $this->toNodesList($entity));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue