From 94a70684d7e6989f340aa8fa427f5a79f8065be8 Mon Sep 17 00:00:00 2001
From: Jean-Philippe Metivier <jean-philippe.metivier@unicaen.fr>
Date: Mon, 15 Nov 2021 14:27:56 +0100
Subject: [PATCH] Nettoyage + doc

---
 readme.md                                     | 45 +++++++------------
 .../Controller/CategorieController.php        |  8 ++--
 .../Controller/CategorieControllerFactory.php |  2 +-
 .../Controller/ConfigurationController.php    | 44 ------------------
 .../ConfigurationControllerFactory.php        | 34 --------------
 .../Controller/PrivilegeController.php        |  8 ++--
 .../Entity/Db/PrivilegeInterface.php          |  2 +-
 .../Categorie/CategorieFormAwareTrait.php     |  4 +-
 .../Form/Categorie/CategorieFormFactory.php   |  2 +-
 .../Form/Categorie/CategorieHydrator.php      |  2 +-
 .../Categorie/CategorieHydratorFactory.php    |  2 +-
 .../Privilege/PrivilegeFormAwareTrait.php     |  4 +-
 .../Form/Privilege/PrivilegeFormFactory.php   |  2 +-
 .../Form/Privilege/PrivilegeHydrator.php      |  2 +-
 .../Privilege/PrivilegeHydratorFactory.php    |  2 +-
 .../Guard/PrivilegeControllerFactory.php      |  2 +-
 .../Guard/PrivilegeRouteFactory.php           |  2 +-
 view/unicaen-privilege/categorie/index.phtml  |  2 +-
 18 files changed, 41 insertions(+), 128 deletions(-)
 delete mode 100644 src/UnicaenPrivilege/Controller/ConfigurationController.php
 delete mode 100644 src/UnicaenPrivilege/Controller/ConfigurationControllerFactory.php

diff --git a/readme.md b/readme.md
index 439cb41..e90cec3 100644
--- a/readme.md
+++ b/readme.md
@@ -77,39 +77,26 @@ Privilèges associés au module
 
 **N.B.** Le script permettant de créer les tables est fourni dans le fichier [privilege/SQL/002_privileges.sql]
 
-1 - Macro
-
-```php
-const DOCUMENTMACRO_INDEX = 'documentmacro-documentmacro_index';
-const DOCUMENTMACRO_AJOUTER = 'documentmacro-documentmacro_ajouter';
-const DOCUMENTMACRO_MODIFIER = 'documentmacro-documentmacro_modifier';
-const DOCUMENTMACRO_SUPPRIMER = 'documentmacro-documentmacro_supprimer';
-```
-
-2 - Template
-
 ```php
-const DOCUMENTTEMPLATE_INDEX        = 'documenttemplate-documenttemplate_index';
-const DOCUMENTTEMPLATE_AFFICHER     = 'documenttemplate-documenttemplate_afficher';
-const DOCUMENTTEMPLATE_AJOUTER      = 'documenttemplate-documenttemplate_ajouter';
-const DOCUMENTTEMPLATE_MODIFIER     = 'documenttemplate-documenttemplate_modifier';
-const DOCUMENTTEMPLATE_SUPPRIMER    = 'documenttemplate-documenttemplate_supprimer';
-```
-
-3 - Rendu
-
-```php
-const DOCUMENTCONTENU_INDEX         = 'documentcontenu-documentcontenu_index';
-const DOCUMENTCONTENU_AFFICHER      = 'documentcontenu-documentcontenu_afficher';
-const DOCUMENTCONTENU_SUPPRIMER     = 'documentcontenu-documentcontenu_supprimer';
+const PRIVILEGE_VOIR = 'privilege-privilege_voir';
+const PRIVILEGE_AJOUTER = 'privilege-privilege_ajouter';
+const PRIVILEGE_MODIFIER = 'privilege-privilege_modifier';
+const PRIVILEGE_SUPPRIMER = 'privilege-privilege_supprimer';
+const PRIVILEGE_AFFECTER = 'privilege-privilege_affecter';
 ```
 
 ***Attention !!!*** Penser à donner les privilèges aux rôles adéquats.
 
 Dépendance à **UnicaenUtilisateur**
 ----------------------------------
