mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
Merge branch 'master' of framagit.org:Chill-project/Chill-Task
merge ...
This commit is contained in:
commit
d1f95b3be8
@ -46,8 +46,8 @@ class TaskController extends Controller
|
||||
->find($taskId)
|
||||
;
|
||||
$defaultReturnPath = $this->generateUrl(
|
||||
'chill_task_task_list_by_person',
|
||||
[ 'personId' => $task->getPerson() ]
|
||||
'chill_task_singletask_list',
|
||||
[ 'person_id' => $task->getPerson() ]
|
||||
);
|
||||
break;
|
||||
default:
|
||||
|
@ -31,6 +31,7 @@ class ChillTaskExtension extends Extension implements PrependExtensionInterface
|
||||
$loader->load('services/repositories.yml');
|
||||
$loader->load('services/workflow.yml');
|
||||
$loader->load('services/templating.yml');
|
||||
$loader->load('services/menu.yml');
|
||||
}
|
||||
|
||||
public function prepend(ContainerBuilder $container)
|
||||
|
@ -21,6 +21,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Chill\TaskBundle\Workflow\TaskWorkflowManager;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Chill\TaskBundle\Templating\UI\CountNotificationTask;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -37,6 +38,7 @@ class TaskWorkflowDefinitionCompilerPass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
$workflowManagerDefinition = $container->getDefinition(TaskWorkflowManager::class);
|
||||
$counterDefinition = $container->getDefinition(CountNotificationTask::class);
|
||||
|
||||
foreach ($container->findTaggedServiceIds('chill_task.workflow_definition') as $id => $tags) {
|
||||
// registering the definition to manager
|
||||
@ -50,6 +52,12 @@ class TaskWorkflowDefinitionCompilerPass implements CompilerPassInterface
|
||||
'method' => 'onTaskStateEntered',
|
||||
'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
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
@ -48,7 +48,7 @@ class SingleTaskRepository extends \Doctrine\ORM\EntityRepository
|
||||
* @param User $currentUser
|
||||
* @return int
|
||||
*/
|
||||
public function countByParameters($params, User $currentUser)
|
||||
public function countByParameters($params, User $currentUser = null)
|
||||
{
|
||||
$qb = $this->createQueryBuilder('st')
|
||||
->select('COUNT(st)');
|
||||
@ -97,9 +97,11 @@ class SingleTaskRepository extends \Doctrine\ORM\EntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
protected function buildQuery(QueryBuilder $qb, $params, User $currentUser)
|
||||
protected function buildQuery(QueryBuilder $qb, $params, User $currentUser = null)
|
||||
{
|
||||
$this->buildACLQuery($qb, $currentUser);
|
||||
if (NULL !== $currentUser) {
|
||||
$this->buildACLQuery($qb, $currentUser);
|
||||
}
|
||||
|
||||
if (\array_key_exists('person', $params) and !empty($params['person'])) {
|
||||
$qb->andWhere($qb->expr()->eq('st.person', ':person'));
|
||||
|
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' }
|
@ -4,3 +4,10 @@ services:
|
||||
$taskWorkflowManager: '@Chill\TaskBundle\Workflow\TaskWorkflowManager'
|
||||
tags:
|
||||
- { name: 'twig.extension' }
|
||||
|
||||
Chill\TaskBundle\Templating\UI\CountNotificationTask:
|
||||
arguments:
|
||||
$singleTaskRepository: '@Chill\TaskBundle\Repository\SingleTaskRepository'
|
||||
$cachePool: '@cache.user_data'
|
||||
tags:
|
||||
- { name: chill.count_notification.user }
|
||||
|
108
Templating/UI/CountNotificationTask.php
Normal file
108
Templating/UI/CountNotificationTask.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?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\Templating\UI;
|
||||
|
||||
use Chill\MainBundle\Templating\UI\NotificationCounterInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\TaskBundle\Repository\SingleTaskRepository;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Workflow\Event\Event;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class CountNotificationTask implements NotificationCounterInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var SingleTaskRepository
|
||||
*/
|
||||
protected $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->cachePool = $cachePool;
|
||||
}
|
||||
|
||||
public function countNotification(User $u): int
|
||||
{
|
||||
$sumCache = $this->cachePool->getItem($this->getCacheKey($u));
|
||||
|
||||
if ($sumCache->isHit()) {
|
||||
return $sumCache->get();
|
||||
}
|
||||
|
||||
$params = [
|
||||
'user' => $u,
|
||||
'is_closed' => false
|
||||
];
|
||||
|
||||
$sum = 0;
|
||||
|
||||
foreach ([
|
||||
SingleTaskRepository::DATE_STATUS_ENDED,
|
||||
SingleTaskRepository::DATE_STATUS_WARNING] as $status) {
|
||||
|
||||
$sum += $this->singleTaskRepository->countByParameters(
|
||||
\array_merge($params, [ 'date_status' => $status ])
|
||||
);
|
||||
}
|
||||
|
||||
$sumCache->set($sum);
|
||||
$this->cachePool->save($sumCache);
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
@ -89,7 +89,5 @@ class TaskWorkflowManager implements SupportStrategyInterface
|
||||
$definition = $this->getTaskWorkflowDefinition($task);
|
||||
|
||||
$task->setClosed($definition->isClosed($task));
|
||||
|
||||
dump($task);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user