44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Validator;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Component\Validator\Constraint;
|
|
use Symfony\Component\Validator\ConstraintValidator;
|
|
|
|
/**
|
|
* @Annotation
|
|
*/
|
|
class Niveau01uniqueValidator 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\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->messageniveau03);
|
|
}
|
|
|
|
$niveau = $this->em->getRepository("App\Entity\Niveau04")->findOneBy(['label' => $value]);
|
|
if ($niveau) {
|
|
$this->context->addViolation($constraint->messageniveau04);
|
|
}
|
|
}
|
|
}
|