Commit 658e1b02 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Historisation des fiche type

parent bc9e2ff9
Loading
Loading
Loading
Loading
+51
Changes for module/Application/config/merged/fiche-metier.config.php: 51 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ use Application\Provider\Privilege\FicheMetierPrivileges;
use Application\Service\FicheMetier\FicheMetierService;
use Application\Service\FicheMetier\FicheMetierServiceFactory;
use Application\View\Helper\FicheTypeExterneViewHelper;
use Application\View\Helper\FicheTypeViewHelper;
use Application\View\Helper\SpecificitePosteViewHelper;
use UnicaenAuth\Guard\PrivilegeController;
use Zend\Mvc\Router\Http\Literal;
@@ -119,6 +120,11 @@ return [
                    'controller' => FicheMetierTypeController::class,
                    'action' => [
                        'afficher',
                        'editer',
                        'detruire',
                        'historiser',
                        'restaurer',

                        'editer-libelle',
                        'editer-missions-principales',
                        'retirer-activite',
@@ -327,6 +333,50 @@ return [
                        ],
                        'may_terminate' => true,
                    ],
                    'editer' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/editer/:id',
                            'defaults' => [
                                'controller' => FicheMetierTypeController::class,
                                'action'     => 'editer',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'historiser' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/historiser/:id',
                            'defaults' => [
                                'controller' => FicheMetierTypeController::class,
                                'action'     => 'historiser',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'restaurer' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/restaurer/:id',
                            'defaults' => [
                                'controller' => FicheMetierTypeController::class,
                                'action'     => 'restaurer',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'detruire' => [
                        'type'  => Segment::class,
                        'options' => [
                            'route'    => '/detruire/:id',
                            'defaults' => [
                                'controller' => FicheMetierTypeController::class,
                                'action'     => 'detruire',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'editer-libelle' => [
                        'type'  => Segment::class,
                        'options' => [
@@ -499,6 +549,7 @@ return [
        'invokables' => [
            'specificitePoste' => SpecificitePosteViewHelper::class,
            'ficheTypeExterne' => FicheTypeExterneViewHelper::class,
            'ficheMetierType'  => FicheTypeViewHelper::class,
        ],
    ],

+36
Changes for module/Application/src/Application/Controller/FicheMetier/FicheMetierTypeController.php: 36 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -49,6 +49,18 @@ class FicheMetierTypeController extends AbstractActionController{
    }

    public function afficherAction()
    {
        $fiche = $this->getFicheMetierService()->getRequestedFicheMetierType($this, 'id', true);
//        $activites = $this->getActiviteService()->getActivitesByFicheMetierType($fiche);

        return new ViewModel([
            'title' => 'Visualisation d\'une fiche métier',
            'fiche' => $fiche,
//            'activites' => $activites,
        ]);
    }

    public function editerAction()
    {
        $fiche = $this->getFicheMetierService()->getRequestedFicheMetierType($this, 'id', true);
        $activites = $this->getActiviteService()->getActivitesByFicheMetierType($fiche);
@@ -59,6 +71,30 @@ class FicheMetierTypeController extends AbstractActionController{
        ]);
    }

    public function historiserAction()
    {
        $fiche = $this->getFicheMetierService()->getRequestedFicheMetierType($this, 'id', true);
        $this->getFicheMetierService()->historiserFicheMetierType($fiche);

        $this->redirect()->toRoute('fiche-metier-type', [], [], true);
    }

    public function restaurerAction()
    {
        $fiche = $this->getFicheMetierService()->getRequestedFicheMetierType($this, 'id', true);
        $this->getFicheMetierService()->restaurationFicheMetierType($fiche);

        $this->redirect()->toRoute('fiche-metier-type', [], [], true);
    }

    public function detruireAction()
    {
        $fiche = $this->getFicheMetierService()->getRequestedFicheMetierType($this, 'id', true);
        $this->getFicheMetierService()->deleteFicheMetierType($fiche);

        $this->redirect()->toRoute('fiche-metier-type', [], [], true);
    }

    public function ajouterAction()
    {
        /** @var FicheMetierType $fiche */
+2
Changes for module/Application/src/Application/Entity/Db/FicheMetierType.php: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,8 +3,10 @@
namespace Application\Entity\Db;

use Doctrine\Common\Collections\ArrayCollection;
use UnicaenApp\Entity\HistoriqueAwareTrait;

class FicheMetierType {
    use HistoriqueAwareTrait;

    /** @var int */
    private $id;
+13
Changes for module/Application/src/Application/Entity/Db/Mapping/Application.Entity.Db.FicheMetierType.dcm.xml: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -36,5 +36,18 @@

        <one-to-many target-entity="Application\Entity\Db\FicheMetierTypeActivite" mapped-by="fiche" field="activites"/>

        <field name="histoCreation"     type="datetime"                 column="histo_creation"     nullable="false"/>
        <field name="histoModification" type="datetime"                 column="histo_modification" nullable="false"/>
        <field name="histoDestruction"  type="datetime"                 column="histo_destruction"  nullable="true"/>

        <many-to-one target-entity="Utilisateur\Entity\Db\User"  field="histoCreateur">
            <join-column name="histo_createur_id" referenced-column-name="id"/>
        </many-to-one>
        <many-to-one target-entity="Utilisateur\Entity\Db\User"  field="histoModificateur">
            <join-column name="histo_modificateur_id" referenced-column-name="id"/>
        </many-to-one>
        <many-to-one target-entity="Utilisateur\Entity\Db\User"  field="histoDestructeur">
            <join-column name="histo_destructeur_id" referenced-column-name="id"/>
        </many-to-one>
    </entity>
</doctrine-mapping>
+80
Changes for module/Application/src/Application/Service/FicheMetier/FicheMetierService.php: 80 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ use Application\Entity\Db\FicheMetier;
use Application\Entity\Db\FicheMetierType;
use Application\Entity\Db\FicheTypeExterne;
use Application\Entity\Db\SpecificitePoste;
use Exception;
use Utilisateur\Service\User\UserServiceAwareTrait;
use DateTime;
use Doctrine\ORM\NonUniqueResultException;
@@ -175,6 +176,17 @@ class FicheMetierService {
     */
    public function createFicheMetierType($ficheMetierType)
    {
        try {
            $date = new DateTime();
            $user = $this->getUserService()->getConnectedUser();
        } catch (Exception $e) {
            throw new RuntimeException("Un problème s'est produit lors de la récupération des informations d'historisation", $e);
        }
        $ficheMetierType->setHistoCreation($date);
        $ficheMetierType->setHistoCreateur($user);
        $ficheMetierType->setHistoModification($date);
        $ficheMetierType->setHistoModificateur($user);

        $this->getEntityManager()->persist($ficheMetierType);
        try {
            $this->getEntityManager()->flush($ficheMetierType);
@@ -185,8 +197,21 @@ class FicheMetierService {

    }

    /**
     * @param FicheMetierType $ficheMetierType
     * @return FicheMetierType
     */
    public function updateFicheMetierType($ficheMetierType)
    {
        try {
            $date = new DateTime();
            $user = $this->getUserService()->getConnectedUser();
        } catch (Exception $e) {
            throw new RuntimeException("Un problème s'est produit lors de la récupération des informations d'historisation", $e);
        }
        $ficheMetierType->setHistoModification($date);
        $ficheMetierType->setHistoModificateur($user);

        try {
            $this->getEntityManager()->flush($ficheMetierType);
        } catch (OptimisticLockException $e) {
@@ -195,6 +220,61 @@ class FicheMetierService {
        return $ficheMetierType;
    }

    /**
     * @param FicheMetierType $ficheMetierType
     * @return FicheMetierType
     */
    public function historiserFicheMetierType($ficheMetierType)
    {
        try {
            $date = new DateTime();
            $user = $this->getUserService()->getConnectedUser();
        } catch (Exception $e) {
            throw new RuntimeException("Un problème s'est produit lors de la récupération des informations d'historisation", $e);
        }
        $ficheMetierType->setHistoDestruction($date);
        $ficheMetierType->setHistoDestructeur($user);

        try {
            $this->getEntityManager()->flush($ficheMetierType);
        } catch (OptimisticLockException $e) {
            throw new RuntimeException("Une erreur s'est produite lors de l'historisation de la fiche métier.", $e);
        }
        return $ficheMetierType;
    }

    /**
     * @param FicheMetierType $ficheMetierType
     * @return FicheMetierType
     */
    public function restaurationFicheMetierType($ficheMetierType)
    {
        $ficheMetierType->setHistoDestruction(null);
        $ficheMetierType->setHistoDestructeur(null);

        try {
            $this->getEntityManager()->flush($ficheMetierType);
        } catch (OptimisticLockException $e) {
            throw new RuntimeException("Une erreur s'est produite lors de la restauration de la fiche métier.", $e);
        }
        return $ficheMetierType;
    }

    /**
     * @param FicheMetierType $ficheMetierType
     * @return FicheMetierType
     */
    public function deleteFicheMetierType($ficheMetierType)
    {
        $this->getEntityManager()->remove($ficheMetierType);
        try {
            $this->getEntityManager()->flush();
        } catch (OptimisticLockException $e) {
            throw new RuntimeException("Une erreur s'est produite lors de l'effacement de la fiche métier.", $e);
        }
        return $ficheMetierType;
    }

    /** SPECIFICITE POSTE  ********************************************************************************************/

    /**
Loading