Commit 93c54200 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Référentiel de compétences

parent ee9ce423
Loading
Loading
Loading
Loading
+59 −0
Original line number Diff line number Diff line
-- STRUCTURE DE LA BASE ---------------------------------------------------------------------------------

create table public.element_competence_referentiel
(
    id                    serial
        constraint element_competence_referentiel_pk
        primary key,
    libelle_court         varchar(64)             not null,
    libelle_long          varchar(1024)           not null,
    couleur               varchar(64),
    histo_creation        timestamp default now() not null,
    histo_createur_id     integer   default 0     not null
        constraint element_competence_referentiel_unicaen_utilisateur_user_id_fk
        references public.unicaen_utilisateur_user,
    histo_modification    timestamp,
    histo_modificateur_id integer
        constraint element_competence_referentiel_unicaen_utilisateur_user_id_fk2
        references public.unicaen_utilisateur_user,
    histo_destruction     timestamp,
    histo_destructeur_id  integer
        constraint element_competence_referentiel_unicaen_utilisateur_user_id_fk3
        references public.unicaen_utilisateur_user
);
comment on column public.element_competence_referentiel.libelle_court is 'Est utilisé pour l''affichage du badge';
comment on column public.element_competence_referentiel.couleur is 'Est utilisée pour l''afficahge du badge';


alter table element_competence
    add referentiel_id integer;
alter table element_competence
    add constraint element_competence_element_competence_referentiel_id_fk
        foreign key (referentiel_id) references element_competence_referentiel
            on delete set null;

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

INSERT INTO unicaen_privilege_categorie (code, libelle, namespace, ordre)
VALUES ('competencereferentiel', 'Gestions des référentiels de compétence', 'Element\Provider\Privilege', 70800);
INSERT INTO unicaen_privilege_privilege(CATEGORIE_ID, CODE, LIBELLE, ORDRE)
WITH d(code, lib, ordre) AS (
    SELECT 'competencereferentiel_index', 'Accéder à l''index des référentiels de compétences', 10 UNION
    SELECT 'competencereferentiel_afficher', 'Afficher', 20 UNION
    SELECT 'competencereferentiel_ajouter', 'Ajouter', 30 UNION
    SELECT 'competencereferentiel_modifier', 'Modifier', 40 UNION
    SELECT 'competencereferentiel_historiser', 'Historiser/Restaurer', 50 UNION
    SELECT 'competencereferentiel_effacer', 'Supprimer', 60
)
SELECT cp.id, d.code, d.lib, d.ordre
FROM d
JOIN unicaen_privilege_categorie cp ON cp.CODE = 'competencereferentiel';

-- MODIF DE BASE -----------------------------------------------------------------------------------------

INSERT INTO element_competence_referentiel (id,libelle_court, libelle_long, couleur) VALUES
(1,'EMC2', 'Référentiel interne à EMC2', '#3465a4'),
(2,'REFERENS3', 'Référentiel des BIATSS Referens3', '#ce5c00');

update element_competence set referentiel_id=1 where source='EMC2';
update element_competence set referentiel_id=2 where source='REFERENS3';
+201 −0
Original line number Diff line number Diff line
<?php

namespace Element;

use Element\Controller\CompetenceReferentielController;
use Element\Controller\CompetenceReferentielControllerFactory;
use Element\Form\CompetenceReferentiel\CompetenceReferentielForm;
use Element\Form\CompetenceReferentiel\CompetenceReferentielFormFactory;
use Element\Form\CompetenceReferentiel\CompetenceReferentielHydrator;
use Element\Form\CompetenceReferentiel\CompetenceReferentielHydratorFactory;
use Element\Provider\Privilege\CompetencereferentielPrivileges;
use Element\Service\CompetenceReferentiel\CompetenceReferentielService;
use Element\Service\CompetenceReferentiel\CompetenceReferentielServiceFactory;
use Element\View\Helper\CompetenceReferenceViewHelper;
use Laminas\Router\Http\Literal;
use Laminas\Router\Http\Segment;
use UnicaenPrivilege\Guard\PrivilegeController;

