mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +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\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||||
use Chill\PersonBundle\Export\Declarations;
|
use Chill\PersonBundle\Export\Declarations;
|
||||||
|
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
||||||
use Doctrine\ORM\Query\Expr\Andx;
|
use Doctrine\ORM\Query\Expr\Andx;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
@ -24,20 +25,27 @@ class SocialIssueFilter implements FilterInterface
|
|||||||
*/
|
*/
|
||||||
private TranslatableStringHelper $translatableStringHelper;
|
private TranslatableStringHelper $translatableStringHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SocialIssueRender
|
||||||
|
*/
|
||||||
|
private SocialIssueRender $socialIssueRender;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
TranslatorInterface $translator,
|
TranslatorInterface $translator,
|
||||||
TranslatableStringHelper $translatableStringHelper
|
TranslatableStringHelper $translatableStringHelper,
|
||||||
|
SocialIssueRender $socialIssueRender
|
||||||
) {
|
) {
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->translatableStringHelper = $translatableStringHelper;
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
|
$this->socialIssueRender = $socialIssueRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder)
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
$builder->add('accepted_socialissue', EntityType::class, [
|
$builder->add('accepted_socialissue', EntityType::class, [
|
||||||
'class' => SocialIssue::class,
|
'class' => SocialIssue::class,
|
||||||
'choice_label' => function(SocialIssue $s) {
|
'choice_label' => function ($socialIssue) {
|
||||||
return $this->translatableStringHelper->localize($s->getTitle());
|
return $this->socialIssueRender->renderString($socialIssue, []);
|
||||||
},
|
},
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
@ -57,7 +65,7 @@ class SocialIssueFilter implements FilterInterface
|
|||||||
if ('null' === $i) {
|
if ('null' === $i) {
|
||||||
$issues[] = $this->translator->trans('Not given');
|
$issues[] = $this->translator->trans('Not given');
|
||||||
} else {
|
} 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->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()
|
public function applyOn()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user