add link when task are near deadline in user menu

This commit is contained in:
2018-04-30 17:37:20 +02:00
parent 399f99ebfc
commit 63168818ec
6 changed files with 145 additions and 6 deletions

View File

@@ -20,6 +20,8 @@ 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;
/**
*
@@ -34,14 +36,30 @@ class CountNotificationTask implements NotificationCounterInterface
*/
protected $singleTaskRepository;
public function __construct(SingleTaskRepository $singleTaskRepository)
{
$this->singleTaskRepository = $singleTaskRepository;
}
/**
*
* @var CacheItempPoolInterface
*/
protected $cachePool;
public function addNotification(User $u): int
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
@@ -58,6 +76,33 @@ class CountNotificationTask implements NotificationCounterInterface
);
}
$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());
}
}