diff --git a/src/Bundle/ChillPersonBundle/Search/PersonSearch.php b/src/Bundle/ChillPersonBundle/Search/PersonSearch.php index fef17b5c5..3de2fd4f1 100644 --- a/src/Bundle/ChillPersonBundle/Search/PersonSearch.php +++ b/src/Bundle/ChillPersonBundle/Search/PersonSearch.php @@ -116,23 +116,23 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf { $string = '@person '; - $string .= empty($data['_default']) ? '' : $data['_default'] . ' '; + $string .= !isset($data['_default']) ? '' : $data['_default'] . ' '; foreach (['firstname', 'lastname', 'gender', 'city'] as $key) { - $string .= empty($data[$key]) ? '' : $key . ':' . + $string .= !isset($data[$key]) ? '' : $key . ':' . // add quote if contains spaces (strpos($data[$key], ' ') !== false ? '"' . $data[$key] . '"' : $data[$key]) . ' '; } foreach (['birthdate', 'birthdate-before', 'birthdate-after'] as $key) { - $string .= empty($data[$key]) ? + $string .= !isset($data[$key]) ? '' : $key . ':' . $data[$key]->format('Y-m-d') . ' '; } - $string .= empty($data['phonenumber']) ? '' : 'phonenumber:' . $data['phonenumber']->getNationalNumber(); + $string .= !isset($data['phonenumber']) ? '' : 'phonenumber:' . $data['phonenumber']->getNationalNumber(); return $string; } @@ -163,7 +163,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf $phonenumber = new PhoneNumber(); $phonenumber->setNationalNumber($terms['phonenumber']); } catch (Exception $ex) { - throw new ParsingException("The data for {$key} is " + throw new ParsingException("The data for phonenumber is " . 'not parsable', 0, $ex); } @@ -267,14 +267,30 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf 'city' => $city, ] = $terms + array_fill_keys(self::POSSIBLE_KEYS, null); - foreach (['birthdateBefore', 'birthdateAfter', 'birthdate'] as $v) { - if (null !== ${$v}) { - try { - ${$v} = new DateTime(${$v}); - } catch (Exception $e) { - throw new ParsingException('The date is ' - . 'not parsable', 0, $e); - } + if (null !== $birthdate) { + try { + $birthdate = new DateTime($birthdate); + } catch (Exception $e) { + throw new ParsingException('The date is ' + . 'not parsable', 0, $e); + } + } + + if (null !== $birthdateBefore) { + try { + $birthdateBefore = new DateTime($birthdateBefore); + } catch (Exception $e) { + throw new ParsingException('The date is ' + . 'not parsable', 0, $e); + } + } + + if (null !== $birthdateAfter) { + try { + $birthdateAfter = new DateTime($birthdateAfter); + } catch (Exception $e) { + throw new ParsingException('The date is ' + . 'not parsable', 0, $e); } } @@ -311,14 +327,30 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf 'city' => $city, ] = $terms + array_fill_keys(self::POSSIBLE_KEYS, null); - foreach (['birthdateBefore', 'birthdateAfter', 'birthdate'] as $v) { - if (null !== ${$v}) { - try { - ${$v} = new DateTime(${$v}); - } catch (Exception $e) { - throw new ParsingException('The date is ' - . 'not parsable', 0, $e); - } + if (null !== $birthdate) { + try { + $birthdate = new DateTime($birthdate); + } catch (Exception $e) { + throw new ParsingException('The date is ' + . 'not parsable', 0, $e); + } + } + + if (null !== $birthdateBefore) { + try { + $birthdateBefore = new DateTime($birthdateBefore); + } catch (Exception $e) { + throw new ParsingException('The date is ' + . 'not parsable', 0, $e); + } + } + + if (null !== $birthdateAfter) { + try { + $birthdateAfter = new DateTime($birthdateAfter); + } catch (Exception $e) { + throw new ParsingException('The date is ' + . 'not parsable', 0, $e); } } diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlapValidator.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlapValidator.php index 527bb43cb..67ee00756 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlapValidator.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/ParticipationOverlapValidator.php @@ -78,15 +78,14 @@ class ParticipationOverlapValidator extends ConstraintValidator if ($overlaps->hasIntersections()) { foreach ($overlaps->getIntersections() as [$start, $end, $ids]) { - $msg = null === $end ? $constraint->message : - $constraint->message; + $msg = $constraint->message; $this->context->buildViolation($msg) ->setParameters([ '{{ start }}' => $start->format('d-m-Y'), '{{ end }}' => null === $end ? null : $end->format('d-m-Y'), '{{ ids }}' => $ids, - '{{ name }}' => $this->personRender->renderString($participation->getPerson(), []), + '{{ name }}' => $this->personRender->renderString($participations[0]->getPerson(), []), ]) ->addViolation(); } diff --git a/src/Bundle/ChillThirdPartyBundle/Form/ChoiceLoader/ThirdPartyChoiceLoader.php b/src/Bundle/ChillThirdPartyBundle/Form/ChoiceLoader/ThirdPartyChoiceLoader.php index 3b5931aa6..7d5bded0f 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/ChoiceLoader/ThirdPartyChoiceLoader.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/ChoiceLoader/ThirdPartyChoiceLoader.php @@ -59,10 +59,6 @@ class ThirdPartyChoiceLoader implements ChoiceLoaderInterface $choices = []; foreach ($values as $value) { - if (null === $value || '' === $value) { - continue; - } - $party = $this->partyRepository->find($value); if (false === in_array($this->center, $party->getCenters()->toArray(), true)) {