. */ declare(strict_types=1); namespace App\Repository; use App\Entity\Base\AbstractNamedDBElement; use App\Entity\UserSystem\User; use App\Helpers\Trees\TreeViewNode; 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->findBy([], ['name' => 'ASC']); 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 an 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 the list of all nodes to use in a select box. * @return AbstractNamedDBElement[] */ public function toNodesList(): array { //All nodes are sorted by name return $this->findBy([], ['name' => 'ASC']); } }