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()) {
|
if ([] !== $helper->getUserPickers()) {
|
||||||
$userPickersBuilder = $builder->create('userPicker', null, ['compound' => true]);
|
$userPickersBuilder = $builder->create('user_pickers', null, ['compound' => true]);
|
||||||
|
|
||||||
foreach ($helper->getUserPickers() as $name => [
|
foreach ($helper->getUserPickers() as $name => [
|
||||||
'label' => $label, 'options' => $options
|
'label' => $label, 'options' => $options
|
||||||
|
@ -67,6 +67,22 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% 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 %}
|
{% if form.single_checkboxes is defined %}
|
||||||
{% set btnSubmit = 1 %}
|
{% set btnSubmit = 1 %}
|
||||||
{% for name, _o in form.single_checkboxes %}
|
{% for name, _o in form.single_checkboxes %}
|
||||||
|
@ -87,7 +87,7 @@ class FilterOrderHelper
|
|||||||
return $this->entityChoices;
|
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];
|
$this->userPickers[$name] = ['label' => $label, 'options' => $options];
|
||||||
|
|
||||||
@ -136,7 +136,8 @@ class FilterOrderHelper
|
|||||||
|
|
||||||
public function getUserPickerData(string $name): array
|
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
|
public function getCheckboxData(string $name): array
|
||||||
|
@ -88,7 +88,7 @@ class FilterOrderHelperBuilder
|
|||||||
return $this;
|
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];
|
$this->userPickers[$name] = ['label' => $label, 'options' => $options];
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ class FilterOrderHelperBuilder
|
|||||||
'options' => $options
|
'options' => $options
|
||||||
]
|
]
|
||||||
) {
|
) {
|
||||||
$helper->addUserPickers($name, $label, $options);
|
$helper->addUserPicker($name, $label, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -300,13 +300,16 @@ final class SingleTaskController extends AbstractController
|
|||||||
|
|
||||||
$filterOrder = $this->buildFilterOrder();
|
$filterOrder = $this->buildFilterOrder();
|
||||||
|
|
||||||
|
$filteredUsers = $filterOrder->getUserPickerData('userPicker');
|
||||||
|
|
||||||
$flags = array_merge(
|
$flags = array_merge(
|
||||||
$filterOrder->getCheckboxData('status'),
|
$filterOrder->getCheckboxData('status'),
|
||||||
array_map(static fn ($i) => 'state_' . $i, $filterOrder->getCheckboxData('states'))
|
array_map(static fn ($i) => 'state_' . $i, $filterOrder->getCheckboxData('states'))
|
||||||
);
|
);
|
||||||
$nb = $this->singleTaskAclAwareRepository->countByAllViewable(
|
$nb = $this->singleTaskAclAwareRepository->countByAllViewable(
|
||||||
$filterOrder->getQueryString(),
|
$filterOrder->getQueryString(),
|
||||||
$flags
|
$flags,
|
||||||
|
$filteredUsers
|
||||||
);
|
);
|
||||||
$paginator = $this->paginatorFactory->create($nb);
|
$paginator = $this->paginatorFactory->create($nb);
|
||||||
|
|
||||||
@ -314,6 +317,7 @@ final class SingleTaskController extends AbstractController
|
|||||||
$tasks = $this->singleTaskAclAwareRepository->findByAllViewable(
|
$tasks = $this->singleTaskAclAwareRepository->findByAllViewable(
|
||||||
$filterOrder->getQueryString(),
|
$filterOrder->getQueryString(),
|
||||||
$flags,
|
$flags,
|
||||||
|
$filteredUsers,
|
||||||
$paginator->getCurrentPageFirstItemNumber(),
|
$paginator->getCurrentPageFirstItemNumber(),
|
||||||
$paginator->getItemsPerPage(),
|
$paginator->getItemsPerPage(),
|
||||||
[
|
[
|
||||||
@ -681,7 +685,7 @@ final class SingleTaskController extends AbstractController
|
|||||||
->addSearchBox()
|
->addSearchBox()
|
||||||
->addCheckbox('status', $statuses, $statuses, $statusTrans)
|
->addCheckbox('status', $statuses, $statuses, $statusTrans)
|
||||||
->addCheckbox('states', $states, ['new', 'in_progress'])
|
->addCheckbox('states', $states, ['new', 'in_progress'])
|
||||||
->addUserPickers('userPicker', 'userPicker', ['multiple' => True])
|
->addUserPicker('userPicker', 'Filter by user', ['multiple' => True, 'required' => False])
|
||||||
->build();
|
->build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,8 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository
|
|||||||
|
|
||||||
public function buildBaseQuery(
|
public function buildBaseQuery(
|
||||||
?string $pattern = null,
|
?string $pattern = null,
|
||||||
?array $flags = []
|
?array $flags = [],
|
||||||
|
?array $users = []
|
||||||
): QueryBuilder {
|
): QueryBuilder {
|
||||||
$qb = $this->em->createQueryBuilder();
|
$qb = $this->em->createQueryBuilder();
|
||||||
$qb
|
$qb
|
||||||
@ -62,6 +63,24 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository
|
|||||||
->setParameter('pattern', '%' . $pattern . '%');
|
->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) {
|
if (count($flags) > 0) {
|
||||||
$orXDate = $qb->expr()->orX();
|
$orXDate = $qb->expr()->orX();
|
||||||
$orXState = $qb->expr()->orX();
|
$orXState = $qb->expr()->orX();
|
||||||
@ -183,9 +202,10 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository
|
|||||||
|
|
||||||
public function countByAllViewable(
|
public function countByAllViewable(
|
||||||
?string $pattern = null,
|
?string $pattern = null,
|
||||||
?array $flags = []
|
?array $flags = [],
|
||||||
|
?array $users = []
|
||||||
): int {
|
): int {
|
||||||
$qb = $this->buildBaseQuery($pattern, $flags);
|
$qb = $this->buildBaseQuery($pattern, $flags, $users);
|
||||||
|
|
||||||
return $this
|
return $this
|
||||||
->addACLGlobal($qb)
|
->addACLGlobal($qb)
|
||||||
@ -231,11 +251,12 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository
|
|||||||
public function findByAllViewable(
|
public function findByAllViewable(
|
||||||
?string $pattern = null,
|
?string $pattern = null,
|
||||||
?array $flags = [],
|
?array $flags = [],
|
||||||
|
?array $users = [],
|
||||||
?int $start = 0,
|
?int $start = 0,
|
||||||
?int $limit = 50,
|
?int $limit = 50,
|
||||||
?array $orderBy = []
|
?array $orderBy = []
|
||||||
): array {
|
): array {
|
||||||
$qb = $this->buildBaseQuery($pattern, $flags);
|
$qb = $this->buildBaseQuery($pattern, $flags, $users);
|
||||||
$qb = $this->addACLGlobal($qb);
|
$qb = $this->addACLGlobal($qb);
|
||||||
|
|
||||||
return $this->getResult($qb, $start, $limit, $orderBy);
|
return $this->getResult($qb, $start, $limit, $orderBy);
|
||||||
|
@ -18,7 +18,8 @@ interface SingleTaskAclAwareRepositoryInterface
|
|||||||
{
|
{
|
||||||
public function countByAllViewable(
|
public function countByAllViewable(
|
||||||
?string $pattern = null,
|
?string $pattern = null,
|
||||||
?array $flags = []
|
?array $flags = [],
|
||||||
|
?array $users = []
|
||||||
): int;
|
): int;
|
||||||
|
|
||||||
public function countByCourse(
|
public function countByCourse(
|
||||||
@ -38,6 +39,7 @@ interface SingleTaskAclAwareRepositoryInterface
|
|||||||
public function findByAllViewable(
|
public function findByAllViewable(
|
||||||
?string $pattern = null,
|
?string $pattern = null,
|
||||||
?array $flags = [],
|
?array $flags = [],
|
||||||
|
?array $users = [],
|
||||||
?int $start = 0,
|
?int $start = 0,
|
||||||
?int $limit = 50,
|
?int $limit = 50,
|
||||||
?array $orderBy = []
|
?array $orderBy = []
|
||||||
|
@ -65,6 +65,7 @@ Not assigned: Aucun utilisateur assigné
|
|||||||
For person: Pour
|
For person: Pour
|
||||||
By: Par
|
By: Par
|
||||||
Any tasks: Aucune tâche
|
Any tasks: Aucune tâche
|
||||||
|
Filter by user: Filtrer par utilisateur(s)
|
||||||
|
|
||||||
# transitions - default task definition
|
# transitions - default task definition
|
||||||
"new": "nouvelle"
|
"new": "nouvelle"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user