Skip to content
Snippets Groups Projects
Commit 7545f5f7 authored by David Surville's avatar David Surville
Browse files

[Tac] Réorganisation du code au niveau des privilèges et des catégories de...

[Tac] Réorganisation du code au niveau des privilèges et des catégories de privilèges pour accueillir les périmètres
parent e2aae3da
No related branches found
No related tags found
No related merge requests found
Pipeline #12793 passed
Showing
with 186 additions and 238 deletions
<?php
use UnicaenPrivilege\Controller\CategorieController;
use UnicaenPrivilege\Controller\CategorieControllerFactory;
use UnicaenPrivilege\Form\Categorie\CategorieFiltreForm;
use UnicaenPrivilege\Form\Categorie\CategorieFiltreFormFactory;
use UnicaenPrivilege\Form\Categorie\CategorieForm;
use UnicaenPrivilege\Form\Categorie\CategorieFormFactory;
use UnicaenPrivilege\Provider\Privilege\PrivilegePrivileges;
use UnicaenPrivilege\Service\Categorie\CategorieService;
use UnicaenPrivilege\Service\Categorie\CategorieServiceFactory;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
return [
'bjyauthorize' => [
'guards' => [
UnicaenPrivilege\Guard\PrivilegeController::class => [
[
'controller' => CategorieController::class,
'action' => [
'index',
'ajouter',
'gerer',
'provider',
'modifier',
'supprimer',
],
'privileges' => [
PrivilegePrivileges::PRIVILEGE_AJOUTER,
],
],
],
],
],
'router' => [
'routes' => [
'unicaen-privilege' => [
'child_routes' => [
'categorie' => [
'type' => Literal::class,
'options' => [
'route' => '/categorie',
'defaults' => [
'controller' => CategorieController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'ajouter' => [
'type' => Literal::class,
'options' => [
'route' => '/ajouter',
'defaults' => [
'controller' => CategorieController::class,
'action' => 'ajouter',
],
],
],
'gerer' => [
'type' => Segment::class,
'options' => [
'route' => '/gerer/:categorie',
'defaults' => [
'controller' => CategorieController::class,
'action' => 'gerer',
],
],
'may_terminate' => true,
],
'provider' => [
'type' => Segment::class,
'options' => [
'route' => '/provider/:categorie',
'defaults' => [
'controller' => CategorieController::class,
'action' => 'provider',
],
],
'may_terminate' => true,
],
'modifier' => [
'type' => Segment::class,
'options' => [
'route' => '/modifier/:categorie',
'defaults' => [
'controller' => CategorieController::class,
'action' => 'modifier',
],
],
'may_terminate' => true,
],
'supprimer' => [
'type' => Segment::class,
'options' => [
'route' => '/supprimer/:categorie',
'defaults' => [
'controller' => CategorieController::class,
'action' => 'supprimer',
],
],
'may_terminate' => true,
],
],
],
],
],
],
],
'navigation' => [
'default' => [
],
],
'controllers' => [
'factories' => [
CategorieController::class => CategorieControllerFactory::class,
],
],
'service_manager' => [
'factories' => [
CategorieService::class => CategorieServiceFactory::class,
],
],
'form_elements' => [
'factories' => [
CategorieForm::class => CategorieFormFactory::class,
CategorieFiltreForm::class => CategorieFiltreFormFactory::class,
],
],
];
\ No newline at end of file
<?php
use UnicaenPrivilege\Controller\PrivilegeCategorieController;
use UnicaenPrivilege\Controller\PrivilegeCategorieControllerFactory;
use UnicaenPrivilege\Controller\PrivilegeController;
use UnicaenPrivilege\Controller\PrivilegeControllerFactory;
use UnicaenPrivilege\Form\Privilege\CategorieFiltreForm;
use UnicaenPrivilege\Form\Privilege\CategorieFiltreFormFactory;
use UnicaenPrivilege\Form\Privilege\CategorieForm;
use UnicaenPrivilege\Form\Privilege\CategorieFormFactory;
use UnicaenPrivilege\Form\Privilege\PrivilegeForm;
use UnicaenPrivilege\Form\Privilege\PrivilegeFormFactory;
use UnicaenPrivilege\Provider\Privilege\PrivilegePrivileges;
use UnicaenPrivilege\Provider\Rule\PrivilegeRuleProvider;
use UnicaenPrivilege\Provider\Rule\PrivilegeRuleProviderFactory;
use UnicaenPrivilege\Service\Privilege\PrivilegeCategorieService;
use UnicaenPrivilege\Service\Privilege\PrivilegeCategorieServiceFactory;
use UnicaenPrivilege\Service\Privilege\PrivilegeService;
use UnicaenPrivilege\Service\Privilege\PrivilegeServiceFactory;
use UnicaenPrivilege\View\Privilege\PrivilegeViewHelper;
......@@ -63,6 +71,20 @@ return [
PrivilegePrivileges::PRIVILEGE_SUPPRIMER,
],
],
[
'controller' => PrivilegeCategorieController::class,
'action' => [
'index',
'ajouter',
'gerer',
'provider',
'modifier',
'supprimer',
],
'privileges' => [
PrivilegePrivileges::PRIVILEGE_AJOUTER,
],
],
],
],
],
......@@ -120,6 +142,73 @@ return [
],
],
],
'categorie' => [
'type' => Literal::class,
'options' => [
'route' => '/categorie',
'defaults' => [
'controller' => PrivilegeCategorieController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'ajouter' => [
'type' => Literal::class,
'options' => [
'route' => '/ajouter',
'defaults' => [
'controller' => PrivilegeCategorieController::class,
'action' => 'ajouter',
],
],
],
'gerer' => [
'type' => Segment::class,
'options' => [
'route' => '/gerer/:categorie',
'defaults' => [
'controller' => PrivilegeCategorieController::class,
'action' => 'gerer',
],
],
'may_terminate' => true,
],
'provider' => [
'type' => Segment::class,
'options' => [
'route' => '/provider/:categorie',
'defaults' => [
'controller' => PrivilegeCategorieController::class,
'action' => 'provider',
],
],
'may_terminate' => true,
],
'modifier' => [
'type' => Segment::class,
'options' => [
'route' => '/modifier/:categorie',
'defaults' => [
'controller' => PrivilegeCategorieController::class,
'action' => 'modifier',
],
],
'may_terminate' => true,
],
'supprimer' => [
'type' => Segment::class,
'options' => [
'route' => '/supprimer/:categorie',
'defaults' => [
'controller' => PrivilegeCategorieController::class,
'action' => 'supprimer',
],
],
'may_terminate' => true,
],
],
],
],
],
],
......@@ -127,12 +216,14 @@ return [
'controllers' => [
'factories' => [
PrivilegeCategorieController::class => PrivilegeCategorieControllerFactory::class,
PrivilegeController::class => PrivilegeControllerFactory::class,
],
],
'service_manager' => [
'factories' => [
PrivilegeCategorieService::class => PrivilegeCategorieServiceFactory::class,
PrivilegeService::class => PrivilegeServiceFactory::class,
PrivilegeRuleProvider::class => PrivilegeRuleProviderFactory::class,
],
......@@ -140,6 +231,8 @@ return [
'form_elements' => [
'factories' => [
CategorieFiltreForm::class => CategorieFiltreFormFactory::class,
CategorieForm::class => CategorieFormFactory::class,
PrivilegeForm::class => PrivilegeFormFactory::class,
],
],
......
......@@ -2,18 +2,16 @@
namespace UnicaenPrivilege\Controller;
use UnicaenPrivilege\Entity\Db\CategorieInterface;
use UnicaenPrivilege\Form\Categorie\CategorieFiltreFormAwareTrait;
use UnicaenPrivilege\Form\Categorie\CategorieFormAwareTrait;
use UnicaenPrivilege\Service\Categorie\CategorieServiceAwareTrait;
use UnicaenPrivilege\Form\Privilege\CategorieFiltreFormAwareTrait;
use UnicaenPrivilege\Form\Privilege\CategorieFormAwareTrait;
use UnicaenPrivilege\Service\Privilege\PrivilegeCategorieServiceAwareTrait;
use UnicaenPrivilege\Service\Privilege\PrivilegeServiceAwareTrait;
use Zend\Http\Request;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class CategorieController extends AbstractActionController
class PrivilegeCategorieController extends AbstractActionController
{
use CategorieServiceAwareTrait;
use PrivilegeCategorieServiceAwareTrait;
use PrivilegeServiceAwareTrait;
use CategorieFormAwareTrait;
use CategorieFiltreFormAwareTrait;
......@@ -24,20 +22,20 @@ class CategorieController extends AbstractActionController
$namespace = $this->params()->fromQuery('namespace');
if($namespace) {
$form->get('namespace')->setValue($namespace);
$categories = $this->categorieService->findByNamespace($namespace);
$categories = $this->privilegeCategorieService->findByNamespace($namespace);
}
else {
$categories = $this->categorieService->findAll();
$categories = $this->privilegeCategorieService->findAll();
}
$title = "Gestion des catégories";
$title = "Gestion des catégories de privilèges";
return compact('title', 'form', 'categories');
}
public function ajouterAction() : ViewModel
{
$categorie = $this->categorieService->getEntityInstance();
$categorie->setOrdre($this->categorieService->getMaxOrdre()+1);
$categorie = $this->privilegeCategorieService->getEntityInstance();
$categorie->setOrdre($this->privilegeCategorieService->getMaxOrdre()+1);
$form = $this->categorieForm;
$form->setAttribute('action', $this->url()->fromRoute('unicaen-privilege/categorie/ajouter', [], [], true));
$form->bind($categorie);
......@@ -46,7 +44,7 @@ class CategorieController extends AbstractActionController
$form->setData($data);
if ($form->isValid()) {
try {
$this->categorieService->create($categorie);
$this->privilegeCategorieService->create($categorie);
$this->flashMessenger()->addSuccessMessage(sprintf("Catégorie <strong>%s</strong> créée avec succès.", $categorie->getLibelle()));
} catch (Exception $e) {
$this->flashMessenger()->addErrorMessage(sprintf("Une erreur est survenu lors de la création de la catégorie <strong>%s</strong>.", $categorie->getLibelle()));
......@@ -66,7 +64,7 @@ class CategorieController extends AbstractActionController
public function gererAction() : array
{
$categorie = $this->categorieService->getRequestedCategorie($this);
$categorie = $this->privilegeCategorieService->getRequestedCategorie($this);
$privileges = $this->privilegeService->findByCategorie($categorie);
$title = "Gestion de la catégorie";
......@@ -75,14 +73,14 @@ class CategorieController extends AbstractActionController
public function providerAction() : array
{
$categorie = $this->categorieService->getRequestedCategorie($this);
$categorie = $this->privilegeCategorieService->getRequestedCategorie($this);
return compact('categorie');
}
public function modifierAction() : ViewModel
{
$categorie = $this->categorieService->getRequestedCategorie($this);
$categorie = $this->privilegeCategorieService->getRequestedCategorie($this);
$form = $this->categorieForm;
$form->setAttribute('action', $this->url()->fromRoute('unicaen-privilege/categorie/modifier', ['categorie' => $categorie->getId()], [], true));
$form->bind($categorie);
......@@ -91,7 +89,7 @@ class CategorieController extends AbstractActionController
$form->setData($data);
if ($form->isValid()) {
try {
$this->categorieService->update($categorie);
$this->privilegeCategorieService->update($categorie);
$this->flashMessenger()->addSuccessMessage(sprintf("Catégorie <strong>%s</strong> modifiée avec succès.", $categorie->getLibelle()));
} catch (Exception $e) {
$this->flashMessenger()->addErrorMessage(sprintf("Une erreur est survenu lors de la modification de la catégorie <strong>%s</strong>.", $categorie->getLibelle()));
......@@ -100,7 +98,7 @@ class CategorieController extends AbstractActionController
}
$view = new ViewModel();
$view->setTemplate('unicaen-privilege/categorie/template/form-categorie');
$view->setTemplate('unicaen-privilege/privilege-categorie/template/form-categorie');
$view->setVariables([
'title' => "Modification de la catégorie",
'form' => $form,
......@@ -113,8 +111,8 @@ class CategorieController extends AbstractActionController
public function supprimerAction() : array
{
try {
$categorie = $this->categorieService->getRequestedCategorie($this);
$this->categorieService->delete($categorie);
$categorie = $this->privilegeCategorieService->getRequestedCategorie($this);
$this->privilegeCategorieService->delete($categorie);
$this->flashMessenger()->addSuccessMessage(sprintf("Catégorie <strong>%s</strong> supprimée avec succès.", $categorie->getLibelle()));
} catch (Exception $e) {
$this->flashMessenger()->addErrorMessage(sprintf("Une erreur est survenu lors de la suppression de la catégorie <strong>%s</strong>.", $categorie->getLibelle()));
......
......@@ -3,12 +3,12 @@
namespace UnicaenPrivilege\Controller;
use Interop\Container\ContainerInterface;
use UnicaenPrivilege\Form\Categorie\CategorieFiltreForm;
use UnicaenPrivilege\Form\Categorie\CategorieForm;
use UnicaenPrivilege\Service\Categorie\CategorieService;
use UnicaenPrivilege\Form\Privilege\CategorieFiltreForm;
use UnicaenPrivilege\Form\Privilege\CategorieForm;
use UnicaenPrivilege\Service\Privilege\PrivilegeCategorieService;
use UnicaenPrivilege\Service\Privilege\PrivilegeService;
class CategorieControllerFactory
class PrivilegeCategorieControllerFactory
{
/**
* Create controller
......@@ -16,21 +16,21 @@ class CategorieControllerFactory
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return CategorieController|object
* @return PrivilegeCategorieController|object
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/**
* @var CategorieService $categorieService
* @var PrivilegeCategorieService $categorieService
* @var PrivilegeService $privilegeService
*/
$categorieService = $container->get(CategorieService::class);
$categorieService = $container->get(PrivilegeCategorieService::class);
$privilegeService = $container->get(PrivilegeService::class);
$categorieForm = $container->get('FormElementManager')->get(CategorieForm::class);
$categorieFiltreForm = $container->get('FormElementManager')->get(CategorieFiltreForm::class);
$controller = new CategorieController();
$controller->setCategorieService($categorieService);
$controller = new PrivilegeCategorieController();
$controller->setPrivilegeCategorieService($categorieService);
$controller->setPrivilegeService($privilegeService);
$controller->setCategorieForm($categorieForm);
$controller->setCategorieFiltreForm($categorieFiltreForm);
......
......@@ -2,19 +2,17 @@
namespace UnicaenPrivilege\Controller;
use UnicaenPrivilege\Form\Categorie\CategorieFiltreFormAwareTrait;
use UnicaenPrivilege\Form\Privilege\CategorieFiltreFormAwareTrait;
use UnicaenPrivilege\Form\Privilege\PrivilegeFormAwareTrait;
use UnicaenPrivilege\Service\Categorie\CategorieServiceAwareTrait;
use UnicaenPrivilege\Service\Privilege\PrivilegeCategorieServiceAwareTrait;
use UnicaenPrivilege\Service\Privilege\PrivilegeServiceAwareTrait;
use UnicaenUtilisateur\Service\Role\RoleServiceAwareTrait;
use Zend\Http\Request;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;
class PrivilegeController extends AbstractActionController
{
use CategorieServiceAwareTrait;
use PrivilegeCategorieServiceAwareTrait;
use PrivilegeServiceAwareTrait;
use RoleServiceAwareTrait;
use PrivilegeFormAwareTrait;
......@@ -37,7 +35,7 @@ class PrivilegeController extends AbstractActionController
public function ajouterAction() : ViewModel
{
$categorie = $this->categorieService->getRequestedCategorie($this);
$categorie = $this->privilegeCategorieService->getRequestedCategorie($this);
$privilege = $this->privilegeService->getEntityInstance();
$privilege->setOrdre($this->privilegeService->getMaxOrdreByCategorie($categorie)+1);
$privilege->setCategorie($categorie);
......
......@@ -3,9 +3,9 @@
namespace UnicaenPrivilege\Controller;
use Interop\Container\ContainerInterface;
use UnicaenPrivilege\Form\Categorie\CategorieFiltreForm;
use UnicaenPrivilege\Form\Privilege\CategorieFiltreForm;
use UnicaenPrivilege\Form\Privilege\PrivilegeForm;
use UnicaenPrivilege\Service\Categorie\CategorieService;
use UnicaenPrivilege\Service\Privilege\PrivilegeCategorieService;
use UnicaenPrivilege\Service\Privilege\PrivilegeService;
use UnicaenUtilisateur\Service\Role\RoleService;
......@@ -22,18 +22,18 @@ class PrivilegeControllerFactory
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/**
* @var CategorieService $categorieService
* @var PrivilegeCategorieService $categorieService
* @var PrivilegeService $privilegeService
* @var RoleService $roleService
*/
$categorieService = $container->get(CategorieService::class);
$categorieService = $container->get(PrivilegeCategorieService::class);
$privilegeService = $container->get(PrivilegeService::class);
$roleService = $container->get(RoleService::class);
$privilegeForm = $container->get('FormElementManager')->get(PrivilegeForm::class);
$categorieFiltreForm = $container->get('FormElementManager')->get(CategorieFiltreForm::class);
$controller = new PrivilegeController();
$controller->setCategorieService($categorieService);
$controller->setPrivilegeCategorieService($categorieService);
$controller->setPrivilegeService($privilegeService);
$controller->setRoleService($roleService);
$controller->setPrivilegeForm($privilegeForm);
......
......@@ -31,7 +31,7 @@ abstract class AbstractPrivilege implements PrivilegeInterface, ResourceInterfac
protected $ordre;
/**
* @var CategorieInterface
* @var PrivilegeCategorieInterface
*/
protected $categorie;
......@@ -163,7 +163,7 @@ abstract class AbstractPrivilege implements PrivilegeInterface, ResourceInterfac
/**
* Get categorie.
*
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function getCategorie()
{
......@@ -173,10 +173,10 @@ abstract class AbstractPrivilege implements PrivilegeInterface, ResourceInterfac
/**
* Set categorie.
*
* @param CategorieInterface $categorie
* @param PrivilegeCategorieInterface $categorie
* @return PrivilegeInterface
*/
public function setCategorie(CategorieInterface $categorie)
public function setCategorie(PrivilegeCategorieInterface $categorie)
{
$this->categorie = $categorie;
......
......@@ -5,7 +5,7 @@ namespace UnicaenPrivilege\Entity\Db;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
abstract class AbstractCategorie implements CategorieInterface
abstract class AbstractPrivilegeCategorie implements PrivilegeCategorieInterface
{
/**
* @var int
......@@ -68,7 +68,7 @@ abstract class AbstractCategorie implements CategorieInterface
* Set id.
*
* @param int $id
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function setId($id)
{
......@@ -91,7 +91,7 @@ abstract class AbstractCategorie implements CategorieInterface
* Set code.
*
* @param string $code
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function setCode($code)
{
......@@ -114,7 +114,7 @@ abstract class AbstractCategorie implements CategorieInterface
* Set libelle.
*
* @param string $libelle
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function setLibelle($libelle)
{
......@@ -137,7 +137,7 @@ abstract class AbstractCategorie implements CategorieInterface
* Set namespace.
*
* @param string $namespace
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function setNamespace($namespace)
{
......@@ -160,7 +160,7 @@ abstract class AbstractCategorie implements CategorieInterface
* Set ordre.
*
* @param int $ordre
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function setOrdre($ordre)
{
......@@ -183,7 +183,7 @@ abstract class AbstractCategorie implements CategorieInterface
* Add privilege.
*
* @param PrivilegeInterface $privilege
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function addPrivilege(PrivilegeInterface $privilege)
{
......@@ -196,7 +196,7 @@ abstract class AbstractCategorie implements CategorieInterface
* Remove privilege.
*
* @param PrivilegeInterface $privilege
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function removePrivilege(PrivilegeInterface $privilege)
{
......
......@@ -2,7 +2,7 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="UnicaenPrivilege\Entity\Db\Categorie" table="UNICAEN_PRIVILEGE_CATEGORIE">
<entity name="UnicaenPrivilege\Entity\Db\PrivilegeCategorie" table="UNICAEN_PRIVILEGE_CATEGORIE">
<unique-constraints>
<unique-constraint name="un_unicaen_privilege_categorie_code" columns="CODE"/>
......
......@@ -20,7 +20,7 @@
<field name="libelle" type="string" column="LIBELLE" length="200" nullable="false"/>
<field name="ordre" type="integer" column="ORDRE" nullable="false"/>
<many-to-one field="categorie" target-entity="UnicaenPrivilege\Entity\Db\Categorie" fetch="LAZY">
<many-to-one field="categorie" target-entity="UnicaenPrivilege\Entity\Db\PrivilegeCategorie" fetch="LAZY">
<join-columns>
<join-column name="CATEGORIE_ID" referenced-column-name="ID"/>
</join-columns>
......
......@@ -2,4 +2,4 @@
namespace UnicaenPrivilege\Entity\Db;
class Categorie extends AbstractCategorie {}
\ No newline at end of file
class PrivilegeCategorie extends AbstractPrivilegeCategorie {}
\ No newline at end of file
......@@ -4,7 +4,7 @@ namespace UnicaenPrivilege\Entity\Db;
use Doctrine\Common\Collections\Collection;
interface CategorieInterface
interface PrivilegeCategorieInterface
{
/**
* @return string
......@@ -22,7 +22,7 @@ interface CategorieInterface
* Set id.
*
* @param int $id
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function setId($id);
......@@ -37,7 +37,7 @@ interface CategorieInterface
* Set code.
*
* @param string $code
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function setCode($code);
......@@ -52,7 +52,7 @@ interface CategorieInterface
* Set libelle.
*
* @param string $libelle
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function setLibelle($libelle);
......@@ -67,7 +67,7 @@ interface CategorieInterface
* Set namespace.
*
* @param string $namespace
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function setNamespace($namespace);
......@@ -82,7 +82,7 @@ interface CategorieInterface
* Set ordre.
*
* @param int $ordre
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function setOrdre($ordre);
......@@ -97,7 +97,7 @@ interface CategorieInterface
* Add privilege.
*
* @param PrivilegeInterface $privilege
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function addPrivilege(PrivilegeInterface $privilege);
......@@ -105,7 +105,7 @@ interface CategorieInterface
* Remove privilege.
*
* @param PrivilegeInterface $privilege
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function removePrivilege(PrivilegeInterface $privilege);
......
......@@ -84,17 +84,17 @@ interface PrivilegeInterface
/**
* Get categorie.
*
* @return CategorieInterface
* @return PrivilegeCategorieInterface
*/
public function getCategorie();
/**
* Set categorie.
*
* @param CategorieInterface $categorie
* @param PrivilegeCategorieInterface $categorie
* @return PrivilegeInterface
*/
public function setCategorie(CategorieInterface $categorie);
public function setCategorie(PrivilegeCategorieInterface $categorie);
/**
* @return Collection
......
<?php
namespace UnicaenPrivilege\Form\Categorie;
namespace UnicaenPrivilege\Form\Privilege;
use DoctrineModule\Form\Element\ObjectSelect;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenPrivilege\Service\Categorie\CategorieServiceAwareTrait;
use UnicaenPrivilege\Service\Privilege\PrivilegeCategorieServiceAwareTrait;
use Zend\Form\Element\Button;
use Zend\Form\Element\Select;
use Zend\Form\Element\Submit;
use Zend\Form\Form;
use Zend\InputFilter\Factory;
class CategorieFiltreForm extends Form
{
use EntityManagerAwareTrait;
use CategorieServiceAwareTrait;
use PrivilegeCategorieServiceAwareTrait;
public function init()
{
......@@ -25,8 +23,8 @@ class CategorieFiltreForm extends Form
'name' => 'namespace',
'options' => [
'empty_option' => "Tous les namespaces",
'value_options' => $this->categorieService->getListForSelect(
$this->categorieService->findAllWithNamespace(), 'namespace', 'namespace'
'value_options' => $this->privilegeCategorieService->getListForSelect(
$this->privilegeCategorieService->findAllWithNamespace(), 'namespace', 'namespace'
),
],
'attributes' => [
......
<?php
namespace UnicaenPrivilege\Form\Categorie;
namespace UnicaenPrivilege\Form\Privilege;
trait CategorieFiltreFormAwareTrait
{
......
<?php
namespace UnicaenPrivilege\Form\Categorie;
namespace UnicaenPrivilege\Form\Privilege;
use Doctrine\ORM\EntityManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject;
use Interop\Container\ContainerInterface;
use UnicaenPrivilege\Service\Categorie\CategorieService;
use UnicaenUtilisateur\Service\Role\RoleService;
use UnicaenPrivilege\Service\Privilege\PrivilegeCategorieService;
class CategorieFiltreFormFactory
{
......@@ -22,14 +20,14 @@ class CategorieFiltreFormFactory
{
/**
* @var EntityManager $entityManager
* @var RoleService $categorieService
* @var PrivilegeCategorieService $categorieService
*/
$entityManager = $container->get('Doctrine\ORM\EntityManager');
$categorieService = $container->get(CategorieService::class);
$categorieService = $container->get(PrivilegeCategorieService::class);
$form = new CategorieFiltreForm();
$form->setEntityManager($entityManager);
$form->setCategorieService($categorieService);
$form->setPrivilegeCategorieService($categorieService);
return $form;
}
......
<?php
namespace UnicaenPrivilege\Form\Categorie;
namespace UnicaenPrivilege\Form\Privilege;
use DoctrineModule\Validator\UniqueObject;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenPrivilege\Service\Categorie\CategorieServiceAwareTrait;
use UnicaenPrivilege\Service\Privilege\PrivilegeCategorieServiceAwareTrait;
use Zend\Form\Element\Button;
use Zend\Form\Element\Hidden;
use Zend\Form\Element\Number;
use Zend\Form\Element\Text;
use Zend\Form\Form;
......@@ -18,7 +16,7 @@ use Zend\Validator\Regex;
class CategorieForm extends Form
{
use EntityManagerAwareTrait;
use CategorieServiceAwareTrait;
use PrivilegeCategorieServiceAwareTrait;
public function init()
{
......@@ -109,7 +107,7 @@ class CategorieForm extends Form
Callback::INVALID_VALUE => "Ce libellé est déjà utilisé pour une autre catégorie.",
],
'callback' => function ($value, $context = []) {
$categorie = $this->categorieService->findByLibelle($value);
$categorie = $this->privilegeCategorieService->findByLibelle($value);
if(!$categorie) {
return true;
}
......@@ -153,7 +151,7 @@ class CategorieForm extends Form
Callback::INVALID_VALUE => "Ce code est déjà utilisé pour une autre catégorie.",
],
'callback' => function ($value, $context = []) {
$categorie = $this->categorieService->findByCode($value);
$categorie = $this->privilegeCategorieService->findByCode($value);
if(!$categorie) {
return true;
}
......
<?php
namespace UnicaenPrivilege\Form\Categorie;
namespace UnicaenPrivilege\Form\Privilege;
trait CategorieFormAwareTrait
{
......
<?php
namespace UnicaenPrivilege\Form\Categorie;
namespace UnicaenPrivilege\Form\Privilege;
use Doctrine\ORM\EntityManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject;
use Interop\Container\ContainerInterface;
use UnicaenPrivilege\Service\Categorie\CategorieService;
use UnicaenPrivilege\Service\Privilege\PrivilegeCategorieService;
class CategorieFormFactory
{
......@@ -21,15 +21,15 @@ class CategorieFormFactory
{
/**
* @var EntityManager $entityManager
* @var CategorieService $categorieService
* @var PrivilegeCategorieService $categorieService
*/
$entityManager = $container->get('Doctrine\ORM\EntityManager');
$categorieService = $container->get(CategorieService::class);
$categorieService = $container->get(PrivilegeCategorieService::class);
$hydrator = $container->get('HydratorManager')->get(DoctrineObject::class);
$form = new CategorieForm();
$form->setEntityManager($entityManager);
$form->setCategorieService($categorieService);
$form->setPrivilegeCategorieService($categorieService);
$form->setHydrator($hydrator);
return $form;
......
......@@ -4,11 +4,8 @@
namespace UnicaenPrivilege\Form\Privilege;
use DoctrineModule\Form\Element\ObjectSelect;
use DoctrineModule\Validator\NoObjectExists;
use DoctrineModule\Validator\UniqueObject;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenPrivilege\Entity\Db\CategorieInterface;
use UnicaenPrivilege\Service\Categorie\CategorieServiceAwareTrait;
use UnicaenPrivilege\Service\Privilege\PrivilegeCategorieServiceAwareTrait;
use UnicaenPrivilege\Service\Privilege\PrivilegeServiceAwareTrait;
use Zend\Form\Element\Button;
use Zend\Form\Element\Hidden;
......@@ -23,7 +20,7 @@ use Zend\Validator\Regex;
class PrivilegeForm extends Form
{
use EntityManagerAwareTrait;
use CategorieServiceAwareTrait;
use PrivilegeCategorieServiceAwareTrait;
use PrivilegeServiceAwareTrait;
public function init()
......@@ -41,7 +38,7 @@ class PrivilegeForm extends Form
'options' => [
'label' => "Catégorie :",
'object_manager' => $this->getEntityManager(),
'target_class' => $this->categorieService->getEntityClass(),
'target_class' => $this->privilegeCategorieService->getEntityClass(),
'property' => 'libelle',
'find_method' => [
'name' => 'findBy',
......@@ -133,7 +130,7 @@ class PrivilegeForm extends Form
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']);
$categorie = $this->privilegeCategorieService->find($context['categorieId']);
$privilege = $this->privilegeService->findByLibelle($value, $categorie);
if(!$privilege) {
return true;
......@@ -178,7 +175,7 @@ class PrivilegeForm extends Form
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']);
$categorie = $this->privilegeCategorieService->find($context['categorieId']);
$privilege = $this->privilegeService->findByCode($value, $categorie);
if(!$privilege) {
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment