mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
back to the list keep the query parameters required by the list
This commit is contained in:
@@ -43,7 +43,7 @@ class CountNotificationTask implements NotificationCounterInterface
|
||||
*/
|
||||
protected $cachePool;
|
||||
|
||||
const CACHE_KEY = 'chill_task.count_notifications.user.%d';
|
||||
const CACHE_KEY = 'chill_task.count_notifications.user.%d.%s';
|
||||
|
||||
public function __construct(
|
||||
SingleTaskRepository $singleTaskRepository,
|
||||
@@ -54,12 +54,29 @@ class CountNotificationTask implements NotificationCounterInterface
|
||||
}
|
||||
|
||||
public function countNotification(UserInterface $u): int
|
||||
{
|
||||
return
|
||||
$this->countNotificationEnded($u)
|
||||
+ $this->countNotificationWarning($u);
|
||||
}
|
||||
|
||||
public function countNotificationEnded(UserInterface $u): int
|
||||
{
|
||||
return $this->_countNotification($u, SingleTaskRepository::DATE_STATUS_ENDED);
|
||||
}
|
||||
|
||||
public function countNotificationWarning(UserInterface $u): int
|
||||
{
|
||||
return $this->_countNotification($u, SingleTaskRepository::DATE_STATUS_WARNING);
|
||||
}
|
||||
|
||||
protected function _countNotification(UserInterface $u, $status)
|
||||
{
|
||||
if (!$u instanceof User) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$sumCache = $this->cachePool->getItem($this->getCacheKey($u));
|
||||
$sumCache = $this->cachePool->getItem($this->getCacheKey($u, $status));
|
||||
|
||||
if ($sumCache->isHit()) {
|
||||
return $sumCache->get();
|
||||
@@ -70,16 +87,9 @@ class CountNotificationTask implements NotificationCounterInterface
|
||||
'is_closed' => false
|
||||
];
|
||||
|
||||
$sum = 0;
|
||||
|
||||
foreach ([
|
||||
SingleTaskRepository::DATE_STATUS_ENDED,
|
||||
SingleTaskRepository::DATE_STATUS_WARNING] as $status) {
|
||||
|
||||
$sum += $this->singleTaskRepository->countByParameters(
|
||||
$sum = $this->singleTaskRepository->countByParameters(
|
||||
\array_merge($params, [ 'date_status' => $status ])
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
$sumCache->set($sum);
|
||||
$this->cachePool->save($sumCache);
|
||||
@@ -106,8 +116,8 @@ class CountNotificationTask implements NotificationCounterInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function getCacheKey(User $u)
|
||||
private function getCacheKey(User $u, $status)
|
||||
{
|
||||
return sprintf(self::CACHE_KEY, $u->getId());
|
||||
return sprintf(self::CACHE_KEY, $u->getId(), $status);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user