fix: validator
This commit is contained in:
43
src/Validator/Niveau04uniqueValidator.php
Normal file
43
src/Validator/Niveau04uniqueValidator.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Validator;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class Niveau04uniqueValidator 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);
|
||||
}
|
||||
|
||||
$niveau = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $value]);
|
||||
if ($niveau) {
|
||||
$this->context->addViolation($constraint->messageniveau01);
|
||||
}
|
||||
|
||||
$niveau = $this->em->getRepository("App\Entity\Niveau02")->findOneBy(['label' => $value]);
|
||||
if ($niveau) {
|
||||
$this->context->addViolation($constraint->messageniveau02);
|
||||
}
|
||||
|
||||
$niveau = $this->em->getRepository("App\Entity\Niveau03")->findOneBy(['label' => $value]);
|
||||
if ($niveau) {
|
||||
$this->context->addViolation($constraint->messageniveau04);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user