add counter for tasks

This commit is contained in:
Julien Fastré 2018-04-27 22:21:11 +02:00
parent 3719ce0896
commit 654a5a2019
3 changed files with 74 additions and 3 deletions

View File

@ -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'));

View File

@ -4,3 +4,9 @@ services:
$taskWorkflowManager: '@Chill\TaskBundle\Workflow\TaskWorkflowManager'
tags:
- { name: 'twig.extension' }
Chill\TaskBundle\Templating\UI\CountNotificationTask:
arguments:
$singleTaskRepository: '@Chill\TaskBundle\Repository\SingleTaskRepository'
tags:
- { name: chill_main.count_notification.user }

View File

@ -0,0 +1,63 @@
<?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;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CountNotificationTask implements NotificationCounterInterface
{
/**
*
* @var SingleTaskRepository
*/
protected $singleTaskRepository;
public function __construct(SingleTaskRepository $singleTaskRepository)
{
$this->singleTaskRepository = $singleTaskRepository;
}
public function addNotification(User $u): int
{
$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 ])
);
}
return $sum;
}
}