mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
add validator which force confidential course to keep a referrer
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<?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 Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class ConfidentialCourseMustHaveReferrer extends Constraint
|
||||
{
|
||||
public string $message = 'A confidential parcours must have a referrer';
|
||||
|
||||
public function getTargets()
|
||||
{
|
||||
return [self::CLASS_CONSTRAINT];
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Validator\Constraints\AccompanyingPeriod;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
class ConfidentialCourseMustHaveReferrerValidator extends ConstraintValidator
|
||||
{
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (!$value instanceof AccompanyingPeriod) {
|
||||
throw new UnexpectedTypeException($value, AccompanyingPeriod::class);
|
||||
}
|
||||
|
||||
if (!$constraint instanceof ConfidentialCourseMustHaveReferrer) {
|
||||
throw new UnexpectedTypeException($constraint, ConfidentialCourseMustHaveReferrer::class);
|
||||
}
|
||||
|
||||
if ($value->isConfidential() && null === $value->getUser()) {
|
||||
$this->context
|
||||
->buildViolation($constraint->message)
|
||||
->atPath('user')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user