mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
67 lines
2.1 KiB
PHP
67 lines
2.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod;
|
|
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
use Chill\PersonBundle\Templating\Entity\PersonRenderInterface;
|
|
use Symfony\Component\Validator\Constraint;
|
|
use Symfony\Component\Validator\ConstraintValidator;
|
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|
use Symfony\Component\Validator\Exception\UnexpectedValueException;
|
|
|
|
class LocationValidityValidator extends ConstraintValidator
|
|
{
|
|
private PersonRenderInterface $render;
|
|
|
|
public function __construct(PersonRenderInterface $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($period, 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();
|
|
}
|
|
}
|
|
}
|