set order in user menu + translations

This commit is contained in:
Julien Fastré 2018-05-04 14:16:44 +02:00
parent f19c9e85dc
commit 583c10128d
3 changed files with 34 additions and 15 deletions

View File

@ -22,6 +22,7 @@ use Knp\Menu\MenuItem;
use Chill\TaskBundle\Templating\UI\CountNotificationTask;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Chill\TaskBundle\Repository\SingleTaskRepository;
use Symfony\Component\Translation\TranslatorInterface;
/**
*
@ -42,12 +43,20 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
*/
public $tokenStorage;
/**
*
* @var TranslatorInterface
*/
public $translator;
public function __construct(
CountNotificationTask $counter,
TokenStorageInterface $tokenStorage
TokenStorageInterface $tokenStorage,
TranslatorInterface $translator
) {
$this->counter = $counter;
$this->tokenStorage = $tokenStorage;
$this->translator = $translator;
}
public static function getMenuIds(): array
@ -57,21 +66,29 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
if ($this->counter->countNotification($this->tokenStorage->getToken()
->getUser()) > 0) {
$menu->addChild('Task near deadlines', [
'route' => 'chill_task_singletask_list',
'routeParameters' => [
'user_id' => $this->tokenStorage
->getToken()
->getUser()
->getId(),
'status' => [
SingleTaskRepository::DATE_STATUS_WARNING,
SingleTaskRepository::DATE_STATUS_ENDED
]
$number = $this->counter->countNotification($this->tokenStorage->getToken()
->getUser());
if ($number > 0) {
$menu->addChild(
$this->translator->transChoice('%number% tasks near deadline', $number),
[
'route' => 'chill_task_singletask_list',
'routeParameters' => [
'user_id' => $this->tokenStorage
->getToken()
->getUser()
->getId(),
'status' => [
SingleTaskRepository::DATE_STATUS_WARNING,
SingleTaskRepository::DATE_STATUS_ENDED
]
]
]);
])
->setExtras([
'order'=> -15,
'icon' => 'exclamation-triangle'
]);
}
}
}

View File

@ -3,5 +3,6 @@ services:
arguments:
$tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'
$counter: '@Chill\TaskBundle\Templating\UI\CountNotificationTask'
$translator: '@Symfony\Component\Translation\TranslatorInterface'
tags:
- { name: 'chill.menu_builder' }

View File

@ -72,3 +72,4 @@ cancel: annuler
'The task has been updated': 'La tâche a été mise à jour'
'The transition is successfully applied': 'La transition a bien été effectuée'
'The transition could not be applied': "La transition n'a pas pu être appliquée"
'%number% tasks near deadline': '{0} Aucune tâche à échance|{1} Une tâche à échéance | ]1,Inf[ %count% tâches à échéance'