mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 18:13:48 +00:00
generate entry "my tasks" dynamically
This commit is contained in:
@@ -24,6 +24,8 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt
|
||||
use Chill\TaskBundle\Repository\SingleTaskRepository;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
use Chill\TaskBundle\Security\Authorization\TaskVoter;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -50,14 +52,22 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
|
||||
*/
|
||||
public $translator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var AuthorizationCheckerInterface
|
||||
*/
|
||||
public $authorizationChecker;
|
||||
|
||||
public function __construct(
|
||||
CountNotificationTask $counter,
|
||||
TokenStorageInterface $tokenStorage,
|
||||
TranslatorInterface $translator
|
||||
TranslatorInterface $translator,
|
||||
AuthorizationCheckerInterface $authorizationChecker
|
||||
) {
|
||||
$this->counter = $counter;
|
||||
$this->tokenStorage = $tokenStorage;
|
||||
$this->translator = $translator;
|
||||
$this->authorizationChecker = $authorizationChecker;
|
||||
}
|
||||
|
||||
public static function getMenuIds(): array
|
||||
@@ -67,6 +77,10 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
|
||||
|
||||
public function buildMenu($menuId, MenuItem $menu, array $parameters)
|
||||
{
|
||||
if (FALSE === $this->authorizationChecker->isGranted(TaskVoter::SHOW)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user = $this->tokenStorage->getToken()->getUser();
|
||||
$ended = $this->counter->countNotificationEnded($user);
|
||||
$warning = $this->counter->countNotificationWarning($user);
|
||||
@@ -92,6 +106,14 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
|
||||
$warning,
|
||||
-14);
|
||||
}
|
||||
|
||||
$menu->addChild("My tasks", [
|
||||
'route' => 'chill_task_single_my_tasks'
|
||||
])
|
||||
->setExtras([
|
||||
'order' => -10,
|
||||
'icon' => 'tasks'
|
||||
]);
|
||||
}
|
||||
|
||||
protected function addItemInMenu(MenuItem $menu, User $u, $message, $title, $status, $number, $order)
|
||||
|
Reference in New Issue
Block a user