-1. Dans **vendor/unicaen/renderer/config/merged/index.config.php**, **vendor/unicaen/renderer/config/merged/macro.config.php**, **vendor/unicaen/renderer/config/merged/rendu.config.php**, **vendor/unicaen/renderer/config/merged/template.config.php** : `UnicaenPrivilege\Guard\PrivilegeController` pour les gardes liées aux actions.
-   Peut être directement remplacer par l'equivalent fournit par `unicaen/auth`.
-
-1. Dans **vendor/unicaen/renderer/src/UnicaenRenderer/Provider/Privilege/DocumentcontenuPrivileges.php**, **vendor/unicaen/renderer/src/UnicaenRenderer/Provider/Privilege/DocumentmacroPrivileges.php**, **vendor/unicaen/renderer/src/UnicaenRenderer/Provider/Privilege/DocumenttemplatePrivileges.php** : `UnicaenPrivilege\Provider\Privilege\Privileges` classe mère des privilèges du module.
-   Peut être directement remplacer par l'equivalent fournit par `unicaen/auth`.
\ No newline at end of file
+1. Dependance à `Role` et `RoleInterface` : dans la déclaration des privilèges car lié à un tableau de rôle
+- AffectationController.php
+- AffectationService.php
+- AbstractPrivilege.php
+- Privilege.php
+- PrivilegeInterface.php
+- Mapping des privilèges
+   
+1. Dependance à `RoleService` et `RoleServiceAwareTrait` : 
+- AffectationController.php
+- AffectationControllerFactory.php
diff --git a/src/UnicaenPrivilege/Controller/CategorieController.php b/src/UnicaenPrivilege/Controller/CategorieController.php
index e9234c9..0cdfc47 100644
--- a/src/UnicaenPrivilege/Controller/CategorieController.php
+++ b/src/UnicaenPrivilege/Controller/CategorieController.php
@@ -35,7 +35,8 @@ class CategorieController extends AbstractActionController
         ]);
     }
 
-    public function ajouterAction() {
+    public function ajouterAction() : ViewModel
+    {
         $categorie = new Categorie();
         $form = $this->getCategorieForm();
         $form->setAttribute('action', $this->url()->fromRoute('unicaen-privilege/categorie/ajouter', [], [], true));
@@ -79,7 +80,8 @@ class CategorieController extends AbstractActionController
         ]);
     }
 
