32 lines
844 B
PHP
32 lines
844 B
PHP
<?php
|
|
namespace App\Validator;
|
|
|
|
use Symfony\Component\Validator\Constraint;
|
|
use Symfony\Component\Validator\ConstraintValidator;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
/**
|
|
* @Annotation
|
|
*/
|
|
class Niveau02uniqueValidator extends ConstraintValidator
|
|
{
|
|
protected $em;
|
|
|
|
public function __construct(EntityManagerInterface $em)
|
|
{
|
|
$this->em = $em;
|
|
}
|
|
|
|
public function validate($value, Constraint $constraint)
|
|
{
|
|
$group = $this->em->getRepository("App\Entity\Group")->findOneBy(["label"=>$value]);
|
|
if($group) {
|
|
$this->context->addViolation($constraint->messagegroup);
|
|
}
|
|
|
|
$niveau02 = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(["label"=>$value]);
|
|
if($niveau02) {
|
|
$this->context->addViolation($constraint->messageniveau01);
|
|
}
|
|
}
|
|
} |