mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
improvement on import - person may have a null gender
This commit is contained in:
@@ -83,6 +83,10 @@ class GenderAggregator implements AggregatorInterface
|
||||
return $this->translator->trans('woman');
|
||||
case Person::MALE_GENDER :
|
||||
return $this->translator->trans('man');
|
||||
case Person::BOTH_GENDER:
|
||||
return $this->translator->trans('both');
|
||||
case null:
|
||||
return $this->translator->trans('Not given');
|
||||
case '_header' :
|
||||
return $this->translator->trans('Gender');
|
||||
default:
|
||||
|
@@ -51,17 +51,19 @@ class GenderFilter implements FilterInterface,
|
||||
$builder->add('accepted_genders', ChoiceType::class, array(
|
||||
'choices' => array(
|
||||
'Woman' => Person::FEMALE_GENDER,
|
||||
'Man' => Person::MALE_GENDER
|
||||
'Man' => Person::MALE_GENDER,
|
||||
'Both' => Person::BOTH_GENDER,
|
||||
'Not given' => 'null'
|
||||
),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false
|
||||
'multiple' => true,
|
||||
'expanded' => true
|
||||
));
|
||||
}
|
||||
|
||||
public function validateForm($data, ExecutionContextInterface $context)
|
||||
{
|
||||
if ($data['accepted_genders'] === null) {
|
||||
if (!is_array($data['accepted_genders']) || count($data['accepted_genders']) === 0 ) {
|
||||
$context->buildViolation("You should select an option")
|
||||
->addViolation();
|
||||
}
|
||||
@@ -70,8 +72,13 @@ class GenderFilter implements FilterInterface,
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$where = $qb->getDQLPart('where');
|
||||
$clause = $qb->expr()->in('person.gender', ':person_gender');
|
||||
|
||||
$isIn = $qb->expr()->in('person.gender', ':person_gender');
|
||||
|
||||
if (!\in_array('null', $data['accepted_genders'])) {
|
||||
$clause = $isIn;
|
||||
} else {
|
||||
$clause = $qb->expr()->orX($isIn, $qb->expr()->isNull('person.gender'));
|
||||
}
|
||||
|
||||
if ($where instanceof Expr\Andx) {
|
||||
$where->add($clause);
|
||||
@@ -80,7 +87,11 @@ class GenderFilter implements FilterInterface,
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('person_gender', $data['accepted_genders']);
|
||||
$qb->setParameter('person_gender', \array_filter(
|
||||
$data['accepted_genders'],
|
||||
function($el) {
|
||||
return $el !== 'null';
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user