mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
[AccompanyingPeriod] create constraints for location
This commit is contained in:
parent
3302d69373
commit
a3a5d5cfd0
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
*/
|
||||||
|
class LocationValidity extends Constraint
|
||||||
|
{
|
||||||
|
public $messagePersonLocatedMustBeAssociated = "The person where the course is located must be associated to the course. Change course's location before removing the person.";
|
||||||
|
|
||||||
|
public $messagPeriodMustRemainsLocated = "The period must remains located";
|
||||||
|
|
||||||
|
public function getTargets()
|
||||||
|
{
|
||||||
|
return self::CLASS_CONSTRAINT;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
use Symfony\Component\Validator\ConstraintValidator;
|
||||||
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||||
|
use Symfony\Component\Validator\Exception\UnexpectedValueException;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
|
use Chill\PersonBundle\Templating\Entity\PersonRender;
|
||||||
|
|
||||||
|
class LocationValidityValidator extends ConstraintValidator
|
||||||
|
{
|
||||||
|
private PersonRender $render;
|
||||||
|
|
||||||
|
public function __construct(PersonRender $render)
|
||||||
|
{
|
||||||
|
$this->render = $render;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validate($period, Constraint $constraint)
|
||||||
|
{
|
||||||
|
if (!$constraint instanceof LocationValidity) {
|
||||||
|
throw new UnexpectedTypeException($constraint, LocationValidity::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$period instanceof AccompanyingPeriod) {
|
||||||
|
throw new UnexpectedValueException($value, AccompanyingPeriod::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($period->getLocationStatus() === 'person') {
|
||||||
|
if (null === $period->getOpenParticipationContainsPerson(
|
||||||
|
$period->getPersonLocation())) {
|
||||||
|
$this->context->buildViolation($constraint->messagePersonLocatedMustBeAssociated)
|
||||||
|
->setParameter('{{ person_name }}', $this->render->renderString(
|
||||||
|
$period->getPersonLocation(), []
|
||||||
|
))
|
||||||
|
->addViolation()
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($period->getStep() !== AccompanyingPeriod::STEP_DRAFT
|
||||||
|
&& $period->getLocationStatus() === 'none') {
|
||||||
|
$this->context->buildViolation($constraint->messagePeriodMustRemainsLocated
|
||||||
|
->addViolation()
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -97,3 +97,8 @@ services:
|
|||||||
resource: '../Templating/Entity'
|
resource: '../Templating/Entity'
|
||||||
tags:
|
tags:
|
||||||
- 'chill.render_entity'
|
- 'chill.render_entity'
|
||||||
|
|
||||||
|
Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\:
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
resource: '../Validator/Constraints/AccompanyingPeriod'
|
||||||
|
@ -81,6 +81,7 @@ Chill\PersonBundle\Entity\AccompanyingPeriod:
|
|||||||
constraints:
|
constraints:
|
||||||
- Callback:
|
- Callback:
|
||||||
callback: isDateConsistent
|
callback: isDateConsistent
|
||||||
|
- 'Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod\LocationValidity': ~
|
||||||
|
|
||||||
Chill\PersonBundle\Entity\PersonPhone:
|
Chill\PersonBundle\Entity\PersonPhone:
|
||||||
properties:
|
properties:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user