diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php index c6094ef46..2df3d2147 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php @@ -166,6 +166,66 @@ class WorkflowController extends AbstractController return $this->redirectToRoute('chill_main_workflow_show', ['id' => $entityWorkflowStep->getEntityWorkflow()->getId()]); } + /** + * Previous workflows where the user has applyed a transition. + * + * @Route("/{_locale}/main/workflow/list/previous_transitionned", name="chill_main_workflow_list_previous_transitionned") + */ + public function myPreviousWorkflowsTransitionned(Request $request): Response + { + $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED'); + + $total = $this->entityWorkflowRepository->countByPreviousTransitionned($this->getUser()); + $paginator = $this->paginatorFactory->create($total); + + $workflows = $this->entityWorkflowRepository->findByPreviousTransitionned( + $this->getUser(), + ['createdAt' => 'DESC'], + $paginator->getItemsPerPage(), + $paginator->getCurrentPageFirstItemNumber() + ); + + return $this->render( + '@ChillMain/Workflow/list.html.twig', + [ + 'help' => 'workflow.Previous workflow transitionned help', + 'workflows' => $this->buildHandler($workflows), + 'paginator' => $paginator, + 'step' => 'previous_transitionned', + ] + ); + } + + /** + * Previous workflows where the user was mentioned, but did not give any reaction. + * + * @Route("/{_locale}/main/workflow/list/previous_without_reaction", name="chill_main_workflow_list_previous_without_reaction") + */ + public function myPreviousWorkflowsWithoutReaction(Request $request): Response + { + $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED'); + + $total = $this->entityWorkflowRepository->countByPreviousDestWithoutReaction($this->getUser()); + $paginator = $this->paginatorFactory->create($total); + + $workflows = $this->entityWorkflowRepository->findByPreviousDestWithoutReaction( + $this->getUser(), + ['createdAt' => 'DESC'], + $paginator->getItemsPerPage(), + $paginator->getCurrentPageFirstItemNumber() + ); + + return $this->render( + '@ChillMain/Workflow/list.html.twig', + [ + 'help' => 'workflow.Previous workflow without reaction help', + 'workflows' => $this->buildHandler($workflows), + 'paginator' => $paginator, + 'step' => 'previous_without_reaction', + ] + ); + } + /** * @Route("/{_locale}/main/workflow/list/dest", name="chill_main_workflow_list_dest") */ diff --git a/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowRepository.php b/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowRepository.php index 63e27c7ba..ab58801fc 100644 --- a/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowRepository.php @@ -34,6 +34,20 @@ class EntityWorkflowRepository implements ObjectRepository return (int) $qb->getQuery()->getSingleScalarResult(); } + public function countByPreviousDestWithoutReaction(User $user): int + { + $qb = $this->buildQueryByPreviousDestWithoutReaction($user)->select('count(ew)'); + + return (int) $qb->getQuery()->getSingleScalarResult(); + } + + public function countByPreviousTransitionned(User $user): int + { + $qb = $this->buildQueryByPreviousTransitionned($user)->select('count(ew)'); + + return (int) $qb->getQuery()->getSingleScalarResult(); + } + public function countBySubscriber(User $user): int { $qb = $this->buildQueryBySubscriber($user)->select('count(ew)'); @@ -78,6 +92,32 @@ class EntityWorkflowRepository implements ObjectRepository return $qb->getQuery()->getResult(); } + public function findByPreviousDestWithoutReaction(User $user, ?array $orderBy = null, $limit = null, $offset = null): array + { + $qb = $this->buildQueryByPreviousDestWithoutReaction($user)->select('ew'); + + foreach ($orderBy as $key => $sort) { + $qb->addOrderBy('ew.' . $key, $sort); + } + + $qb->setMaxResults($limit)->setFirstResult($offset); + + return $qb->getQuery()->getResult(); + } + + public function findByPreviousTransitionned(User $user, ?array $orderBy = null, $limit = null, $offset = null): array + { + $qb = $this->buildQueryByPreviousTransitionned($user)->select('ew')->distinct(true); + + foreach ($orderBy as $key => $sort) { + $qb->addOrderBy('ew.' . $key, $sort); + } + + $qb->setMaxResults($limit)->setFirstResult($offset); + + return $qb->getQuery()->getResult(); + } + public function findBySubscriber(User $user, ?array $orderBy = null, $limit = null, $offset = null): array { $qb = $this->buildQueryBySubscriber($user)->select('ew'); @@ -120,6 +160,41 @@ class EntityWorkflowRepository implements ObjectRepository return $qb; } + private function buildQueryByPreviousDestWithoutReaction(User $user): QueryBuilder + { + $qb = $this->repository->createQueryBuilder('ew'); + + $qb->join('ew.steps', 'step'); + + $qb->where( + $qb->expr()->andX( + $qb->expr()->isMemberOf(':user', 'step.destUser'), + $qb->expr()->neq('step.transitionBy', ':user'), + ) + ); + + $qb->setParameter('user', $user); + + return $qb; + } + + private function buildQueryByPreviousTransitionned(User $user): QueryBuilder + { + $qb = $this->repository->createQueryBuilder('ew'); + + $qb->join('ew.steps', 'step'); + + $qb->where( + $qb->expr()->andX( + $qb->expr()->eq('step.transitionBy', ':user'), + ) + ); + + $qb->setParameter('user', $user); + + return $qb; + } + private function buildQueryBySubscriber(User $user): QueryBuilder { $qb = $this->repository->createQueryBuilder('ew'); diff --git a/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig index a3890fa97..83d60ff4c 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Workflow/list.html.twig @@ -11,6 +11,7 @@

{{ block('title') }}

+ + {% if help is defined %} +

{{ help|trans }}

+ {% endif %} + {% if workflows|length == 0 %}

{{ 'workflow.No workflow'|trans }}

{% else %} diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index d8186bd6a..06532db8a 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -408,6 +408,10 @@ workflow: Add an email: Ajouter une adresse email Remove an email: Enlever cette adresse email Any email: Aucune adresse email + Previous dest without reaction: Workflows clotûrés après action d'un autre utilisateur + Previous workflow without reaction help: Liste des workflows où vous avez été cité comme pouvant réagir à une étape, mais où un autre utilisateur a exécuté une action avant vous. + Previous transitionned: Anciens workflows + Previous workflow transitionned help: Workflows où vous avez exécuté une action. Subscribe final: Recevoir une notification à l'étape finale