Commit 15a20de4 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Blocage et redirection des créer ou duplication de fiche de poste pour des agents en ayant déjà une

parent 9357a2e4
Loading
Loading
Loading
Loading
+19 −2
Changes for module/Application/src/Application/Controller/FichePosteController.php: 19 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -98,6 +98,15 @@ class FichePosteController extends AbstractActionController {
    public function ajouterAction()
    {
        $agent = $this->getAgentService()->getRequestedAgent($this);

        if ($agent) {
            $fiche = $this->getFichePosteService()->getFichePosteByAgent($agent);
            if ($fiche !== null) {
                $this->flashMessenger()->addErrorMessage("La fiche de poste existe déjà l'ajout n'a pu être effectué.");
                return $this->redirect()->toRoute('fiche-poste/editer', ['fiche-poste' => $fiche->getId()], [], true);
            }
        }

        $fiche = new FichePoste();
        $fiche->setAgent($agent);
        $this->getFichePosteService()->create($fiche);
@@ -106,11 +115,19 @@ class FichePosteController extends AbstractActionController {

    public function dupliquerAction()
    {
        $structure = $this->getStructureService()->getRequestedStructure($this);
        $agent = $this->getAgentService()->getRequestedAgent($this);
        if ($agent !== null) {
            $fiche = $this->getFichePosteService()->getFichePosteByAgent($agent);
            if ($fiche !== null) {
                $this->flashMessenger()->addErrorMessage("La fiche de poste existe déjà la duplication n'a pu être effectuée.");
                return $this->redirect()->toRoute('fiche-poste/editer', ['fiche-poste' => $fiche->getId()], [], true);
            }
        }

        $structure = $this->getStructureService()->getRequestedStructure($this);
        $structures = $this->getStructureService()->getStructuresFilles($structure);
        $structures[] = $structure;
        $agent = $this->getAgentService()->getRequestedAgent($this);

        $fiches = $this->getFichePosteService()->getFichesPostesByStructures($structures, true);

        /** @var Request $request */
+21
Changes for module/Application/src/Application/Service/FichePoste/FichePosteService.php: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Application\Service\FichePoste;

use Application\Entity\Db\Activite;
use Application\Entity\Db\Agent;
use Application\Entity\Db\FicheMetier;
use Application\Entity\Db\FichePoste;
use Application\Entity\Db\FicheposteApplicationRetiree;
@@ -629,4 +630,24 @@ class FichePosteService {

        return $dictionnaire;
    }

    /**
     * @param Agent $agent
     * @return FichePoste
     */
    public function getFichePosteByAgent(Agent $agent)
    {
        $qb = $this->createQueryBuilder()
            ->andWhere('fiche.agent = :agent')
            ->setParameter('agent',$agent)
            ->andWhere('fiche.histoDestruction IS NULL')
        ;

        try {
            $result = $qb->getQuery()->getOneOrNullResult();
        } catch (NonUniqueResultException $e) {
            throw new RuntimeException("Plusieurs fiche de postes actives associés à l'agent [".$agent->getId()."|".$agent->getDenomination()."]",0,$e);
        }
        return $result;
    }
}
 No newline at end of file
+2
Changes for module/Application/view/application/fiche-poste/editer.phtml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ $this->headTitle("Modification de la fiche de poste #".$fiche->getId());
        a.action {width: 18em;}
    </style>

    <?php echo $this->messenger()->addMessagesFromFlashMessenger(); ?>

    <div class="row">
        <div class="col-md-9">
            <h1 class="page-header">
+2
Changes for module/Application/view/application/fiche-poste/partial/environnement-poste.phtml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@ $canModifier = $this->isAllowed($fiche, FichePostePrivileges::FICHEPOSTE_MODIFIE
$poste = $fiche->getPoste();
/** @var Structure[] $structures */
$structures = [];
if ($agent !== null) {
    foreach ($agent->getGradesActifs() as $agentGrade) {
        $structure = $agentGrade->getStructure();
        if ($structure !== null) $structures[] = $structure;
    }
}

?>

+1 −1
Changes for module/Application/view/application/structure/partial/agents.phtml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -105,7 +105,7 @@ $canDetruireFichePoste = $this->isAllowed(FichePostePrivileges::getResource
                <?php if($fiche === null) : ?>
                    <?php if ($canAjouterFichePoste) : ?>
                        <a
                            <?php /** @see \Application\Controller\FichePosteController::afficherAction() */ ?>
                            <?php /** @see \Application\Controller\FichePosteController::ajouterAction() */ ?>
                            href="<?php echo $this->url('fiche-poste/ajouter', ['agent' => $agent->getId()], [], true); ?>"
                            target="_blank"
                        ><span class="icon ajouter"