fix: validator (#8)
Some checks failed
Cadoles/nineskeletor/pipeline/head There was a failure building this commit

Co-authored-by: Arnaud Fornerot <afornerot@cadoles.com>
Reviewed-on: #8
This commit is contained in:
2022-10-26 09:19:16 +02:00
parent 19fa75e2eb
commit e52fdd9083
14 changed files with 234 additions and 19 deletions

View File

@ -0,0 +1,17 @@
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class Groupunique extends Constraint
{
public $messagegroup = 'Un groupe utilise déjà ce label';
public $messageniveau01 = 'Un niveau de rang 01 utilise déjà ce label';
public $messageniveau02 = 'Un niveau de rang 02 utilise déjà ce label';
public $messageniveau03 = 'Un niveau de rang 03 utilise déjà ce label';
public $messageniveau04 = 'Un niveau de rang 04 utilise déjà ce label';
}

View 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 GroupuniqueValidator extends ConstraintValidator
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function validate($value, Constraint $constraint)
{
$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->messageniveau03);
}
$niveau = $this->em->getRepository("App\Entity\Niveau04")->findOneBy(['label' => $value]);
if ($niveau) {
$this->context->addViolation($constraint->messageniveau04);
}
}
}

View File

@ -10,5 +10,8 @@ use Symfony\Component\Validator\Constraint;
class Niveau01unique extends Constraint
{
public $messagegroup = 'Un groupe utilise déjà ce label';
public $messageniveau01 = 'Un niveau de rang 01 utilise déjà ce label';
public $messageniveau02 = 'Un niveau de rang 02 utilise déjà ce label';
public $messageniveau03 = 'Un niveau de rang 03 utilise déjà ce label';
public $messageniveau04 = 'Un niveau de rang 04 utilise déjà ce label';
}

View File

@ -25,9 +25,19 @@ class Niveau01uniqueValidator extends ConstraintValidator
$this->context->addViolation($constraint->messagegroup);
}
$niveau02 = $this->em->getRepository("App\Entity\Niveau02")->findOneBy(['label' => $value]);
if ($niveau02) {
$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);
}
}
}

View File

@ -11,4 +11,7 @@ class Niveau02unique extends Constraint
{
public $messagegroup = 'Un groupe utilise déjà ce label';
public $messageniveau01 = 'Un niveau de rang 01 utilise déjà ce label';
public $messageniveau02 = 'Un niveau de rang 02 utilise déjà ce label';
public $messageniveau03 = 'Un niveau de rang 03 utilise déjà ce label';
public $messageniveau04 = 'Un niveau de rang 04 utilise déjà ce label';
}

View File

@ -25,9 +25,19 @@ class Niveau02uniqueValidator extends ConstraintValidator
$this->context->addViolation($constraint->messagegroup);
}
$niveau02 = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $value]);
if ($niveau02) {
$niveau = $this->em->getRepository("App\Entity\Niveau01")->findOneBy(['label' => $value]);
if ($niveau) {
$this->context->addViolation($constraint->messageniveau01);
}
$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);
}
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class Niveau03unique extends Constraint
{
public $messagegroup = 'Un groupe utilise déjà ce label';
public $messageniveau01 = 'Un niveau de rang 01 utilise déjà ce label';
public $messageniveau02 = 'Un niveau de rang 02 utilise déjà ce label';
public $messageniveau03 = 'Un niveau de rang 03 utilise déjà ce label';
public $messageniveau04 = 'Un niveau de rang 04 utilise déjà ce label';
}

View 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 Niveau03uniqueValidator 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\Niveau04")->findOneBy(['label' => $value]);
if ($niveau) {
$this->context->addViolation($constraint->messageniveau04);
}
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class Niveau04unique extends Constraint
{
public $messagegroup = 'Un groupe utilise déjà ce label';
public $messageniveau01 = 'Un niveau de rang 01 utilise déjà ce label';
public $messageniveau02 = 'Un niveau de rang 02 utilise déjà ce label';
public $messageniveau03 = 'Un niveau de rang 03 utilise déjà ce label';
public $messageniveau04 = 'Un niveau de rang 04 utilise déjà ce label';
}

View 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);
}
}
}