Compare commits

...

1 Commits

3 changed files with 30 additions and 6 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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;
}
}