mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
FEATURE [user filter] implement query. Selecting multiple users doesn't work
This commit is contained in:
parent
a34b5f8588
commit
4da7040a49
@ -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
|
||||
|
@ -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 %}
|
||||
<div class="row my-2">
|
||||
<div class="col-sm-8 pt-2">
|
||||
{% for p in form['user_pickers'][name].children %}
|
||||
{{ form_widget(p) }}
|
||||
{{ form_label(p) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if form.single_checkboxes is defined %}
|
||||
{% set btnSubmit = 1 %}
|
||||
{% for name, _o in form.single_checkboxes %}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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 = []
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user