mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
add link when task are near deadline in user menu
This commit is contained in:
parent
399f99ebfc
commit
63168818ec
@ -31,6 +31,7 @@ class ChillTaskExtension extends Extension implements PrependExtensionInterface
|
|||||||
$loader->load('services/repositories.yml');
|
$loader->load('services/repositories.yml');
|
||||||
$loader->load('services/workflow.yml');
|
$loader->load('services/workflow.yml');
|
||||||
$loader->load('services/templating.yml');
|
$loader->load('services/templating.yml');
|
||||||
|
$loader->load('services/menu.yml');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prepend(ContainerBuilder $container)
|
public function prepend(ContainerBuilder $container)
|
||||||
|
@ -21,6 +21,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Chill\TaskBundle\Workflow\TaskWorkflowManager;
|
use Chill\TaskBundle\Workflow\TaskWorkflowManager;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
use Chill\TaskBundle\Templating\UI\CountNotificationTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -37,6 +38,7 @@ class TaskWorkflowDefinitionCompilerPass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$workflowManagerDefinition = $container->getDefinition(TaskWorkflowManager::class);
|
$workflowManagerDefinition = $container->getDefinition(TaskWorkflowManager::class);
|
||||||
|
$counterDefinition = $container->getDefinition(CountNotificationTask::class);
|
||||||
|
|
||||||
foreach ($container->findTaggedServiceIds('chill_task.workflow_definition') as $id => $tags) {
|
foreach ($container->findTaggedServiceIds('chill_task.workflow_definition') as $id => $tags) {
|
||||||
// registering the definition to manager
|
// registering the definition to manager
|
||||||
@ -50,6 +52,12 @@ class TaskWorkflowDefinitionCompilerPass implements CompilerPassInterface
|
|||||||
'method' => 'onTaskStateEntered',
|
'method' => 'onTaskStateEntered',
|
||||||
'priority' => -255
|
'priority' => -255
|
||||||
]);
|
]);
|
||||||
|
$counterDefinition
|
||||||
|
->addTag('kernel.event_listener', [
|
||||||
|
'event' => sprintf('workflow.%s.entered', $definition->getClass()::getAssociatedWorkflowName()),
|
||||||
|
'method' => 'resetCacheOnNewStates',
|
||||||
|
'priority' => 0
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
77
Menu/UserMenuBuilder.php
Normal file
77
Menu/UserMenuBuilder.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
namespace Chill\TaskBundle\Menu;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
||||||
|
use Knp\Menu\MenuItem;
|
||||||
|
use Chill\TaskBundle\Templating\UI\CountNotificationTask;
|
||||||
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
|
use Chill\TaskBundle\Repository\SingleTaskRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
|
*/
|
||||||
|
class UserMenuBuilder implements LocalMenuBuilderInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var CountNotificationTask
|
||||||
|
*/
|
||||||
|
public $counter;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @var TokenStorageInterface
|
||||||
|
*/
|
||||||
|
public $tokenStorage;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
CountNotificationTask $counter,
|
||||||
|
TokenStorageInterface $tokenStorage
|
||||||
|
) {
|
||||||
|
$this->counter = $counter;
|
||||||
|
$this->tokenStorage = $tokenStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getMenuIds(): array
|
||||||
|
{
|
||||||
|
return [ 'user' ];
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
Resources/config/services/menu.yml
Normal file
7
Resources/config/services/menu.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
services:
|
||||||
|
Chill\TaskBundle\Menu\UserMenuBuilder:
|
||||||
|
arguments:
|
||||||
|
$tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'
|
||||||
|
$counter: '@Chill\TaskBundle\Templating\UI\CountNotificationTask'
|
||||||
|
tags:
|
||||||
|
- { name: 'chill.menu_builder' }
|
@ -8,5 +8,6 @@ services:
|
|||||||
Chill\TaskBundle\Templating\UI\CountNotificationTask:
|
Chill\TaskBundle\Templating\UI\CountNotificationTask:
|
||||||
arguments:
|
arguments:
|
||||||
$singleTaskRepository: '@Chill\TaskBundle\Repository\SingleTaskRepository'
|
$singleTaskRepository: '@Chill\TaskBundle\Repository\SingleTaskRepository'
|
||||||
|
$cachePool: '@cache.user_data'
|
||||||
tags:
|
tags:
|
||||||
- { name: chill.count_notification.user }
|
- { name: chill.count_notification.user }
|
||||||
|
@ -20,6 +20,8 @@ namespace Chill\TaskBundle\Templating\UI;
|
|||||||
use Chill\MainBundle\Templating\UI\NotificationCounterInterface;
|
use Chill\MainBundle\Templating\UI\NotificationCounterInterface;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User;
|
||||||
use Chill\TaskBundle\Repository\SingleTaskRepository;
|
use Chill\TaskBundle\Repository\SingleTaskRepository;
|
||||||
|
use Psr\Cache\CacheItemPoolInterface;
|
||||||
|
use Symfony\Component\Workflow\Event\Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -34,14 +36,30 @@ class CountNotificationTask implements NotificationCounterInterface
|
|||||||
*/
|
*/
|
||||||
protected $singleTaskRepository;
|
protected $singleTaskRepository;
|
||||||
|
|
||||||
public function __construct(SingleTaskRepository $singleTaskRepository)
|
/**
|
||||||
{
|
*
|
||||||
|
* @var CacheItempPoolInterface
|
||||||
|
*/
|
||||||
|
protected $cachePool;
|
||||||
|
|
||||||
|
const CACHE_KEY = 'chill_task.count_notifications.user.%d';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
SingleTaskRepository $singleTaskRepository,
|
||||||
|
CacheItemPoolInterface $cachePool
|
||||||
|
) {
|
||||||
$this->singleTaskRepository = $singleTaskRepository;
|
$this->singleTaskRepository = $singleTaskRepository;
|
||||||
|
$this->cachePool = $cachePool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function countNotification(User $u): int
|
||||||
public function addNotification(User $u): int
|
|
||||||
{
|
{
|
||||||
|
$sumCache = $this->cachePool->getItem($this->getCacheKey($u));
|
||||||
|
|
||||||
|
if ($sumCache->isHit()) {
|
||||||
|
return $sumCache->get();
|
||||||
|
}
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'user' => $u,
|
'user' => $u,
|
||||||
'is_closed' => false
|
'is_closed' => false
|
||||||
@ -58,6 +76,33 @@ class CountNotificationTask implements NotificationCounterInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sumCache->set($sum);
|
||||||
|
$this->cachePool->save($sumCache);
|
||||||
|
|
||||||
return $sum;
|
return $sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addNotification(User $u): int
|
||||||
|
{
|
||||||
|
return $this->countNotification($u);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resetCacheOnNewStates(Event $e)
|
||||||
|
{
|
||||||
|
/* @var $task \Chill\TaskBundle\Entity\SingleTask */
|
||||||
|
$task = $e->getSubject();
|
||||||
|
|
||||||
|
if (NULL !== $task->getAssignee()) {
|
||||||
|
$sumCache = $this->cachePool->getItem($this->getCacheKey($task->getAssignee()));
|
||||||
|
|
||||||
|
if ($sumCache->isHit()) {
|
||||||
|
$this->cachePool->deleteItem($this->getCacheKey($task->getAssignee()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getCacheKey(User $u)
|
||||||
|
{
|
||||||
|
return sprintf(self::CACHE_KEY, $u->getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user