diff --git a/src/Bundle/ChillMainBundle/Form/Type/Listing/FilterOrderType.php b/src/Bundle/ChillMainBundle/Form/Type/Listing/FilterOrderType.php index a5166e322..c6744f852 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/Listing/FilterOrderType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/Listing/FilterOrderType.php @@ -126,7 +126,7 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType } if ([] !== $helper->getUserPickers()) { - $userPickersBuilder = $builder->create('userPicker', null, ['compound' => true]); + $userPickersBuilder = $builder->create('user_pickers', null, ['compound' => true]); foreach ($helper->getUserPickers() as $name => [ 'label' => $label, 'options' => $options diff --git a/src/Bundle/ChillMainBundle/Resources/views/FilterOrder/base.html.twig b/src/Bundle/ChillMainBundle/Resources/views/FilterOrder/base.html.twig index b2673b60c..fa35cdbf3 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/FilterOrder/base.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/FilterOrder/base.html.twig @@ -67,6 +67,22 @@ {% endfor %} {% endif %} {% endif %} + {% if form.user_pickers is defined %} + {% set btnSubmit = 1 %} + {% if form.user_pickers|length > 0 %} + {% for name, options in form.user_pickers %} +
+
+ {% for p in form['user_pickers'][name].children %} + {{ form_widget(p) }} + {{ form_label(p) }} + {% endfor %} +
+
+ {% endfor %} + {% endif %} + {% endif %} + {% if form.single_checkboxes is defined %} {% set btnSubmit = 1 %} {% for name, _o in form.single_checkboxes %} @@ -78,7 +94,7 @@ {% endfor %} {% endif %} - + {% if btnSubmit == 1 %}
diff --git a/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelper.php b/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelper.php index bdec463bd..026c55ef6 100644 --- a/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelper.php +++ b/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelper.php @@ -87,7 +87,7 @@ class FilterOrderHelper return $this->entityChoices; } - public function addUserPickers(string $name, ?string $label = null, array $options = []): self + public function addUserPicker(string $name, ?string $label = null, array $options = []): self { $this->userPickers[$name] = ['label' => $label, 'options' => $options]; @@ -136,7 +136,8 @@ class FilterOrderHelper public function getUserPickerData(string $name): array { - return $this->getFormData()['userPickers'][$name]; + dump($this->getFormData()['user_pickers']); + return $this->getFormData()['user_pickers'][$name]; } public function getCheckboxData(string $name): array diff --git a/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperBuilder.php b/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperBuilder.php index 6fd0eeb42..86180d06e 100644 --- a/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperBuilder.php +++ b/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperBuilder.php @@ -88,7 +88,7 @@ class FilterOrderHelperBuilder return $this; } - public function addUserPickers(string $name, ?string $label = null, ?array $options = []): self + public function addUserPicker(string $name, ?string $label = null, ?array $options = []): self { $this->userPickers[$name] = ['label' => $label, 'options' => $options]; @@ -143,7 +143,7 @@ class FilterOrderHelperBuilder 'options' => $options ] ) { - $helper->addUserPickers($name, $label, $options); + $helper->addUserPicker($name, $label, $options); } diff --git a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php index 58d2a406e..e60a58145 100644 --- a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php +++ b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php @@ -300,13 +300,16 @@ final class SingleTaskController extends AbstractController $filterOrder = $this->buildFilterOrder(); + $filteredUsers = $filterOrder->getUserPickerData('userPicker'); + $flags = array_merge( $filterOrder->getCheckboxData('status'), array_map(static fn ($i) => 'state_' . $i, $filterOrder->getCheckboxData('states')) ); $nb = $this->singleTaskAclAwareRepository->countByAllViewable( $filterOrder->getQueryString(), - $flags + $flags, + $filteredUsers ); $paginator = $this->paginatorFactory->create($nb); @@ -314,6 +317,7 @@ final class SingleTaskController extends AbstractController $tasks = $this->singleTaskAclAwareRepository->findByAllViewable( $filterOrder->getQueryString(), $flags, + $filteredUsers, $paginator->getCurrentPageFirstItemNumber(), $paginator->getItemsPerPage(), [ @@ -681,7 +685,7 @@ final class SingleTaskController extends AbstractController ->addSearchBox() ->addCheckbox('status', $statuses, $statuses, $statusTrans) ->addCheckbox('states', $states, ['new', 'in_progress']) - ->addUserPickers('userPicker', 'userPicker', ['multiple' => True]) + ->addUserPicker('userPicker', 'Filter by user', ['multiple' => True, 'required' => False]) ->build(); } diff --git a/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php b/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php index 0efc16085..ef30a7783 100644 --- a/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php +++ b/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepository.php @@ -51,7 +51,8 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository public function buildBaseQuery( ?string $pattern = null, - ?array $flags = [] + ?array $flags = [], + ?array $users = [] ): QueryBuilder { $qb = $this->em->createQueryBuilder(); $qb @@ -62,6 +63,24 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository ->setParameter('pattern', '%' . $pattern . '%'); } + if (count($users) > 0) { + $orXUser = $qb->expr()->orX(); + + foreach ($users as $key => $user) { + $orXUser->add( + $qb->expr()->eq('t.assignee', ':user') + ); + + $qb->setParameter('user', $user); + } + + if ($orXUser->count() > 0) { + $qb->andWhere($orXUser); + } + + return $qb; + } + if (count($flags) > 0) { $orXDate = $qb->expr()->orX(); $orXState = $qb->expr()->orX(); @@ -183,9 +202,10 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository public function countByAllViewable( ?string $pattern = null, - ?array $flags = [] + ?array $flags = [], + ?array $users = [] ): int { - $qb = $this->buildBaseQuery($pattern, $flags); + $qb = $this->buildBaseQuery($pattern, $flags, $users); return $this ->addACLGlobal($qb) @@ -231,11 +251,12 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository public function findByAllViewable( ?string $pattern = null, ?array $flags = [], + ?array $users = [], ?int $start = 0, ?int $limit = 50, ?array $orderBy = [] ): array { - $qb = $this->buildBaseQuery($pattern, $flags); + $qb = $this->buildBaseQuery($pattern, $flags, $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 57c57e592..7d2870c67 100644 --- a/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepositoryInterface.php +++ b/src/Bundle/ChillTaskBundle/Repository/SingleTaskAclAwareRepositoryInterface.php @@ -18,7 +18,8 @@ interface SingleTaskAclAwareRepositoryInterface { public function countByAllViewable( ?string $pattern = null, - ?array $flags = [] + ?array $flags = [], + ?array $users = [] ): int; public function countByCourse( @@ -38,6 +39,7 @@ interface SingleTaskAclAwareRepositoryInterface public function findByAllViewable( ?string $pattern = null, ?array $flags = [], + ?array $users = [], ?int $start = 0, ?int $limit = 50, ?array $orderBy = [] diff --git a/src/Bundle/ChillTaskBundle/translations/messages.fr.yml b/src/Bundle/ChillTaskBundle/translations/messages.fr.yml index d437baac2..599ca8640 100644 --- a/src/Bundle/ChillTaskBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillTaskBundle/translations/messages.fr.yml @@ -65,6 +65,7 @@ Not assigned: Aucun utilisateur assigné For person: Pour By: Par Any tasks: Aucune tâche +Filter by user: Filtrer par utilisateur(s) # transitions - default task definition "new": "nouvelle"