From 294165489e4cb88e7552ec5c9f6b27765a167e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 15 Oct 2025 11:34:38 +0200 Subject: [PATCH] Only show active workflow on the page "my tracked workflow --- .../unreleased/Feature-20251015-113430.yaml | 6 +++++ .../Controller/WorkflowController.php | 3 ++- .../Workflow/EntityWorkflowRepository.php | 27 +++++++++++++++---- 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 .changes/unreleased/Feature-20251015-113430.yaml diff --git a/.changes/unreleased/Feature-20251015-113430.yaml b/.changes/unreleased/Feature-20251015-113430.yaml new file mode 100644 index 000000000..f89f6c1bf --- /dev/null +++ b/.changes/unreleased/Feature-20251015-113430.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: Only show active workflow on the page "my tracked workflow" +time: 2025-10-15T11:34:30.857052581+02:00 +custom: + Issue: "394" + SchemaChange: No schema change diff --git a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php index 248bd286e..1a78d2884 100644 --- a/src/Bundle/ChillMainBundle/Controller/WorkflowController.php +++ b/src/Bundle/ChillMainBundle/Controller/WorkflowController.php @@ -264,11 +264,12 @@ class WorkflowController extends AbstractController { $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED'); - $total = $this->entityWorkflowRepository->countBySubscriber($this->security->getUser()); + $total = $this->entityWorkflowRepository->countBySubscriber($this->security->getUser(), false); $paginator = $this->paginatorFactory->create($total); $workflows = $this->entityWorkflowRepository->findBySubscriber( $this->security->getUser(), + false, ['createdAt' => 'DESC'], $paginator->getItemsPerPage(), $paginator->getCurrentPageFirstItemNumber() diff --git a/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowRepository.php b/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowRepository.php index a3f210ed2..6cdcd22b2 100644 --- a/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/Workflow/EntityWorkflowRepository.php @@ -57,9 +57,15 @@ class EntityWorkflowRepository implements ObjectRepository return (int) $qb->getQuery()->getSingleScalarResult(); } - public function countBySubscriber(User $user): int + /** + * @param bool|null $isFinal true to get only the entityWorkflow which is finalized, false to get the workflows that are not finalized, and null to ignore + * + * @throws \Doctrine\ORM\NoResultException + * @throws \Doctrine\ORM\NonUniqueResultException + */ + public function countBySubscriber(User $user, ?bool $isFinal = null): int { - $qb = $this->buildQueryBySubscriber($user)->select('count(ew)'); + $qb = $this->buildQueryBySubscriber($user, $isFinal)->select('count(ew)'); return (int) $qb->getQuery()->getSingleScalarResult(); } @@ -182,9 +188,12 @@ class EntityWorkflowRepository implements ObjectRepository return $qb->getQuery()->getResult(); } - public function findBySubscriber(User $user, ?array $orderBy = null, $limit = null, $offset = null): array + /** + * @param bool|null $isFinal true to get only the entityWorkflow which is finalized, false to get the workflows that are not finalized, and null to ignore + */ + public function findBySubscriber(User $user, ?bool $isFinal = null, ?array $orderBy = null, $limit = null, $offset = null): array { - $qb = $this->buildQueryBySubscriber($user)->select('ew'); + $qb = $this->buildQueryBySubscriber($user, $isFinal)->select('ew'); foreach ($orderBy as $key => $sort) { $qb->addOrderBy('ew.'.$key, $sort); @@ -312,7 +321,7 @@ class EntityWorkflowRepository implements ObjectRepository return $qb; } - private function buildQueryBySubscriber(User $user): QueryBuilder + private function buildQueryBySubscriber(User $user, ?bool $isFinal): QueryBuilder { $qb = $this->repository->createQueryBuilder('ew'); @@ -325,6 +334,14 @@ class EntityWorkflowRepository implements ObjectRepository $qb->setParameter('user', $user); + if (null !== $isFinal) { + if ($isFinal) { + $qb->andWhere(sprintf('EXISTS (SELECT 1 FROM %s step WHERE step.isFinal = true AND ew = step.entityWorkflow)', EntityWorkflowStep::class)); + } else { + $qb->andWhere(sprintf('NOT EXISTS (SELECT 1 FROM %s step WHERE step.isFinal = true AND ew = step.entityWorkflow)', EntityWorkflowStep::class)); + } + } + return $qb; } }