mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-16 18:22:49 +00:00
Only show active workflow on the page "my tracked workflows"
This commit is contained in:
6
.changes/unreleased/Feature-20251015-113430.yaml
Normal file
6
.changes/unreleased/Feature-20251015-113430.yaml
Normal 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
|
@@ -264,11 +264,12 @@ class WorkflowController extends AbstractController
|
|||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
|
$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);
|
$paginator = $this->paginatorFactory->create($total);
|
||||||
|
|
||||||
$workflows = $this->entityWorkflowRepository->findBySubscriber(
|
$workflows = $this->entityWorkflowRepository->findBySubscriber(
|
||||||
$this->security->getUser(),
|
$this->security->getUser(),
|
||||||
|
false,
|
||||||
['createdAt' => 'DESC'],
|
['createdAt' => 'DESC'],
|
||||||
$paginator->getItemsPerPage(),
|
$paginator->getItemsPerPage(),
|
||||||
$paginator->getCurrentPageFirstItemNumber()
|
$paginator->getCurrentPageFirstItemNumber()
|
||||||
|
@@ -57,9 +57,15 @@ class EntityWorkflowRepository implements ObjectRepository
|
|||||||
return (int) $qb->getQuery()->getSingleScalarResult();
|
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();
|
return (int) $qb->getQuery()->getSingleScalarResult();
|
||||||
}
|
}
|
||||||
@@ -182,9 +188,14 @@ class EntityWorkflowRepository implements ObjectRepository
|
|||||||
return $qb->getQuery()->getResult();
|
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
|
||||||
|
* @param mixed|null $limit
|
||||||
|
* @param mixed|null $offset
|
||||||
|
*/
|
||||||
|
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) {
|
foreach ($orderBy as $key => $sort) {
|
||||||
$qb->addOrderBy('ew.'.$key, $sort);
|
$qb->addOrderBy('ew.'.$key, $sort);
|
||||||
@@ -312,7 +323,7 @@ class EntityWorkflowRepository implements ObjectRepository
|
|||||||
return $qb;
|
return $qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildQueryBySubscriber(User $user): QueryBuilder
|
private function buildQueryBySubscriber(User $user, ?bool $isFinal): QueryBuilder
|
||||||
{
|
{
|
||||||
$qb = $this->repository->createQueryBuilder('ew');
|
$qb = $this->repository->createQueryBuilder('ew');
|
||||||
|
|
||||||
@@ -325,6 +336,14 @@ class EntityWorkflowRepository implements ObjectRepository
|
|||||||
|
|
||||||
$qb->setParameter('user', $user);
|
$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;
|
return $qb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user