mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
social issues filter: improve render with parents, add parents in where clause
This commit is contained in:
parent
bb22317eb1
commit
0d38d4df40
@ -6,6 +6,7 @@ use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
@ -24,20 +25,27 @@ class SocialIssueFilter implements FilterInterface
|
||||
*/
|
||||
private TranslatableStringHelper $translatableStringHelper;
|
||||
|
||||
/**
|
||||
* @var SocialIssueRender
|
||||
*/
|
||||
private SocialIssueRender $socialIssueRender;
|
||||
|
||||
public function __construct(
|
||||
TranslatorInterface $translator,
|
||||
TranslatableStringHelper $translatableStringHelper
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
SocialIssueRender $socialIssueRender
|
||||
) {
|
||||
$this->translator = $translator;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->socialIssueRender = $socialIssueRender;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('accepted_socialissue', EntityType::class, [
|
||||
'class' => SocialIssue::class,
|
||||
'choice_label' => function(SocialIssue $s) {
|
||||
return $this->translatableStringHelper->localize($s->getTitle());
|
||||
'choice_label' => function ($socialIssue) {
|
||||
return $this->socialIssueRender->renderString($socialIssue, []);
|
||||
},
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
@ -57,7 +65,7 @@ class SocialIssueFilter implements FilterInterface
|
||||
if ('null' === $i) {
|
||||
$issues[] = $this->translator->trans('Not given');
|
||||
} else {
|
||||
$issues[] = $this->translatableStringHelper->localize($i->getTitle());
|
||||
$issues[] = $this->socialIssueRender->renderString($i, []);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,7 +94,44 @@ class SocialIssueFilter implements FilterInterface
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('socialissues', $data['accepted_socialissue']);
|
||||
$qb->setParameter('socialissues',
|
||||
$this->addParentIssues($data['accepted_socialissue'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* "Le filtre retiendra les parcours qui comportent cette problématique,
|
||||
* ou une problématique parente à celles choisies."
|
||||
*
|
||||
* Add parent of each socialissue selected, and remove duplicates
|
||||
*
|
||||
* @param $accepted_issues
|
||||
* @return array
|
||||
*/
|
||||
private function addParentIssues($accepted_issues)
|
||||
{
|
||||
$array = [];
|
||||
foreach ($accepted_issues as $i)
|
||||
{
|
||||
/** @var SocialIssue $i */
|
||||
if ($i->hasParent()) {
|
||||
$array[] = $i->getParent();
|
||||
}
|
||||
$array[] = $i;
|
||||
}
|
||||
return $this->removeDuplicate($array);
|
||||
}
|
||||
|
||||
private function removeDuplicate(array $array): array
|
||||
{
|
||||
$ids = array_map(function ($item) {
|
||||
return $item->getId();
|
||||
}, $array);
|
||||
|
||||
$unique_ids = array_unique($ids); dump($unique_ids);
|
||||
|
||||
return array_values(
|
||||
array_intersect_key($array, $unique_ids));
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
|
Loading…
x
Reference in New Issue
Block a user