mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-27 04:08:57 +02:00
Added dropdowns for quick generating labels for different profiles.
This commit is contained in:
parent
747962884a
commit
48ff81a6d1
8 changed files with 118 additions and 3 deletions
57
src/Services/LabelSystem/LabelProfileDropdownHelper.php
Normal file
57
src/Services/LabelSystem/LabelProfileDropdownHelper.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2020 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 Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Services\LabelSystem;
|
||||
|
||||
|
||||
use App\Entity\LabelSystem\LabelProfile;
|
||||
use App\Services\UserCacheKeyGenerator;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Contracts\Cache\ItemInterface;
|
||||
use Symfony\Contracts\Cache\TagAwareCacheInterface;
|
||||
|
||||
class LabelProfileDropdownHelper
|
||||
{
|
||||
private $cache;
|
||||
private $entityManager;
|
||||
private $keyGenerator;
|
||||
|
||||
public function __construct(TagAwareCacheInterface $cache, EntityManagerInterface $entityManager, UserCacheKeyGenerator $keyGenerator)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->keyGenerator = $keyGenerator;
|
||||
}
|
||||
|
||||
public function getDropdownProfiles(string $type): array
|
||||
{
|
||||
$secure_class_name = str_replace('\\', '_', LabelProfile::class);
|
||||
$key = 'profile_dropdown_'.$this->keyGenerator->generateKey().'_'.$secure_class_name . '_' . $type;
|
||||
|
||||
$repo = $this->entityManager->getRepository(LabelProfile::class);
|
||||
|
||||
return $this->cache->get($key, function (ItemInterface $item) use ($repo, $type, $secure_class_name) {
|
||||
// Invalidate when groups, a element with the class or the user changes
|
||||
$item->tag(['groups', 'tree_treeview', $this->keyGenerator->generateKey(), $secure_class_name]);
|
||||
|
||||
return $repo->getDropdownProfiles($type);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue