mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
issue641: add descendants to selected in alterQuery
This commit is contained in:
parent
de7ba29853
commit
ccea6dd95c
@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
||||
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Chill\PersonBundle\Form\Type\Select2SocialIssueType;
|
||||
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
||||
@ -56,7 +57,9 @@ class SocialIssueFilter implements FilterInterface
|
||||
$clause = $qb->expr()->in('acpsocialissue.id', ':socialissues');
|
||||
|
||||
$qb ->andWhere($clause)
|
||||
->setParameter('socialissues', $data['accepted_socialissues']);
|
||||
->setParameter('socialissues',
|
||||
$this->addDescendantsIssues($data['accepted_socialissues'])
|
||||
);
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
@ -71,17 +74,18 @@ class SocialIssueFilter implements FilterInterface
|
||||
]);
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
$issues = [];
|
||||
|
||||
$socialissues = $data['accepted_socialissues'];
|
||||
|
||||
foreach ($socialissues as $i) {
|
||||
if ('null' === $i) {
|
||||
foreach ($socialissues as $si) {
|
||||
/** @var SocialIssue $si */
|
||||
if (null === $si) {
|
||||
$issues[] = $this->translator->trans('Not given');
|
||||
} else {
|
||||
$issues[] = $this->socialIssueRender->renderString($i, []);
|
||||
$issues[] = $this->socialIssueRender->renderString($si, []);
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,8 +95,36 @@ class SocialIssueFilter implements FilterInterface
|
||||
], ];
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Filter by social issue';
|
||||
}
|
||||
|
||||
private function addDescendantsIssues($accepted_socialissues): array
|
||||
{
|
||||
$array = [];
|
||||
|
||||
foreach ($accepted_socialissues as $si) {
|
||||
/** @var SocialIssue $si */
|
||||
$array[] = $si;
|
||||
if (!$si->hasParent()) {
|
||||
$array = array_merge($array, $si->getDescendants()->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
return $this->removeDuplicate($array);
|
||||
}
|
||||
|
||||
private function removeDuplicate(array $array): array
|
||||
{
|
||||
$ids = array_map(static function ($item) {
|
||||
return $item->getId();
|
||||
}, $array);
|
||||
|
||||
$unique_ids = array_unique($ids);
|
||||
|
||||
return array_values(
|
||||
array_intersect_key($array, $unique_ids)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user