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

Association du poste à la fiche metier

parent 839db559
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@ use Application\Form\FicheMetier\AssocierMetierTypeForm;
use Application\Form\FicheMetier\AssocierMetierTypeFormFactory;
use Application\Form\FicheMetier\AssocierMetierTypeHydrator;
use Application\Form\FicheMetier\AssocierMetierTypeHydratorFactory;
use Application\Form\FicheMetier\AssocierPosteForm;
use Application\Form\FicheMetier\AssocierPosteFormFactory;
use Application\Form\FicheMetier\AssocierPosteHydrator;
use Application\Form\FicheMetier\AssocierPosteHydratorFactory;
use Application\Form\FicheMetier\FicheMetierCreationForm;
use Application\Form\FicheMetier\FicheMetierCreationFormFactory;
use Application\Form\FicheMetier\FicheMetierCreationHydrator;
@@ -66,7 +70,8 @@ return [
                        'supprimer-mission-complementaire',
                        'editer-specificite-poste',
                        'associer-metier-type',
                        'associer-agent'
                        'associer-agent',
                        'associer-poste',
                    ],
                    'privileges' => [
                        FicheMetierPrivileges::AFFICHER,
@@ -154,6 +159,17 @@ return [
                        ],
                        'may_terminate' => true,
                    ],
                    'associer-poste' => [
                        'type' => Segment::class,
                        'options' => [
                            'route'    => '/associer-poste/:fiche',
                            'defaults' => [
                                'controller' => FicheMetierController::class,
                                'action'     => 'associer-poste',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'associer-metier-type' => [
                        'type' => Segment::class,
                        'options' => [
@@ -402,6 +418,7 @@ return [
            SpecificitePosteForm::class => SpecificitePosteFormFactory::class,
            AssocierMetierTypeForm::class => AssocierMetierTypeFormFactory::class,
            AssocierAgentForm::class => AssocierAgentFormFactory::class,
            AssocierPosteForm::class => AssocierPosteFormFactory::class,
        ],
    ],
    'hydrators' => [
@@ -414,6 +431,7 @@ return [
            MissionComplementaireHydrator::class => MissionComplementaireHydratorFactory::class,
            AssocierMetierTypeHydrator::class => AssocierMetierTypeHydratorFactory::class,
            AssocierAgentHydrator::class => AssocierAgentHydratorFactory::class,
            AssocierPosteHydrator::class => AssocierPosteHydratorFactory::class,
        ]
    ],
    'view_helpers' => [
+34 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ use Application\Form\Agent\AgentForm;
use Application\Form\Agent\MissionComplementaireForm;
use Application\Form\FicheMetier\AssocierAgentForm;
use Application\Form\FicheMetier\AssocierMetierTypeForm;
use Application\Form\FicheMetier\AssocierPosteForm;
use Application\Form\FicheMetier\FicheMetierCreationForm;
use Application\Form\FicheMetier\SpecificitePosteForm;
use Application\Service\Activite\ActiviteServiceAwareTrait;
@@ -263,7 +264,7 @@ class FicheMetierController extends AbstractActionController

    }

    /** FICHE METIER TYPE *********************************************************************************************/
    /** AGENT *********************************************************************************************************/

    public function associerAgentAction()
    {
@@ -296,6 +297,38 @@ class FicheMetierController extends AbstractActionController

    }

    /** POSTE *********************************************************************************************************/

    public function associerPosteAction()
    {
        $ficheId = $this->params()->fromRoute('fiche');
        $fiche = $this->getFicheMetierService()->getFicheMetier($ficheId);

        /** @var AssocierAgentForm $form */
        $form = $this->getServiceLocator()->get('FormElementManager')->get(AssocierPosteForm::class);
        $form->setAttribute('action', $this->url()->fromRoute('fiche-metier/associer-poste', ['fiche' => $fiche->getId()], [], true));
        $form->bind($fiche);

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


        $vm = new ViewModel();
        $vm->setTemplate('application/default/default-form');
        $vm->setVariables([
            'title' => 'Associer un poste',
            'form' => $form,
        ]);
        return $vm;

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

    public function editerSpecificitePosteAction()
+56 −0
Original line number Diff line number Diff line
<?php

namespace Application\Form\FicheMetier;

use Application\Entity\Db\Poste;
use DoctrineModule\Form\Element\ObjectSelect;
use UnicaenApp\Service\EntityManagerAwareTrait;
use Zend\Form\Element\Button;
use Zend\Form\Form;

class AssocierPosteForm extends Form {
    use EntityManagerAwareTrait;

    public function init()
    {
        //Selection obligatoire AFFECTATION
        $this->add([
            'type' => ObjectSelect::class,
            'name' => 'poste',
            'options' => [
                'label' => "Poste :",
                'empty_option' => "Sélectionner un poste",
                'object_manager' => $this->getEntityManager(),
                'target_class' => Poste::class,
                'property' => 'numeroPoste',
                'find_method' => [
                    'name' => 'findBy',
                    'params' => [
                        'criteria' => [],
                        'orderBy' => ['numeroPoste' => 'ASC'],
                    ],
                ],
                'disable_inarray_validator' => true,
            ],
            'attributes' => [
                'id' => 'poste',
            ],
        ]);

//        submit
        $this->add([
            'type' => Button::class,
            'name' => 'creer',
            'options' => [
                'label' => '<i class="fas fa-save"></i> Associer le poste',
                'label_options' => [
                    'disable_html_escape' => true,
                ],
            ],
            'attributes' => [
                'type' => 'submit',
                'class' => 'btn btn-primary',
            ],
        ]);
    }
}
 No newline at end of file
+29 −0
Original line number Diff line number Diff line
<?php

namespace Application\Form\FicheMetier;

use Doctrine\ORM\EntityManager;
use Zend\Form\FormElementManager;

class AssocierPosteFormFactory {

    public function __invoke(FormElementManager $manager)
    {
        /** @var AssocierPosteHydrator $hydrator */
        $hydrator = $manager->getServiceLocator()->get('HydratorManager')->get(AssocierPosteHydrator::class);

        /** @var EntityManager $entityManager **/
        $entityManager = $manager->getServiceLocator()->get('doctrine.entitymanager.orm_default');

        /** @var AssocierPosteForm $form */
        $form = new AssocierPosteForm();
        $form->setEntityManager($entityManager);

        $form->setHydrator($hydrator);
        $form->init();


        return $form;
    }

}
 No newline at end of file
+41 −0
Original line number Diff line number Diff line
<?php

namespace Application\Form\FicheMetier;

use Application\Entity\Db\FicheMetier;
use Application\Service\Poste\PosteServiceAwareTrait;
use Zend\Stdlib\Hydrator\HydratorInterface;

;

class AssocierPosteHydrator implements HydratorInterface {
    use PosteServiceAwareTrait;

    /**
     * @param FicheMetier $object
     * @return array
     */
    public function extract($object)
    {
        return [
            'poste' => ($object->getPoste())?$object->getPoste()->getId():0,
        ];
    }

    /**
     * @param FicheMetier $object
     * @param array $data
     * @return FicheMetier
     */
    public function hydrate(array $data, $object)
    {
        $metierType = $this->getPosteService()->getPoste($data['poste']);

        if ($metierType) {
            $object->setPoste($metierType);
        } else {
            $object->setPoste(null);
        }
        return $object;
    }
}
 No newline at end of file
Loading