translator = $translator; $this->urlGenerator = $urlGenerator; $this->cache = $treeCache; $this->keyGenerator = $keyGenerator; $this->security = $security; } /** * Generates the tree for the tools menu. * The result is cached. * @return TreeViewNode[] The array containing all Nodes for the tools menu. */ public function getTree() : array { $key = "tree_tools_" . $this->keyGenerator->generateKey(); return $this->cache->get($key, function (ItemInterface $item) { //Invalidate tree, whenever group or the user changes $item->tag(["tree_tools", "groups", $this->keyGenerator->generateKey()]); $tree = array(); $tree[] = new TreeViewNode($this->translator->trans('tree.tools.edit'), null, $this->getEditNodes()); $tree[] = new TreeViewNode($this->translator->trans('tree.tools.show'), null, $this->getShowNodes()); $tree[] = new TreeViewNode($this->translator->trans('tree.tools.system'), null, $this->getSystemNodes()); return $tree; }); } /** * This functions creates a tree entries for the "edit" node of the tool's tree * @return TreeViewNode[] */ protected function getEditNodes() : array { $nodes = array(); if ($this->security->isGranted('read', new AttachmentType())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.edit.attachment_types'), $this->urlGenerator->generate('attachment_type_new') ); } if ($this->security->isGranted('read', new Category())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.edit.categories'), $this->urlGenerator->generate('category_new') ); } if ($this->security->isGranted('read', new Device())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.edit.devices'), $this->urlGenerator->generate('device_new') ); } if ($this->security->isGranted('read', new Supplier())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.edit.suppliers'), $this->urlGenerator->generate('supplier_new') ); } if ($this->security->isGranted('read', new Manufacturer())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.edit.manufacturer'), $this->urlGenerator->generate('manufacturer_new') ); } if ($this->security->isGranted('read', new Storelocation())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.edit.storelocation'), $this->urlGenerator->generate('store_location_new') ); } if ($this->security->isGranted('read', new Footprint())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.edit.footprint'), $this->urlGenerator->generate('footprint_new') ); } if ($this->security->isGranted('read', new Currency())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.edit.currency'), $this->urlGenerator->generate('currency_new') ); } if ($this->security->isGranted('read', new MeasurementUnit())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.edit.measurement_unit'), $this->urlGenerator->generate('measurement_unit_new') ); } if ($this->security->isGranted('create', new Part())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.edit.part'), $this->urlGenerator->generate('part_new') ); } return $nodes; } /** * This function creates the tree entries for the "show" node of the tools tree * @return TreeViewNode[] */ protected function getShowNodes() : array { $show_nodes = array(); $show_nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.show.all_parts'), $this->urlGenerator->generate('parts_show_all') ); if ($this->security->isGranted('read', new PartAttachment())) { $show_nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.show.all_attachments'), $this->urlGenerator->generate('attachment_list') ); } return $show_nodes; } /** * This function creates the tree entries for the "system" node of the tools tree. * @return array */ protected function getSystemNodes() : array { $nodes = array(); if ($this->security->isGranted('read', new User())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.system.users'), $this->urlGenerator->generate("user_new") ); } if ($this->security->isGranted('read', new Group())) { $nodes[] = new TreeViewNode( $this->translator->trans('tree.tools.system.groups'), $this->urlGenerator->generate('group_new') ); } return $nodes; } }