diff --git a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php index 4c6ab338f..ba67b62c4 100644 --- a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php +++ b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php @@ -300,7 +300,9 @@ final class SingleTaskController extends AbstractController ) { $this->denyAccessUnlessGranted(TaskVoter::SHOW, null); - $filterOrder = $this->buildFilterOrder(); + $showMissionTypeFilter = $this->getParameter('show_mission_type_filter'); + + $filterOrder = $this->buildFilterOrder(true, $showMissionTypeFilter); $filteredUsers = $filterOrder->getUserPickerData('userPicker'); @@ -308,9 +310,15 @@ final class SingleTaskController extends AbstractController $filterOrder->getCheckboxData('status'), array_map(static fn ($i) => 'state_' . $i, $filterOrder->hasCheckboxData('states') ? $filterOrder->getCheckboxData('states') : []) ); + + if ($showMissionTypeFilter) { + $types = $filterOrder->getCheckboxData('missionTypePicker'); + } + $nb = $this->singleTaskAclAwareRepository->countByAllViewable( $filterOrder->getQueryString(), $flags, + $types ?? [], $filteredUsers ); $paginator = $this->paginatorFactory->create($nb); @@ -319,6 +327,7 @@ final class SingleTaskController extends AbstractController $tasks = $this->singleTaskAclAwareRepository->findByAllViewable( $filterOrder->getQueryString(), $flags, + $types ?? [], $filteredUsers, $paginator->getCurrentPageFirstItemNumber(), $paginator->getItemsPerPage(), @@ -669,7 +678,7 @@ final class SingleTaskController extends AbstractController return $form; } - private function buildFilterOrder($includeFilterByUser = true): FilterOrderHelper + private function buildFilterOrder($includeFilterByUser = true, $includeMissionType = false): FilterOrderHelper { $statuses = ['no-alert', 'warning', 'alert']; $statusTrans = [ @@ -678,6 +687,8 @@ final class SingleTaskController extends AbstractController 'Tasks over deadline', ]; + $missionTypes = ['fsl', 'ispah', 'diagnostic_maintien', 'social_help', 'ni', 'diagnostic_acces']; + $filterBuilder = $this->filterOrderHelperFactory ->create(self::class) ->addSearchBox() @@ -696,6 +707,10 @@ final class SingleTaskController extends AbstractController ->addUserPicker('userPicker', 'Filter by user', ['multiple' => true, 'required' => false]); } + if ($includeMissionType) { + $filterBuilder->addCheckbox('missionTypePicker', $missionTypes); + } + return $filterBuilder->build(); } diff --git a/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php b/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php index 53ed4c38d..c8f989765 100644 --- a/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php +++ b/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php @@ -52,6 +52,7 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository public function buildBaseQuery( ?string $pattern = null, ?array $flags = [], + ?array $types = [], ?array $users = [] ): QueryBuilder { $qb = $this->em->createQueryBuilder(); @@ -81,6 +82,12 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository return $qb; } + if (null !== $types && count($types) > 0) { + $qb->andWhere($qb->expr()->in('t.type', ':types')); + + $qb->setParameter('types', $types); + } + if (null !== $flags && count($flags) > 0) { $orXDate = $qb->expr()->orX(); $orXState = $qb->expr()->orX(); @@ -203,9 +210,10 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository public function countByAllViewable( ?string $pattern = null, ?array $flags = [], + ?array $types = [], ?array $users = [] ): int { - $qb = $this->buildBaseQuery($pattern, $flags, $users); + $qb = $this->buildBaseQuery($pattern, $flags, $types, $users); return $this ->addACLGlobal($qb) @@ -251,12 +259,13 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository public function findByAllViewable( ?string $pattern = null, ?array $flags = [], + ?array $types = [], ?array $users = [], ?int $start = 0, ?int $limit = 50, ?array $orderBy = [] ): array { - $qb = $this->buildBaseQuery($pattern, $flags, $users); + $qb = $this->buildBaseQuery($pattern, $flags, $types, $users); $qb = $this->addACLGlobal($qb); return $this->getResult($qb, $start, $limit, $orderBy); diff --git a/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepositoryInterface.php b/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepositoryInterface.php index 7d2870c67..bb63c0caa 100644 --- a/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepositoryInterface.php +++ b/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepositoryInterface.php @@ -19,6 +19,7 @@ interface SingleTaskAclAwareRepositoryInterface public function countByAllViewable( ?string $pattern = null, ?array $flags = [], + ?array $types = [], ?array $users = [] ): int; @@ -39,6 +40,7 @@ interface SingleTaskAclAwareRepositoryInterface public function findByAllViewable( ?string $pattern = null, ?array $flags = [], + ?array $types = [], ?array $users = [], ?int $start = 0, ?int $limit = 50,