Commit 6d3bd823 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Module ok

parent 905e46e3
Loading
Loading
Loading
Loading
+114 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ use UnicaenParametre\Form\Categorie\CategorieForm;
use UnicaenParametre\Form\Categorie\CategorieFormFactory;
use UnicaenParametre\Form\Categorie\CategorieHydrator;
use UnicaenParametre\Form\Categorie\CategorieHydratorFactory;
use UnicaenParametre\Provider\Privilege\ParametrecategoriePrivileges;
use UnicaenParametre\Service\Categorie\CategorieService;
use UnicaenParametre\Service\Categorie\CategorieServiceFactory;
use UnicaenPrivilege\Guard\PrivilegeController;
@@ -18,13 +19,126 @@ return [
    'bjyauthorize' => [
        'guards' => [
            PrivilegeController::class => [
                [
                    'controller' => CategorieController::class,
                    'action' => [
                        'index',
                    ],
                    'pivileges' => ParametrecategoriePrivileges::PARAMETRECATEGORIE_INDEX,
                ],
                [
                    'controller' => CategorieController::class,
                    'action' => [
                        'ajouter',
                    ],
                    'pivileges' => ParametrecategoriePrivileges::PARAMETRECATEGORIE_AJOUTER,
                ],
                [
                    'controller' => CategorieController::class,
                    'action' => [
                        'modifier',
                    ],
                    'pivileges' => ParametrecategoriePrivileges::PARAMETRECATEGORIE_MODIFIER,
                ],
                [
                    'controller' => CategorieController::class,
                    'action' => [
                        'supprimer',
                    ],
                    'pivileges' => ParametrecategoriePrivileges::PARAMETRECATEGORIE_SUPPRIMER,
                ],
            ],
        ],
    ],

    'navigation'      => [
        'default' => [
            'home' => [
                'pages' => [
                    'administration' => [
                        'pages' => [
                            'parametre' => [
                                'label'    => 'Paramètres',
                                'route'    => 'parametre/index',
        //                            'resource' => PrivilegeController::getResourceId(CategorieController::class, 'index'),
                                'resource' => ParametrecategoriePrivileges::getResourceId(ParametrecategoriePrivileges::PARAMETRECATEGORIE_INDEX),
                                'order'    => 3000,
                                'pages' => [],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],

    'router'          => [
        'routes' => [
            'parametre' => [
                'type'  => Literal::class,
                'options' => [
                    'route'    => '/parametre',
                    'defaults' => [
                        'controller' => CategorieController::class,
                    ],
                ],
                'may_terminate' => false,
                'child_routes' => [
                    'index' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/index[/:categorie]',
                            'defaults' => [
                                'controller' => CategorieController::class,
                                'action' => 'index'
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'categorie' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/categorie',
                            'defaults' => [
                                'controller' => CategorieController::class,
                            ],
                        ],
                        'may_terminate' => false,
                        'child_routes' => [
                            'ajouter' => [
                                'type'  => Literal::class,
                                'options' => [
                                    'route'    => '/ajouter',
                                    'defaults' => [
                                        'controller' => CategorieController::class,
                                        'action' => 'ajouter'
                                    ],
                                ],
                            ],
                            'modifier' => [
                                'type'  => Segment::class,
                                'options' => [
                                    'route'    => '/modifier/:categorie',
                                    'defaults' => [
                                        'controller' => CategorieController::class,
                                        'action' => 'modifier'
                                    ],
                                ],
                            ],
                            'supprimer' => [
                                'type'  => Segment::class,
                                'options' => [
                                    'route'    => '/supprimer/:categorie',
                                    'defaults' => [
                                        'controller' => CategorieController::class,
                                        'action' => 'supprimer'
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],

+83 −2
Original line number Diff line number Diff line
@@ -2,8 +2,11 @@

namespace UnicaenParametre;

use UnicaenParametre\Controller\ParametreController;
use UnicaenParametre\Controller\ParametreControllerFactory;
use UnicaenParametre\Form\Parametre\ParametreForm;
use UnicaenParametre\Form\Parametre\ParametreFormFactory;
use UnicaenParametre\Provider\Privilege\ParametrePrivileges;
use UnicaenParametre\Service\Parametre\ParametreService;
use UnicaenParametre\Service\Parametre\ParametreServiceFactory;
use UnicaenPrivilege\Guard\PrivilegeController;
@@ -14,13 +17,89 @@ return [
    'bjyauthorize' => [
        'guards' => [
            PrivilegeController::class => [

                [
                    'controller' => ParametreController::class,
                    'action' => [
                        'ajouter',
                    ],
                    'pivileges' => ParametrePrivileges::PARAMETRE_AJOUTER,
                ],
                [
                    'controller' => ParametreController::class,
                    'action' => [
                        'modifier',
                    ],
                    'pivileges' => ParametrePrivileges::PARAMETRE_MODIFIER,
                ],
                [
                    'controller' => ParametreController::class,
                    'action' => [
                        'modifier-valeur',
                    ],
                    'pivileges' => ParametrePrivileges::PARAMETRE_VALEUR,
                ],
                [
                    'controller' => ParametreController::class,
                    'action' => [
                        'supprimer',
                    ],
                    'pivileges' => ParametrePrivileges::PARAMETRE_SUPPRIMER,
                ],
            ],
        ],
    ],

    'router'          => [
        'routes' => [
            'parametre' => [
                'type'  => Literal::class,
                'options' => [
                    'route'    => '/parametre',
                ],
                'may_terminate' => false,
                'child_routes' => [
                    'ajouter' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/ajouter/:categorie',
                            'defaults' => [
                                'controller' => ParametreController::class,
                                'action' => 'ajouter'
                            ],
                        ],
                    ],
                    'modifier' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/modifier/:parametre',
                            'defaults' => [
                                'controller' => ParametreController::class,
                                'action' => 'modifier'
                            ],
                        ],
                    ],
                    'supprimer' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/supprimer/:parametre',
                            'defaults' => [
                                'controller' => ParametreController::class,
                                'action' => 'supprimer'
                            ],
                        ],
                    ],
                    'modifier-valeur' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/modifier-valeur/:parametre',
                            'defaults' => [
                                'controller' => ParametreController::class,
                                'action' => 'modifier-valeur'
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],

@@ -30,7 +109,9 @@ return [
        ],
    ],
    'controllers'     => [
        'factories' => [],
        'factories' => [
            ParametreController::class => ParametreControllerFactory::class,
        ],
    ],
    'form_elements' => [
        'factories' => [
+17 −2
Original line number Diff line number Diff line
@@ -37,11 +37,26 @@ create table unicaen_parametre_parametre
    ordre integer default 9999
);

alter table unicaen_parametre_parametre owner to ad_preecog_prod;

create unique index unicaen_parametre_parametre_id_uindex
    on unicaen_parametre_parametre (id);

create unique index unicaen_parametre_parametre_code_categorie_id_uindex
    on unicaen_parametre_parametre (code, categorie_id);

-- PRIVILEGES ----------------------------------------------------------------------------------------------------------

INSERT INTO unicaen_privilege_categorie (id, code, libelle, ordre, namespace) VALUES (nextval(unicaen_privilege_categorie_id_seq), 'parametrecategorie', 'UnicaenParametre - Gestion des catégories de paramètres', 70000, 'UnicaenParametre\Provider\Privilege');
INSERT INTO unicaen_privilege_privilege (categorie_id, code, libelle, ordre) VALUES (lastval(unicaen_privilege_categorie_id_seq), 'parametrecategorie_index', 'Affichage de l''index des paramètres', 10);
INSERT INTO unicaen_privilege_privilege (categorie_id, code, libelle, ordre) VALUES (lastval(unicaen_privilege_categorie_id_seq), 'parametrecategorie_modifier', 'Modifier une catégorie de paramètre', 40);
INSERT INTO unicaen_privilege_privilege (categorie_id, code, libelle, ordre) VALUES (lastval(unicaen_privilege_categorie_id_seq), 'parametrecategorie_ajouter', 'Ajouter une catégorie de paramètre', 30);
INSERT INTO unicaen_privilege_privilege (categorie_id, code, libelle, ordre) VALUES (lastval(unicaen_privilege_categorie_id_seq), 'parametrecategorie_supprimer', 'Supprimer une catégorie de paramètre', 60);
INSERT INTO unicaen_privilege_privilege (categorie_id, code, libelle, ordre) VALUES (lastval(unicaen_privilege_categorie_id_seq), 'parametrecategorie_afficher', 'Affichage des détails d''une catégorie', 20);

INSERT INTO unicaen_privilege_categorie (id, code, libelle, ordre, namespace) VALUES (nextval(unicaen_privilege_categorie_id_seq), 'parametre', 'UnicaenParametre - Gestion des paramètres', 70001, 'UnicaenParametre\Provider\Privilege');
INSERT INTO unicaen_privilege_privilege (categorie_id, code, libelle, ordre) VALUES (lastval(unicaen_privilege_categorie_id_seq), 'parametre_afficher', 'Afficher un paramètre', 10);
INSERT INTO unicaen_privilege_privilege (categorie_id, code, libelle, ordre) VALUES (lastval(unicaen_privilege_categorie_id_seq), 'parametre_ajouter', 'Ajouter un paramètre', 20);
INSERT INTO unicaen_privilege_privilege (categorie_id, code, libelle, ordre) VALUES (lastval(unicaen_privilege_categorie_id_seq), 'parametre_modifier', 'Modifier un paramètre', 30);
INSERT INTO unicaen_privilege_privilege (categorie_id, code, libelle, ordre) VALUES (lastval(unicaen_privilege_categorie_id_seq), 'parametre_supprimer', 'Supprimer un paramètre', 50);
INSERT INTO unicaen_privilege_privilege (categorie_id, code, libelle, ordre) VALUES (lastval(unicaen_privilege_categorie_id_seq), 'parametre_valeur', 'Modifier la valeur d''un parametre', 100);

--TODO penser à accorder les privilèges selon le besoin
 No newline at end of file
+79 −0
Original line number Diff line number Diff line
@@ -2,23 +2,102 @@

namespace UnicaenParametre\Controller;

use UnicaenParametre\Entity\Db\Categorie;
use UnicaenParametre\Form\Categorie\CategorieFormAwareTrait;
use UnicaenParametre\Service\Categorie\CategorieServiceAwareTrait;
use UnicaenParametre\Service\Parametre\ParametreServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class CategorieController extends AbstractActionController {
    use CategorieServiceAwareTrait;
    use ParametreServiceAwareTrait;
    use CategorieFormAwareTrait;

    public function indexAction()
    {
        $categories = $this->getCategorieService()->getCategories();
        $parametres = $this->getParametreService()->getParametres();
        $selection = $this->getCategorieService()->getRequestedCategorie($this);

        return new ViewModel([
            'categories' => $categories,
            'parametres' => $parametres,
            'selection' => $selection,
        ]);
    }

    public function ajouterAction() {

        $categorie = new Categorie();
        $form = $this->getCategorieForm();
        $form->setAttribute('action', $this->url()->fromRoute('parametre/categorie/ajouter', [], [], true));
        $form->bind($categorie);

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                $this->getCategorieService()->create($categorie);
            }
        }

        $vm = new ViewModel([
            'title' => "Ajout d'une catégorie de paramètre",
            'form' => $form,
        ]);
        $vm->setTemplate('unicaen-parametre/default/default-form');
        return $vm;
    }

    public function modifierAction()
    {
        $categorie = $this->getCategorieService()->getRequestedCategorie($this);
        $form = $this->getCategorieForm();
        $form->setOldCode($categorie->getCode());
        $form->setAttribute('action', $this->url()->fromRoute('parametre/categorie/modifier', ['categorie' => $categorie->getId()], [], true));
        $form->bind($categorie);

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                $this->getCategorieService()->update($categorie);
            }
        }

        $vm = new ViewModel([
            'title' => "Modification de la catégorie [".$categorie->getCode()."] ",
            'form' => $form,
        ]);
        $vm->setTemplate('unicaen-parametre/default/default-form');
        return $vm;
    }

    public function supprimerAction()
    {
        $categorie = $this->getCategorieService()->getRequestedCategorie($this);

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            if ($data["reponse"] === "oui") $this->getCategorieService()->delete($categorie);
            exit();
        }

        $vm = new ViewModel();
        if ($categorie !== null) {
            $vm->setTemplate('unicaen-parametre/default/confirmation');
            $vm->setVariables([
                'title' => "Suppression de la catégorie de  paramètre [" . $categorie->getCode() . "]",
                'text' => "La suppression est définitive êtes-vous sûr·e de vouloir continuer ?",
                'action' => $this->url()->fromRoute('parametre/categorie/supprimer', ["categorie" => $categorie->getId()], [], true),
            ]);
        }
        return $vm;
    }


}
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace UnicaenParametre\Controller;
use Interop\Container\ContainerInterface;
use UnicaenParametre\Form\Categorie\CategorieForm;
use UnicaenParametre\Service\Categorie\CategorieService;
use UnicaenParametre\Service\Parametre\ParametreService;

class CategorieControllerFactory {

@@ -12,8 +13,10 @@ class CategorieControllerFactory {
    {
        /**
         * @var CategorieService $categorieService
         * @var ParametreService $parametreService
         */
        $categorieService = $container->get(CategorieService::class);
        $parametreService = $container->get(ParametreService::class);

        /**
         * @var CategorieForm $categorieForm
@@ -22,6 +25,7 @@ class CategorieControllerFactory {

        $controller = new CategorieController();
        $controller->setCategorieService($categorieService);
        $controller->setParametreService($parametreService);
        $controller->setCategorieForm($categorieForm);
        return $controller;
    }
Loading