. */ declare(strict_types=1); namespace App\Repository; use App\Entity\Base\AbstractNamedDBElement; use App\Entity\UserSystem\User; use App\Helpers\Trees\TreeViewNode; /** * @template TEntityClass of AbstractNamedDBElement * @extends DBElementRepository * @see \App\Tests\Repository\NamedDBElementRepositoryTest */ class NamedDBElementRepository extends DBElementRepository { /** * Gets a tree of TreeViewNode elements. The root elements has $parent as parent. * The treeview is generic, that means the href are null and ID values are set. * * @return TreeViewNode[] */ public function getGenericNodeTree(): array { $result = []; $entities = $this->getFlatList(); foreach ($entities as $entity) { /** @var AbstractNamedDBElement $entity */ $node = new TreeViewNode($entity->getName(), null, null); $node->setId($entity->getID()); $result[] = $node; if ($entity instanceof User) { if ($entity->isDisabled()) { //If this is a user, then add a badge when it is disabled $node->setIcon('fa-fw fa-treeview fa-solid fa-user-lock text-muted'); } if ($entity->isSamlUser()) { $node->setIcon('fa-fw fa-treeview fa-solid fa-house-user text-muted'); } } } return $result; } /** * Returns a flattened list of all nodes, sorted by name in natural order. * @return AbstractNamedDBElement[] * @phpstan-return array */ public function getFlatList(): array { $qb = $this->createQueryBuilder('e'); $q = $qb->select('e') ->orderBy('NATSORT(e.name)', 'ASC') ->getQuery(); return $q->getResult(); } }