2019-03-24 15:25:40 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* part-db version 0.1
|
|
|
|
* Copyright (C) 2005 Christoph Lechner
|
|
|
|
* http://www.cl-projects.de/.
|
|
|
|
*
|
|
|
|
* part-db version 0.2+
|
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
|
|
|
|
* http://code.google.com/p/part-db/
|
|
|
|
*
|
|
|
|
* Part-DB Version 0.4+
|
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer
|
|
|
|
* https://github.com/jbtronics
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Helpers\TreeViewNode;
|
2019-03-26 15:57:51 +01:00
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
2019-08-20 12:52:12 +02:00
|
|
|
use Symfony\Component\Security\Core\Security;
|
|
|
|
use Symfony\Contracts\Cache\ItemInterface;
|
|
|
|
use Symfony\Contracts\Cache\TagAwareCacheInterface;
|
2019-03-26 15:57:51 +01:00
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
2019-03-24 15:25:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This Service generates the tree structure for the tools.
|
|
|
|
* @package App\Services
|
|
|
|
*/
|
|
|
|
class ToolsTreeBuilder
|
|
|
|
{
|
|
|
|
|
2019-03-26 15:57:51 +01:00
|
|
|
protected $translator;
|
|
|
|
protected $urlGenerator;
|
2019-08-20 18:18:11 +02:00
|
|
|
protected $keyGenerator;
|
2019-08-20 12:52:12 +02:00
|
|
|
protected $cache;
|
2019-03-26 15:57:51 +01:00
|
|
|
|
2019-08-20 12:52:12 +02:00
|
|
|
public function __construct(TranslatorInterface $translator, UrlGeneratorInterface $urlGenerator,
|
2019-08-20 18:18:11 +02:00
|
|
|
TagAwareCacheInterface $treeCache, UserCacheKeyGenerator $keyGenerator)
|
2019-03-26 15:57:51 +01:00
|
|
|
{
|
|
|
|
$this->translator = $translator;
|
|
|
|
$this->urlGenerator = $urlGenerator;
|
|
|
|
|
2019-08-20 12:52:12 +02:00
|
|
|
$this->cache = $treeCache;
|
2019-08-20 18:18:11 +02:00
|
|
|
|
|
|
|
$this->keyGenerator = $keyGenerator;
|
2019-08-20 12:52:12 +02:00
|
|
|
}
|
2019-03-26 15:57:51 +01:00
|
|
|
|
2019-03-24 15:25:40 +01:00
|
|
|
/**
|
|
|
|
* Generates the tree for the tools menu.
|
2019-08-20 12:52:12 +02:00
|
|
|
* The result is cached.
|
2019-03-24 15:25:40 +01:00
|
|
|
* @return TreeViewNode The array containing all Nodes for the tools menu.
|
|
|
|
*/
|
|
|
|
public function getTree() : array
|
|
|
|
{
|
2019-08-20 18:18:11 +02:00
|
|
|
$key = "tree_tools_" . $this->keyGenerator->generateKey();
|
2019-08-20 12:52:12 +02:00
|
|
|
|
2019-08-20 18:18:11 +02:00
|
|
|
return $this->cache->get($key, function (ItemInterface $item) {
|
2019-08-20 12:52:12 +02:00
|
|
|
//Invalidate tree, whenever group or the user changes
|
2019-08-20 18:18:11 +02:00
|
|
|
$item->tag(["tree_tools", "groups", $this->keyGenerator->generateKey()]);
|
2019-08-20 12:52:12 +02:00
|
|
|
|
|
|
|
$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;
|
|
|
|
});
|
|
|
|
}
|
2019-03-24 15:25:40 +01:00
|
|
|
|
2019-08-20 12:52:12 +02:00
|
|
|
/**
|
|
|
|
* This functions creates a tree entries for the "edit" node of the tool's tree
|
|
|
|
* @return TreeViewNode[]
|
|
|
|
*/
|
|
|
|
protected function getEditNodes() : array
|
|
|
|
{
|
2019-03-24 15:25:40 +01:00
|
|
|
$nodes = array();
|
2019-04-05 18:39:55 +02:00
|
|
|
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.attachment_types'),
|
|
|
|
$this->urlGenerator->generate('attachment_type_new'));
|
2019-04-20 20:39:06 +02:00
|
|
|
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.categories'),
|
|
|
|
$this->urlGenerator->generate('category_new'));
|
2019-04-26 18:31:09 +02:00
|
|
|
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.devices'),
|
|
|
|
$this->urlGenerator->generate('device_new'));
|
2019-04-26 19:37:40 +02:00
|
|
|
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.suppliers'),
|
|
|
|
$this->urlGenerator->generate('supplier_new'));
|
|
|
|
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.manufacturer'),
|
|
|
|
$this->urlGenerator->generate('manufacturer_new'));
|
2019-04-28 12:50:35 +02:00
|
|
|
|
|
|
|
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.storelocation'),
|
|
|
|
$this->urlGenerator->generate('store_location_new'));
|
|
|
|
|
2019-04-28 13:08:06 +02:00
|
|
|
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.footprint'),
|
|
|
|
$this->urlGenerator->generate('footprint_new'));
|
|
|
|
|
2019-08-12 23:45:21 +02:00
|
|
|
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.currency'),
|
|
|
|
$this->urlGenerator->generate('currency_new'));
|
|
|
|
|
2019-08-14 18:31:46 +02:00
|
|
|
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.measurement_unit'),
|
|
|
|
$this->urlGenerator->generate('measurement_unit_new'));
|
|
|
|
|
2019-04-28 12:50:35 +02:00
|
|
|
$nodes[] = new TreeViewNode($this->translator->trans('tree.tools.edit.part'),
|
|
|
|
$this->urlGenerator->generate('part_new'));
|
2019-03-24 15:25:40 +01:00
|
|
|
|
2019-08-20 12:52:12 +02:00
|
|
|
return $nodes;
|
|
|
|
}
|
2019-03-24 15:25:40 +01:00
|
|
|
|
2019-08-20 12:52:12 +02:00
|
|
|
/**
|
|
|
|
* This function creates the tree entries for the "show" node of the tools tree
|
|
|
|
* @return TreeViewNode[]
|
|
|
|
*/
|
|
|
|
protected function getShowNodes() : array
|
|
|
|
{
|
2019-03-26 15:57:51 +01:00
|
|
|
$show_nodes = array();
|
|
|
|
$show_nodes[] = new TreeViewNode($this->translator->trans('tree.tools.show.all_parts'),
|
|
|
|
$this->urlGenerator->generate('parts_show_all')
|
|
|
|
);
|
|
|
|
|
2019-08-20 12:52:12 +02:00
|
|
|
return $show_nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function creates the tree entries for the "system" node of the tools tree.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getSystemNodes() : array
|
|
|
|
{
|
|
|
|
$edit_nodes = array();
|
|
|
|
|
|
|
|
$edit_nodes[] = new TreeViewNode($this->translator->trans('tree.tools.system.users'),
|
|
|
|
$this->urlGenerator->generate("user_new")
|
|
|
|
);
|
2019-03-26 15:57:51 +01:00
|
|
|
|
2019-08-20 12:52:12 +02:00
|
|
|
return $edit_nodes;
|
2019-03-24 15:25:40 +01:00
|
|
|
}
|
|
|
|
}
|