return [
    'bjyauthorize' => [
        'guards' => [
            PrivilegeController::class => [
                [
                    'controller' => CompetenceReferentielController::class,
                    'action' => [
                        'index',
                    ],
                    'privileges' => [
                        CompetencereferentielPrivileges::COMPETENCEREFERENTIEL_INDEX,
                    ],
                ],
                [
                    'controller' => CompetenceReferentielController::class,
                    'action' => [
                        'afficher',
                    ],
                    'privileges' => [
                        CompetencereferentielPrivileges::COMPETENCEREFERENTIEL_AFFICHER,
                    ],
                ],
                [
                    'controller' => CompetenceReferentielController::class,
                    'action' => [
                        'ajouter',
                    ],
                    'privileges' => [
                        CompetencereferentielPrivileges::COMPETENCEREFERENTIEL_AJOUTER,
                    ],
                ],
                [
                    'controller' => CompetenceReferentielController::class,
                    'action' => [
                        'modifier',
                    ],
                    'privileges' => [
                        CompetencereferentielPrivileges::COMPETENCEREFERENTIEL_MODIFIER,
                    ],
                ],
                [
                    'controller' => CompetenceReferentielController::class,
                    'action' => [
                        'historiser',
                        'restaurer',
                    ],
                    'privileges' => [
                        CompetencereferentielPrivileges::COMPETENCEREFERENTIEL_HISTORISER,
                    ],
                ],
                [
                    'controller' => CompetenceReferentielController::class,
                    'action' => [
                        'supprimer',
                    ],
                    'privileges' => [
                        CompetencereferentielPrivileges::COMPETENCEREFERENTIEL_EFFACER,
                    ],
                ],
            ],
        ],
    ],

    'router' => [
        'routes' => [
            'element' => [
                'type' => Literal::class,
                'options' => [
                    'route' => '/element',
                ],
                'may_terminate' => true,
                'child_routes' => [
                    'competence-referentiel' => [
                        'type' => Literal::class,
                        'options' => [
                            'route' => '/competence-referentiel',
                            'defaults' => [
                                /** @see CompetenceReferentielController::indexAction() */
                                'controller' => CompetenceReferentielController::class,
                                'action' => 'index',
                            ],
                        ],
                        'may_terminate' => true,
                        'child_routes' => [
                            'afficher' => [
                                'type' => Segment::class,
                                'options' => [
                                    'route' => '/afficher/:competence-referentiel',
                                    'defaults' => [
                                        /** @see CompetenceReferentielController::afficherAction() */
                                        'controller' => CompetenceReferentielController::class,
                                        'action' => 'afficher',
                                    ],
                                ],
                            ],
                            'ajouter' => [
                                'type' => Literal::class,
                                'options' => [
                                    'route' => '/ajouter',
                                    'defaults' => [
                                        /** @see CompetenceReferentielController::ajouterAction() */
                                        'controller' => CompetenceReferentielController::class,
                                        'action' => 'ajouter',
                                    ],
                                ],
                            ],
                            'modifier' => [
                                'type' => Segment::class,
                                'options' => [
                                    'route' => '/modifier/:competence-referentiel',
                                    'defaults' => [
                                        /** @see CompetenceReferentielController::modifierAction() */
                                        'controller' => CompetenceReferentielController::class,
                                        'action' => 'modifier',
                                    ],
                                ],
                            ],
                            'historiser' => [
                                'type' => Segment::class,
                                'options' => [
                                    'route' => '/historiser/:competence-referentiel',
                                    'defaults' => [
                                        /** @see CompetenceReferentielController::historiserAction() */
                                        'controller' => CompetenceReferentielController::class,
                                        'action' => 'historiser',
                                    ],
                                ],
                            ],
                            'restaurer' => [
                                'type' => Segment::class,
                                'options' => [
                                    'route' => '/restaurer/:competence-referentiel',
                                    'defaults' => [
                                        /** @see CompetenceReferentielController::restaurerAction() */
                                        'controller' => CompetenceReferentielController::class,
                                        'action' => 'restaurer',
                                    ],
                                ],
                            ],
                            'supprimer' => [
                                'type' => Segment::class,
                                'options' => [
                                    'route' => '/supprimer/:competence-referentiel',
                                    'defaults' => [
                                        /** @see CompetenceReferentielController::supprimerAction() */
                                        'controller' => CompetenceReferentielController::class,
                                        'action' => 'supprimer',
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],

    'service_manager' => [
        'factories' => [
            CompetenceReferentielService::class => CompetenceReferentielServiceFactory::class
        ],
    ],
    'controllers' => [
        'factories' => [
            CompetenceReferentielController::class => CompetenceReferentielControllerFactory::class,
        ],
    ],
    'form_elements' => [
        'factories' => [
            CompetenceReferentielForm::class => CompetenceReferentielFormFactory::class,
        ],
    ],
    'hydrators' => [
        'factories' => [
            CompetenceReferentielHydrator::class => CompetenceReferentielHydratorFactory::class
        ],
    ],
    'view_helpers' => [
        'invokables' => [
            'competenceReference' => CompetenceReferenceViewHelper::class,
        ],
    ],
];
 No newline at end of file
+132 −0
Original line number Diff line number Diff line
<?php

namespace Element\Controller;

use Element\Entity\Db\CompetenceReferentiel;
use Element\Form\CompetenceReferentiel\CompetenceReferentielFormAwareTrait;
use Element\Service\CompetenceReferentiel\CompetenceReferentielServiceAwareTrait;
use Laminas\Http\Request;
use Laminas\Http\Response;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;

class CompetenceReferentielController extends AbstractActionController
{
    use CompetenceReferentielServiceAwareTrait;
    use CompetenceReferentielFormAwareTrait;

    public function indexAction(): ViewModel
    {
        $referentiels = $this->getCompetenceReferentielService()->getCompetencesReferentiels();

        return new ViewModel([
            'referentiels' => $referentiels,
        ]);
    }

    public function afficherAction(): ViewModel
    {
        $referentiel = $this->getCompetenceReferentielService()->getRequestedCompetenceReferentiel($this);
        return new ViewModel([
            'title' => "Affichage d'un référentiel de compétences",
            'referentiel' => $referentiel,
        ]);
    }

    public function ajouterAction(): ViewModel
    {
        $referentiel = new CompetenceReferentiel();
        $form = $this->getCompetenceReferentielForm();
        $form->setAttribute('action', $this->url()->fromRoute('element/competence-referentiel/ajouter', [], [], true));
        $form->bind($referentiel);

        /** @var Request $request */
        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                $this->getCompetenceReferentielService()->create($referentiel);
                exit();
            }
        }

        $vm = new ViewModel();
        $vm->setTemplate('default/default-form');
        $vm->setVariables([
            'title' => "Ajout d'un référentiel de compétences",
            'form' => $form,
        ]);
        return $vm;
    }

    public function modifierAction(): ViewModel
    {
        $referentiel = $this->getCompetenceReferentielService()->getRequestedCompetenceReferentiel($this);
        $form = $this->getCompetenceReferentielForm();
        $form->setAttribute('action', $this->url()->fromRoute('element/competence-referentiel/modifier', ['competence-referentiel' => $referentiel->getId()], [], true));
        $form->bind($referentiel);

        /** @var Request $request */
        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $form->setData($data);
            if ($form->isValid()) {
                $this->getCompetenceReferentielService()->update($referentiel);
            }
        }

        $vm = new ViewModel();
        $vm->setTemplate('default/default-form');
        $vm->setVariables([
            'title' => "Modification d'un référentiel de compétences",
            'form' => $form,
        ]);
        return $vm;
    }

    public function historiserAction(): Response
    {
        $referentiel = $this->getCompetenceReferentielService()->getRequestedCompetenceReferentiel($this);
        $this->getCompetenceReferentielService()->historise($referentiel);

        $retour = $this->params()->fromQuery('retour');
        if ($retour) return $this->redirect()->toUrl($retour);
        return $this->redirect()->toRoute('element/competence-referentiel', [], [], true);
    }

    public function restaurerAction(): Response
    {
        $referentiel = $this->getCompetenceReferentielService()->getRequestedCompetenceReferentiel($this);
        $this->getCompetenceReferentielService()->restore($referentiel);

        $retour = $this->params()->fromQuery('retour');
        if ($retour) return $this->redirect()->toUrl($retour);
        return $this->redirect()->toRoute('element/competence-referentiel', [], [], true);
    }

    public function supprimerAction(): ViewModel
    {
        $referentiel = $this->getCompetenceReferentielService()->getRequestedCompetenceReferentiel($this);

        /** @var Request $request */
        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            if ($data["reponse"] === "oui") $this->getCompetenceReferentielService()->delete($referentiel);
            exit();
        }

        $vm = new ViewModel();
        if ($referentiel !== null) {
            $vm->setTemplate('default/confirmation');
            $vm->setVariables([
                'title' => "Suppression du référentiel de compétences  " . $referentiel->getLibelleCourt(),
                'text' => "La suppression est définitive êtes-vous sûr&middot;e de vouloir continuer ?",
                'action' => $this->url()->fromRoute('element/competence-referentiel/supprimer', ["competence-referentiel" => $referentiel->getId()], [], true),
            ]);
        }
        return $vm;
    }
}
 No newline at end of file
+33 −0
Original line number Diff line number Diff line
<?php

namespace Element\Controller;

use Element\Form\CompetenceReferentiel\CompetenceReferentielForm;
use Element\Service\CompetenceReferentiel\CompetenceReferentielService;
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class CompetenceReferentielControllerFactory {

    /**
     * @param ContainerInterface $container
     * @return CompetenceReferentielController
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function __invoke(ContainerInterface $container) : CompetenceReferentielController
    {
        /**
         * @var CompetenceReferentielService $competenceReferentielService
         * @var CompetenceReferentielForm $competenceReferentielForm
         */
        $competenceReferentielService = $container->get(CompetenceReferentielService::class);
        $competenceReferentielForm = $container->get('FormElementManager')->get(CompetenceReferentielForm::class);

        $controller = new CompetenceReferentielController();
        $controller->setCompetenceReferentielService($competenceReferentielService);
        $controller->setCompetenceReferentielForm($competenceReferentielForm);
        return $controller;
    }
}
 No newline at end of file
+11 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ class Competence implements HistoriqueAwareInterface {
    private ?string $description = null;
    private ?CompetenceType $type = null;
    private ?CompetenceTheme $theme = null;
    private ?CompetenceReferentiel $referentiel = null;
    private ?string $source = null;
    private ?string $idSource = null;

@@ -64,6 +65,16 @@ class Competence implements HistoriqueAwareInterface {
        $this->theme = $theme;
    }

    public function getReferentiel(): ?CompetenceReferentiel
    {
        return $this->referentiel;
    }

    public function setReferentiel(?CompetenceReferentiel $referentiel): void
    {
        $this->referentiel = $referentiel;
    }

    public function getSource(): ?string
    {
        return $this->source;
Loading