Loading src/UnicaenPrivilege/Controller/PrivilegeController.php +2 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ class PrivilegeController extends AbstractActionController $privilege->setCategorie($categorie); $form = $this->privilegeForm; $form->setAttribute('action', $this->url()->fromRoute('unicaen-privilege/ajouter', ['categorie' => $categorie->getId()], [], true)); $form->get('categorieId')->setValue($categorie->getId()); $form->bind($privilege); if ($data = $this->params()->fromPost()) { Loading Loading @@ -72,6 +73,7 @@ class PrivilegeController extends AbstractActionController $privilege = $this->privilegeService->getRequestedPrivilege($this); $form = $this->privilegeForm; $form->setAttribute('action', $this->url()->fromRoute('unicaen-privilege/modifier', ['privilege' => $privilege->getId()], [], true)); $form->get('categorieId')->setValue($privilege->getCategorie()->getId()); $form->bind($privilege); if ($data = $this->params()->fromPost()) { Loading src/UnicaenPrivilege/Form/Categorie/CategorieForm.php +39 −20 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use Zend\Form\Form; use Zend\InputFilter\Factory; use Zend\Validator\Callback; use Zend\Validator\NotEmpty; use Zend\Validator\Regex; class CategorieForm extends Form { Loading @@ -23,12 +24,6 @@ class CategorieForm extends Form { $this->setAttribute('id', 'form-categorie'); /** nécessaire pour le validator @see \DoctrineModule\Validator\UniqueObject */ $this->add([ 'name' => 'id', 'type' => Hidden::class, ]); $this->add([ 'type' => Text::class, 'name' => 'libelle', Loading Loading @@ -108,17 +103,24 @@ class CategorieForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Callback::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->categorieService->getRepo(), 'use_context' => true, 'fields' => ['libelle'], 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Ce libellé est déjà utilisé dans l'application.", Callback::INVALID_VALUE => "Ce libellé est déjà utilisé pour une autre catégorie.", ], 'callback' => function ($value, $context = []) { $categorie = $this->categorieService->findByLibelle($value); if(!$categorie) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getLibelle()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading @@ -135,17 +137,34 @@ class CategorieForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Regex::class, 'options' => [ 'pattern' => '/^[a-z0-9_-]+$/', 'messages' => [ Regex::NOT_MATCH => "Seuls les caractères suivants sont autorisés : [a-z, 0-9, _, -].", ], 'break_chain_on_failure' => true, ], ], [ 'name' => Callback::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->categorieService->getRepo(), 'use_context' => true, 'fields' => ['code'], 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Ce code est déjà utilisé dans l'application.", Callback::INVALID_VALUE => "Ce code est déjà utilisé pour une autre catégorie.", ], 'callback' => function ($value, $context = []) { $categorie = $this->categorieService->findByCode($value); if(!$categorie) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getCode()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading src/UnicaenPrivilege/Form/Privilege/PrivilegeForm.php +43 −16 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ use Zend\Form\Form; use Zend\InputFilter\Factory; use Zend\Validator\Callback; use Zend\Validator\NotEmpty; use Zend\Validator\Regex; class PrivilegeForm extends Form { Loading @@ -29,10 +30,9 @@ class PrivilegeForm extends Form { $this->setAttribute('id', 'form-privilege'); /** nécessaire pour le validator @see \DoctrineModule\Validator\UniqueObject */ $this->add([ 'name' => 'id', 'type' => Hidden::class, 'name' => 'categorieId', ]); $this->add([ Loading @@ -54,6 +54,7 @@ class PrivilegeForm extends Form ], 'attributes' => [ 'id' => 'categorie', 'readonly' => true ], ]); Loading Loading @@ -126,17 +127,25 @@ class PrivilegeForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Callback::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->privilegeService->getRepo(), 'use_context' => true, 'fields' => ['libelle'], 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Ce libellé est déjà utilisé dans l'application.", Callback::INVALID_VALUE => "Ce libellé est déjà utilisé pour un autre privilège de cette catégorie.", ], 'callback' => function ($value, $context = []) { $categorie = $this->categorieService->find($context['categorieId']); $privilege = $this->privilegeService->findByLibelle($value, $categorie); if(!$privilege) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getLibelle()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading @@ -153,17 +162,35 @@ class PrivilegeForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Regex::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->privilegeService->getRepo(), 'use_context' => true, 'fields' => ['code'], 'pattern' => '/^[a-z0-9_-]+$/', 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Ce code est déjà utilisé dans l'application.", Regex::NOT_MATCH => "Seuls les caractères suivants sont autorisés : [a-z, 0-9, _, -].", ], 'break_chain_on_failure' => true, ], ], [ 'name' => Callback::class, 'options' => [ 'messages' => [ Callback::INVALID_VALUE => "Ce code est déjà utilisé pour un autre privilège de cette catégorie.", ], 'callback' => function ($value, $context = []) { $categorie = $this->categorieService->find($context['categorieId']); $privilege = $this->privilegeService->findByCode($value, $categorie); if(!$privilege) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getCode()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading view/unicaen-privilege/categorie/index.phtml +1 −1 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ $canProvider = $this->isAllowed(PrivilegePrivileges::getResourceId(PrivilegeP </a> </td> <td> <code><?php echo $categorie->getNamespace(); ?></code> <?php echo $categorie->getNamespace() ? sprintf('<code>%s</code>', $categorie->getNamespace()) : ''; ?> </td> <td><?php echo $categorie->getOrdre(); ?></td> <td> Loading Loading
src/UnicaenPrivilege/Controller/PrivilegeController.php +2 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ class PrivilegeController extends AbstractActionController $privilege->setCategorie($categorie); $form = $this->privilegeForm; $form->setAttribute('action', $this->url()->fromRoute('unicaen-privilege/ajouter', ['categorie' => $categorie->getId()], [], true)); $form->get('categorieId')->setValue($categorie->getId()); $form->bind($privilege); if ($data = $this->params()->fromPost()) { Loading Loading @@ -72,6 +73,7 @@ class PrivilegeController extends AbstractActionController $privilege = $this->privilegeService->getRequestedPrivilege($this); $form = $this->privilegeForm; $form->setAttribute('action', $this->url()->fromRoute('unicaen-privilege/modifier', ['privilege' => $privilege->getId()], [], true)); $form->get('categorieId')->setValue($privilege->getCategorie()->getId()); $form->bind($privilege); if ($data = $this->params()->fromPost()) { Loading
src/UnicaenPrivilege/Form/Categorie/CategorieForm.php +39 −20 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use Zend\Form\Form; use Zend\InputFilter\Factory; use Zend\Validator\Callback; use Zend\Validator\NotEmpty; use Zend\Validator\Regex; class CategorieForm extends Form { Loading @@ -23,12 +24,6 @@ class CategorieForm extends Form { $this->setAttribute('id', 'form-categorie'); /** nécessaire pour le validator @see \DoctrineModule\Validator\UniqueObject */ $this->add([ 'name' => 'id', 'type' => Hidden::class, ]); $this->add([ 'type' => Text::class, 'name' => 'libelle', Loading Loading @@ -108,17 +103,24 @@ class CategorieForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Callback::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->categorieService->getRepo(), 'use_context' => true, 'fields' => ['libelle'], 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Ce libellé est déjà utilisé dans l'application.", Callback::INVALID_VALUE => "Ce libellé est déjà utilisé pour une autre catégorie.", ], 'callback' => function ($value, $context = []) { $categorie = $this->categorieService->findByLibelle($value); if(!$categorie) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getLibelle()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading @@ -135,17 +137,34 @@ class CategorieForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Regex::class, 'options' => [ 'pattern' => '/^[a-z0-9_-]+$/', 'messages' => [ Regex::NOT_MATCH => "Seuls les caractères suivants sont autorisés : [a-z, 0-9, _, -].", ], 'break_chain_on_failure' => true, ], ], [ 'name' => Callback::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->categorieService->getRepo(), 'use_context' => true, 'fields' => ['code'], 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Ce code est déjà utilisé dans l'application.", Callback::INVALID_VALUE => "Ce code est déjà utilisé pour une autre catégorie.", ], 'callback' => function ($value, $context = []) { $categorie = $this->categorieService->findByCode($value); if(!$categorie) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getCode()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading
src/UnicaenPrivilege/Form/Privilege/PrivilegeForm.php +43 −16 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ use Zend\Form\Form; use Zend\InputFilter\Factory; use Zend\Validator\Callback; use Zend\Validator\NotEmpty; use Zend\Validator\Regex; class PrivilegeForm extends Form { Loading @@ -29,10 +30,9 @@ class PrivilegeForm extends Form { $this->setAttribute('id', 'form-privilege'); /** nécessaire pour le validator @see \DoctrineModule\Validator\UniqueObject */ $this->add([ 'name' => 'id', 'type' => Hidden::class, 'name' => 'categorieId', ]); $this->add([ Loading @@ -54,6 +54,7 @@ class PrivilegeForm extends Form ], 'attributes' => [ 'id' => 'categorie', 'readonly' => true ], ]); Loading Loading @@ -126,17 +127,25 @@ class PrivilegeForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Callback::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->privilegeService->getRepo(), 'use_context' => true, 'fields' => ['libelle'], 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Ce libellé est déjà utilisé dans l'application.", Callback::INVALID_VALUE => "Ce libellé est déjà utilisé pour un autre privilège de cette catégorie.", ], 'callback' => function ($value, $context = []) { $categorie = $this->categorieService->find($context['categorieId']); $privilege = $this->privilegeService->findByLibelle($value, $categorie); if(!$privilege) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getLibelle()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading @@ -153,17 +162,35 @@ class PrivilegeForm extends Form ], ], [ 'name' => UniqueObject::class, 'name' => Regex::class, 'options' => [ 'object_manager' => $this->getEntityManager(), 'object_repository' => $this->privilegeService->getRepo(), 'use_context' => true, 'fields' => ['code'], 'pattern' => '/^[a-z0-9_-]+$/', 'messages' => [ UniqueObject::ERROR_OBJECT_NOT_UNIQUE => "Ce code est déjà utilisé dans l'application.", Regex::NOT_MATCH => "Seuls les caractères suivants sont autorisés : [a-z, 0-9, _, -].", ], 'break_chain_on_failure' => true, ], ], [ 'name' => Callback::class, 'options' => [ 'messages' => [ Callback::INVALID_VALUE => "Ce code est déjà utilisé pour un autre privilège de cette catégorie.", ], 'callback' => function ($value, $context = []) { $categorie = $this->categorieService->find($context['categorieId']); $privilege = $this->privilegeService->findByCode($value, $categorie); if(!$privilege) { return true; } elseif($this->getObject()->getId() != null) { // modification return strtoupper($this->getObject()->getCode()) === strtoupper($value); } return false; }, 'break_chain_on_failure' => true, ], ], ] ], ], Loading
view/unicaen-privilege/categorie/index.phtml +1 −1 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ $canProvider = $this->isAllowed(PrivilegePrivileges::getResourceId(PrivilegeP </a> </td> <td> <code><?php echo $categorie->getNamespace(); ?></code> <?php echo $categorie->getNamespace() ? sprintf('<code>%s</code>', $categorie->getNamespace()) : ''; ?> </td> <td><?php echo $categorie->getOrdre(); ?></td> <td> Loading