diff --git a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php index eb8e6de69..90dbe4744 100644 --- a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php +++ b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php @@ -5,6 +5,8 @@ namespace Chill\TaskBundle\Controller; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher; use Chill\MainBundle\Security\Resolver\CenterResolverInterface; +use Chill\MainBundle\Templating\Listing\FilterOrderHelper; +use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface; use Chill\PersonBundle\Privacy\PrivacyEvent; use Chill\TaskBundle\Repository\SingleTaskAclAwareRepositoryInterface; use Psr\Log\LoggerInterface; @@ -54,6 +56,7 @@ final class SingleTaskController extends AbstractController private TranslatorInterface $translator; private PaginatorFactory $paginatorFactory; private SingleTaskAclAwareRepositoryInterface $singleTaskAclAwareRepository; + private FilterOrderHelperFactoryInterface $filterOrderHelperFactory; public function __construct( CenterResolverDispatcher $centerResolverDispatcher, @@ -62,7 +65,8 @@ final class SingleTaskController extends AbstractController TranslatorInterface $translator, EventDispatcherInterface $eventDispatcher, TimelineBuilder $timelineBuilder, - LoggerInterface $logger + LoggerInterface $logger, + FilterOrderHelperFactoryInterface $filterOrderHelperFactory ) { $this->eventDispatcher = $eventDispatcher; $this->timelineBuilder = $timelineBuilder; @@ -71,6 +75,7 @@ final class SingleTaskController extends AbstractController $this->centerResolverDispatcher = $centerResolverDispatcher; $this->paginatorFactory = $paginatorFactory; $this->singleTaskAclAwareRepository = $singleTaskAclAwareRepository; + $this->filterOrderHelperFactory = $filterOrderHelperFactory; } private function getEntityContext(Request $request) @@ -526,19 +531,42 @@ final class SingleTaskController extends AbstractController { $this->denyAccessUnlessGranted('ROLE_USER'); - $nb = $this->singleTaskAclAwareRepository->countByCurrentUsersTasks(); + $filterOrder = $this->buildFilterOrder(); + $nb = $this->singleTaskAclAwareRepository->countByCurrentUsersTasks( + $filterOrder->getQueryString(), + $filterOrder->getCheckbox('status') + ); $paginator = $this->paginatorFactory->create($nb); $tasks = $this->singleTaskAclAwareRepository->findByCurrentUsersTasks( - null, [], $paginator->getCurrentPageFirstItemNumber(), + $filterOrder->getQueryString(), + $filterOrder->getCheckbox('status'), + $paginator->getCurrentPageFirstItemNumber(), $paginator->getItemsPerPage() ); return $this->render('@ChillTask/SingleTask/List/index.html.twig', [ 'tasks' => $tasks, 'paginator' => $paginator, + 'filter_order' => $filterOrder, ]); } + private function buildFilterOrder(): FilterOrderHelper + { + $statuses = ['no-alert', 'warning', 'alert']; + $statusTrans = [ + 'Tasks near deadline', + 'Tasks over deadline', + 'Tasks without alert', + ]; + return $this->filterOrderHelperFactory + ->create(self::class) + ->addSearchBox() + ->addCheckbox('status', $statuses, $statuses, $statusTrans) + ->build() + ; + } + /** * * Arguments: diff --git a/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php b/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php index e85a6abd7..b034bf973 100644 --- a/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php +++ b/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php @@ -61,6 +61,66 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository ->setParameter('user', $this->security->getUser()) ; + if (!empty($pattern)) { + $qb->andWhere($qb->expr()->like('LOWER(UNACCENT(t.title))', 'LOWER(UNACCENT(:pattern))')) + ->setParameter('pattern', $pattern) + ; + } + + if (count($flags) > 0) { + $orX = $qb->expr()->orX(); + $now = new \DateTime(); + + if (\in_array('no-alert', $flags)) { + $orX + ->add( + $qb->expr()->orX( + $qb->expr()->isNull('t.endDate'), + $qb->expr()->gte('t.endDate - COALESCE(t.warningInterval, :intervalBlank)', ':now') + ) + ); + $qb + ->setParameter('intervalBlank', new \DateInterval('P0D')) + ->setParameter('now', $now) + ; + } + + if (\in_array('warning', $flags)) { + $orX + ->add( + $qb->expr()->andX( + $qb->expr()->eq('t.closed', "'FALSE'"), + $qb->expr()->not($qb->expr()->isNull('t.endDate')), + $qb->expr()->not($qb->expr()->isNull('t.warningInterval')), + $qb->expr()->lte('t.endDate - t.warningInterval', ':now') + ) + ) + ; + $qb + ->setParameter('now', $now) + ; + } + + if (\in_array('alert', $flags)) { + $orX + ->add( + $qb->expr()->andX( + $qb->expr()->eq('t.closed', "'FALSE'"), + $qb->expr()->not($qb->expr()->isNull('t.endDate')), + $qb->expr()->lte('t.endDate', ':now') + ) + ) + ; + $qb + ->setParameter('now', $now) + ; + } + + $qb->andWhere($orX); + } + + + return $qb; } diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index.html.twig index 87de25ccd..5b06fabed 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index.html.twig @@ -7,6 +7,8 @@
{{ 'Any tasks'|trans }}
{% else %} diff --git a/src/Bundle/ChillTaskBundle/translations/messages.fr.yml b/src/Bundle/ChillTaskBundle/translations/messages.fr.yml index 76c2c0674..0b9ef6251 100644 --- a/src/Bundle/ChillTaskBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillTaskBundle/translations/messages.fr.yml @@ -97,6 +97,10 @@ Are you sure you want to start this task ?: Êtes-vous sûrs de vouloir démarre "%number% tasks over deadline": "{0} Aucune tâche dépassée|{1} Une tâche dépassée | ]1,Inf[ %count% tâches dépassées" "%number% tasks near deadline": "{0} Aucune tâche en rappel|{1} Une tâche en rappel | ]1,Inf[ %count% tâches en rappel" +Tasks near deadline: Tâches à échéance proche +Tasks over deadline: Tâches à échéance dépassée +Tasks without alert: Tâches sans alerte + #title My tasks near deadline: Mes tâches à échéance proche My tasks over deadline: Mes tâches à échéance dépassée