mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
issue641: same for actions: take children, propose only associated and sort them by ordering
This commit is contained in:
@@ -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\SocialAction;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Chill\PersonBundle\Form\Type\Select2SocialActionType;
|
||||
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
|
||||
@@ -52,7 +53,9 @@ class SocialActionFilter implements FilterInterface
|
||||
$clause = $qb->expr()->in('acpwsocialaction.id', ':socialactions');
|
||||
|
||||
$qb ->andWhere($clause)
|
||||
->setParameter('socialactions', $data['accepted_socialactions']);
|
||||
->setParameter('socialactions',
|
||||
$this->addDescendantsActions($data['accepted_socialactions'])
|
||||
);
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
@@ -69,14 +72,16 @@ class SocialActionFilter implements FilterInterface
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
$socialactions = [];
|
||||
$actions = [];
|
||||
|
||||
foreach ($data['accepted_socialactions'] as $sa) {
|
||||
$socialactions[] = $this->actionRender->renderString($sa, []);
|
||||
$socialactions = $data['accepted_socialactions'];
|
||||
|
||||
foreach ($socialactions as $action) {
|
||||
$actions[] = $this->renderAction($action);
|
||||
}
|
||||
|
||||
return ['Filtered by socialactions: only %socialactions%', [
|
||||
'%socialactions%' => implode(', ou ', $socialactions),
|
||||
'%socialactions%' => implode(', ou ', $actions),
|
||||
]];
|
||||
}
|
||||
|
||||
@@ -84,4 +89,45 @@ class SocialActionFilter implements FilterInterface
|
||||
{
|
||||
return 'Filter by socialaction';
|
||||
}
|
||||
|
||||
private function addDescendantsActions($accepted_socialactions): array
|
||||
{
|
||||
$array = [];
|
||||
|
||||
foreach ($accepted_socialactions as $action) {
|
||||
/** @var SocialAction $action */
|
||||
$array[] = $action;
|
||||
if (!$action->hasParent()) {
|
||||
$array = array_merge($array, $action->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)
|
||||
);
|
||||
}
|
||||
|
||||
private function renderAction(SocialAction $action): string
|
||||
{
|
||||
$render_str = $this->actionRender->renderString($action, []);
|
||||
|
||||
if (!$action->hasParent()) {
|
||||
if (count($action->getDescendants()) > 0) {
|
||||
return $render_str . " (et dérivés)";
|
||||
}
|
||||
}
|
||||
|
||||
return $render_str;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user