fix: validator (#8)
Cadoles/nineskeletor/pipeline/head There was a failure building this commit
Details
Cadoles/nineskeletor/pipeline/head There was a failure building this commit
Details
Co-authored-by: Arnaud Fornerot <afornerot@cadoles.com> Reviewed-on: #8
This commit is contained in:
parent
19fa75e2eb
commit
e52fdd9083
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Validator;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
@ -25,6 +26,8 @@ class Group
|
|||
private $id;
|
||||
|
||||
/**
|
||||
* @Validator\Grouplabel()
|
||||
* @Validator\Groupunique()
|
||||
* @ORM\Column(type="string", length=250, unique=true)
|
||||
*/
|
||||
private $label;
|
||||
|
|
|
@ -193,22 +193,28 @@ class LdapService
|
|||
{
|
||||
$connection = $this->connect();
|
||||
if (false == $recursive) {
|
||||
$removed = ldap_delete($connection, $dn);
|
||||
if (!$removed) {
|
||||
$this->ldapError();
|
||||
}
|
||||
} else {
|
||||
// searching for sub entries
|
||||
$sr = ldap_list($connection, $dn, 'ObjectClass=*', ['']);
|
||||
$info = ldap_get_entries($connection, $sr);
|
||||
for ($i = 0; $i < $info['count']; ++$i) {
|
||||
$result = $this->deleteByDN($info[$i]['dn'], $recursive);
|
||||
if (!$result) {
|
||||
return $result;
|
||||
$ldapentrys = $this->searchdn($dn);
|
||||
if (!empty($ldapentrys)) {
|
||||
$removed = ldap_delete($connection, $dn);
|
||||
if (!$removed) {
|
||||
$this->ldapError();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ldapentrys = $this->searchdn($dn);
|
||||
if (!empty($ldapentrys)) {
|
||||
// searching for sub entries
|
||||
$sr = ldap_list($connection, $dn, 'ObjectClass=*', ['']);
|
||||
$info = ldap_get_entries($connection, $sr);
|
||||
for ($i = 0; $i < $info['count']; ++$i) {
|
||||
$result = $this->deleteByDN($info[$i]['dn'], $recursive);
|
||||
if (!$result) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return ldap_delete($connection, $dn);
|
||||
return ldap_delete($connection, $dn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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';
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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';
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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';
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -66,7 +66,7 @@
|
|||
|
||||
{% if auditUse and mode=="update" and (access=="admin" or access=="modo" or access=="audit") %}
|
||||
<div class="float-end" style="width:700px;max-width:100%">
|
||||
{{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau02",entityid:niveau03.id})) }}
|
||||
{{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau03",entityid:niveau03.id})) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{{ form_end(form) }}
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
|
||||
{% if auditUse and mode=="update" and (access=="admin" or access=="modo" or access=="audit") %}
|
||||
<div class="float-end" style="width:700px;max-width:100%">
|
||||
{{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau02",entityid:niveau03.id})) }}
|
||||
{{ render(path("app_"~access~"_audit_renderid",{entityname:"Niveau04",entityid:niveau04.id})) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{{ form_end(form) }}
|
||||
|
|
Loading…
Reference in New Issue