-    public function modifierAction() {
+    public function modifierAction() : ViewModel
+    {
         $categorie = $this->getCategorieService()->getRequestedCategorie($this);
         $form = $this->getCategorieForm();
         $form->setAttribute('action', $this->url()->fromRoute('unicaen-privilege/categorie/modifier', ['categorie' => $categorie->getId()], [], true));
@@ -106,7 +108,7 @@ class CategorieController extends AbstractActionController
         return $vm;
     }
 
-    public function supprimerAction() {
+    public function supprimerAction() : ViewModel {
         $categorie = $this->getCategorieService()->getRequestedCategorie($this);
 
         /** @var Request $request */
diff --git a/src/UnicaenPrivilege/Controller/CategorieControllerFactory.php b/src/UnicaenPrivilege/Controller/CategorieControllerFactory.php
index ff855d7..49cf867 100644
--- a/src/UnicaenPrivilege/Controller/CategorieControllerFactory.php
+++ b/src/UnicaenPrivilege/Controller/CategorieControllerFactory.php
@@ -8,7 +8,7 @@ use UnicaenPrivilege\Service\Categorie\CategorieService;
 
 class CategorieControllerFactory {
 
-    public function __invoke(ContainerInterface $container)
+    public function __invoke(ContainerInterface $container) : CategorieController
     {
         /**
          * @var CategorieService $categorieService
diff --git a/src/UnicaenPrivilege/Controller/ConfigurationController.php b/src/UnicaenPrivilege/Controller/ConfigurationController.php
deleted file mode 100644
index 26592e2..0000000
--- a/src/UnicaenPrivilege/Controller/ConfigurationController.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-
-namespace UnicaenPrivilege\Controller;
-
-use UnicaenPrivilege\Entity\Db\Categorie;
-use UnicaenPrivilege\Entity\Db\Privilege;
-use UnicaenPrivilege\Form\Categorie\CategorieFormAwareTrait;
-use UnicaenPrivilege\Form\Privilege\PrivilegeFormAwareTrait;
-use UnicaenPrivilege\Service\Categorie\CategorieServiceAwareTrait;
-use UnicaenPrivilege\Service\Privilege\PrivilegeServiceAwareTrait;
-use Zend\Http\Request;
-use Zend\Mvc\Controller\AbstractActionController;
-use Zend\View\Model\ViewModel;
-
-class ConfigurationController extends AbstractActionController {
-    use CategorieServiceAwareTrait;
-    use PrivilegeServiceAwareTrait;
-    use CategorieFormAwareTrait;
-    use PrivilegeFormAwareTrait;
-
-    public function indexConfigurationCategorieAction() {
-        /**
-         * @var string[] $namespaces
-         * @var string $namespaces
-         */
-        $namespaces = $this->getCategorieService()->listerNamespaces();
-        $namespace = $this->params()->fromQuery('namespace');
-
-        /** @var Categorie[] $categories */
-        $categories = $this->getCategorieService()->getCategories('ordre');
-        $namespaceC = ($namespace === "Laissé vide !")?"":$namespace;
-        if ($namespace !== null AND $namespace !== "") $categories = array_filter($categories, function (Categorie $a) use ($namespaceC) { return $a->getNamespace() == $namespaceC; });
-
-        return new ViewModel([
-            'namespaces' => $namespaces,
-            'namespace' => $namespace,
-            'categories' => $categories,
-        ]);
-    }
-
-
-
-
-}
\ No newline at end of file
diff --git a/src/UnicaenPrivilege/Controller/ConfigurationControllerFactory.php b/src/UnicaenPrivilege/Controller/ConfigurationControllerFactory.php
deleted file mode 100644
index 6f87ae5..0000000
--- a/src/UnicaenPrivilege/Controller/ConfigurationControllerFactory.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-
-namespace UnicaenPrivilege\Controller;
-
-use Interop\Container\ContainerInterface;
-use UnicaenPrivilege\Form\Categorie\CategorieForm;
-use UnicaenPrivilege\Form\Privilege\PrivilegeForm;
-use UnicaenPrivilege\Service\Categorie\CategorieService;
-use UnicaenPrivilege\Service\Privilege\PrivilegeService;
-
-class ConfigurationControllerFactory {
-
-    public function __invoke(ContainerInterface $container)
-    {
-        /**
-         * @var CategorieService $categorieService
-         * @var PrivilegeService $privilegeService
-         */
-        $categorieService = $container->get(CategorieService::class);
-        $privilegeService = $container->get(PrivilegeService::class);
-
-        /** @var CategorieForm $categoriePrivilegeForm */
-        $categoriePrivilegeForm = $container->get('FormElementManager')->get(CategorieForm::class);
-        $privilegeForm = $container->get('FormElementManager')->get(PrivilegeForm::class);
-
-        /** @var ConfigurationController $controller */
-        $controller = new ConfigurationController();
-        $controller->setCategorieService($categorieService);
-        $controller->setPrivilegeService($privilegeService);
-        $controller->setCategorieForm($categoriePrivilegeForm);
-        $controller->setPrivilegeForm($privilegeForm);
-        return $controller;
-    }
-}
\ No newline at end of file
diff --git a/src/UnicaenPrivilege/Controller/PrivilegeController.php b/src/UnicaenPrivilege/Controller/PrivilegeController.php
index 24d6e4b..14ebee5 100644
--- a/src/UnicaenPrivilege/Controller/PrivilegeController.php
+++ b/src/UnicaenPrivilege/Controller/PrivilegeController.php
@@ -15,7 +15,7 @@ class PrivilegeController extends AbstractActionController {
     use PrivilegeServiceAwareTrait;
     use PrivilegeFormAwareTrait;
 
-    public function ajouterAction()
+    public function ajouterAction() : ViewModel
     {
         $categorie = $this->getCategorieService()->getRequestedCategorie($this);
         $privilege = new Privilege();
@@ -44,7 +44,8 @@ class PrivilegeController extends AbstractActionController {
         return $vm;
     }
 
-    public function modifierAction() {
+    public function modifierAction() : ViewModel
+    {
         $privilege = $this->getPrivilegeService()->getRequestedPrivilege($this);
         $form = $this->getPrivilegeForm();
         $form->setAttribute('action', $this->url()->fromRoute('unicaen-privilege/privilege/modifier', ['privilege' => $privilege->getId()], [], true));
@@ -72,7 +73,8 @@ class PrivilegeController extends AbstractActionController {
         return $vm;
     }
 
-    public function supprimerAction() {
+    public function supprimerAction() : ViewModel
+    {
         $privilege = $this->getPrivilegeService()->getRequestedPrivilege($this);
 
         /** @var Request $request */
diff --git a/src/UnicaenPrivilege/Entity/Db/PrivilegeInterface.php b/src/UnicaenPrivilege/Entity/Db/PrivilegeInterface.php
index c29f219..cd75d8b 100644
--- a/src/UnicaenPrivilege/Entity/Db/PrivilegeInterface.php
+++ b/src/UnicaenPrivilege/Entity/Db/PrivilegeInterface.php
@@ -53,7 +53,7 @@ interface PrivilegeInterface
 
 
     /**
-     * @param Categorie $categorie
+     * @param Categorie|null $categorie
      * @return self
      */
     public function setCategorie(?Categorie $categorie = null) : PrivilegeInterface;
diff --git a/src/UnicaenPrivilege/Form/Categorie/CategorieFormAwareTrait.php b/src/UnicaenPrivilege/Form/Categorie/CategorieFormAwareTrait.php
index e65c98a..04c13a7 100644
--- a/src/UnicaenPrivilege/Form/Categorie/CategorieFormAwareTrait.php
+++ b/src/UnicaenPrivilege/Form/Categorie/CategorieFormAwareTrait.php
@@ -10,7 +10,7 @@ trait CategorieFormAwareTrait {
     /**
      * @return CategorieForm
      */
-    public function getCategorieForm()
+    public function getCategorieForm() : CategorieForm
     {
         return $this->categoriePrivilegeForm;
     }
@@ -19,7 +19,7 @@ trait CategorieFormAwareTrait {
      * @param CategorieForm $categoriePrivilegeForm
      * @return CategorieForm
      */
-    public function setCategorieForm($categoriePrivilegeForm)
+    public function setCategorieForm(CategorieForm $categoriePrivilegeForm) : CategorieForm
     {
         $this->categoriePrivilegeForm = $categoriePrivilegeForm;
         return $this->categoriePrivilegeForm;
diff --git a/src/UnicaenPrivilege/Form/Categorie/CategorieFormFactory.php b/src/UnicaenPrivilege/Form/Categorie/CategorieFormFactory.php
index 91f7acd..1f943a4 100644
--- a/src/UnicaenPrivilege/Form/Categorie/CategorieFormFactory.php
+++ b/src/UnicaenPrivilege/Form/Categorie/CategorieFormFactory.php
@@ -7,7 +7,7 @@ use Interop\Container\ContainerInterface;
 
 class CategorieFormFactory {
 
-    public function __invoke(ContainerInterface $container)
+    public function __invoke(ContainerInterface $container) : CategorieForm
     {
         /**
          * @var EntityManager $entitymanager
diff --git a/src/UnicaenPrivilege/Form/Categorie/CategorieHydrator.php b/src/UnicaenPrivilege/Form/Categorie/CategorieHydrator.php
index 8d60985..1b7a05e 100644
--- a/src/UnicaenPrivilege/Form/Categorie/CategorieHydrator.php
+++ b/src/UnicaenPrivilege/Form/Categorie/CategorieHydrator.php
@@ -11,7 +11,7 @@ class CategorieHydrator implements HydratorInterface {
      * @param Categorie $object
      * @return array
      */
-    public function extract($object)
+    public function extract($object) : array
     {
         $data = [
             'libelle'     => $object->getLibelle(),
diff --git a/src/UnicaenPrivilege/Form/Categorie/CategorieHydratorFactory.php b/src/UnicaenPrivilege/Form/Categorie/CategorieHydratorFactory.php
index 70b0a21..f588b6a 100644
--- a/src/UnicaenPrivilege/Form/Categorie/CategorieHydratorFactory.php
+++ b/src/UnicaenPrivilege/Form/Categorie/CategorieHydratorFactory.php
@@ -6,7 +6,7 @@ use Interop\Container\ContainerInterface;
 
 class CategorieHydratorFactory {
 
-    public function __invoke(ContainerInterface $container)
+    public function __invoke(ContainerInterface $container) : CategorieHydrator
     {
         /** @var CategorieHydrator $hydrator */
         $hydrator = new CategorieHydrator();
diff --git a/src/UnicaenPrivilege/Form/Privilege/PrivilegeFormAwareTrait.php b/src/UnicaenPrivilege/Form/Privilege/PrivilegeFormAwareTrait.php
index b4cc5b2..b3eef86 100644
--- a/src/UnicaenPrivilege/Form/Privilege/PrivilegeFormAwareTrait.php
+++ b/src/UnicaenPrivilege/Form/Privilege/PrivilegeFormAwareTrait.php
@@ -10,7 +10,7 @@ trait  PrivilegeFormAwareTrait {
     /**
      * @return PrivilegeForm
      */
-    public function getPrivilegeForm()
+    public function getPrivilegeForm() : PrivilegeForm
     {
         return $this->privilegeForm;
     }
@@ -19,7 +19,7 @@ trait  PrivilegeFormAwareTrait {
      * @param PrivilegeForm $privilegeForm
      * @return PrivilegeForm
      */
-    public function setPrivilegeForm($privilegeForm)
+    public function setPrivilegeForm(PrivilegeForm $privilegeForm) : PrivilegeForm
     {
         $this->privilegeForm = $privilegeForm;
         return $this->privilegeForm;
diff --git a/src/UnicaenPrivilege/Form/Privilege/PrivilegeFormFactory.php b/src/UnicaenPrivilege/Form/Privilege/PrivilegeFormFactory.php
index 8639e8c..dcd7dce 100644
--- a/src/UnicaenPrivilege/Form/Privilege/PrivilegeFormFactory.php
+++ b/src/UnicaenPrivilege/Form/Privilege/PrivilegeFormFactory.php
@@ -7,7 +7,7 @@ use Interop\Container\ContainerInterface;
 
 class PrivilegeFormFactory {
 
-    public function __invoke(ContainerInterface $container)
+    public function __invoke(ContainerInterface $container) : PrivilegeForm
     {
         /**
          * @var EntityManager $entitymanager
diff --git a/src/UnicaenPrivilege/Form/Privilege/PrivilegeHydrator.php b/src/UnicaenPrivilege/Form/Privilege/PrivilegeHydrator.php
index 19cd248..f7bca2c 100644
--- a/src/UnicaenPrivilege/Form/Privilege/PrivilegeHydrator.php
+++ b/src/UnicaenPrivilege/Form/Privilege/PrivilegeHydrator.php
@@ -11,7 +11,7 @@ class PrivilegeHydrator implements HydratorInterface {
      * @param Privilege $object
      * @return array
      */
-    public function extract($object)
+    public function extract($object) : array
     {
         $data = [
             'libelle'     => $object->getLibelle(),
diff --git a/src/UnicaenPrivilege/Form/Privilege/PrivilegeHydratorFactory.php b/src/UnicaenPrivilege/Form/Privilege/PrivilegeHydratorFactory.php
index 2570771..ef14e4d 100644
--- a/src/UnicaenPrivilege/Form/Privilege/PrivilegeHydratorFactory.php
+++ b/src/UnicaenPrivilege/Form/Privilege/PrivilegeHydratorFactory.php
@@ -6,7 +6,7 @@ use Interop\Container\ContainerInterface;
 
 class PrivilegeHydratorFactory {
 
-    public function __invoke(ContainerInterface $container)
+    public function __invoke(ContainerInterface $container) : PrivilegeHydrator
     {
         /** @var PrivilegeHydrator $hydrator */
         $hydrator = new PrivilegeHydrator();
diff --git a/src/UnicaenPrivilege/Guard/PrivilegeControllerFactory.php b/src/UnicaenPrivilege/Guard/PrivilegeControllerFactory.php
index 1d3bf1f..fd35a90 100644
--- a/src/UnicaenPrivilege/Guard/PrivilegeControllerFactory.php
+++ b/src/UnicaenPrivilege/Guard/PrivilegeControllerFactory.php
@@ -8,7 +8,7 @@ use UnicaenPrivilege\Service\Privilege\PrivilegeService;
 
 class PrivilegeControllerFactory
 {
-    public function __invoke(ContainerInterface $container)
+    public function __invoke(ContainerInterface $container) : PrivilegeController
     {
         /** @var PrivilegeProviderInterface $privilegeService */
         $privilegeProvider = $container->get(PrivilegeService::class);
diff --git a/src/UnicaenPrivilege/Guard/PrivilegeRouteFactory.php b/src/UnicaenPrivilege/Guard/PrivilegeRouteFactory.php
index b0d7894..f375a69 100644
--- a/src/UnicaenPrivilege/Guard/PrivilegeRouteFactory.php
+++ b/src/UnicaenPrivilege/Guard/PrivilegeRouteFactory.php
@@ -9,7 +9,7 @@ use UnicaenPrivilege\Service\Privilege\PrivilegeService;
 
 class PrivilegeRouteFactory
 {
-    public function __invoke(ContainerInterface $container)
+    public function __invoke(ContainerInterface $container) : PrivilegeRoute
     {
         /** @var PrivilegeProviderInterface $privilegeService */
         $privilegeProvider = $container->get(PrivilegeService::class);
diff --git a/view/unicaen-privilege/categorie/index.phtml b/view/unicaen-privilege/categorie/index.phtml
index 5d07543..aeb86d3 100644
--- a/view/unicaen-privilege/categorie/index.phtml
+++ b/view/unicaen-privilege/categorie/index.phtml
@@ -59,7 +59,7 @@ $canProvider    = $this->isAllowed(PrivilegePrivileges::getResourceId(PrivilegeP
                 <th> Ordre </th>
                 <th> Namespace </th>
                 <th> #Privilège </th>
-                <th> Action </th>
+                <th style="min-width:10rem;"> Action </th>
             </tr>
         </thead>
         <tbody>
-- 
GitLab