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

Gestion des formations d'un plan de formation

parent 75f11b15
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ return [
                    'controller' => PlanDeFormationController::class,
                    'action' => [
                        'ajouter',
                        'reprendre',
                    ],
                    'privileges' => [
                        PlanformationPrivileges::PLANFORMATION_AJOUTER
@@ -72,6 +71,8 @@ return [
                [
                    'controller' => PlanDeFormationController::class,
                    'action' => [
                        'gerer-formations',
                        'reprendre',
                        'supprimer'
                    ],
                    'privileges' => [
@@ -154,6 +155,17 @@ return [
                            ],
                        ],
                    ],
                    'gerer-formations' => [
                        'type'  => Segment::class,
                        'options' => [
                            /** @see PlanDeFormationController::gererFormationsAction() */
                            'route'    => '/gerer-formations/:plan-de-formation',
                            'defaults' => [
                                'controller' => PlanDeFormationController::class,
                                'action'     => 'ajouter-formation',
                            ],
                        ],
                    ],
                    'reprendre' => [
                        'type'  => Segment::class,
                        'options' => [
+54 −4
Original line number Diff line number Diff line
@@ -3,8 +3,10 @@
namespace Formation\Controller;

use Application\Service\Agent\AgentServiceAwareTrait;
use Formation\Entity\Db\FormationGroupe;
use Formation\Entity\Db\PlanDeFormation;
use Formation\Form\PlanDeFormation\PlanDeFormationFormAwareTrait;
use Formation\Form\SelectionFormation\SelectionFormationFormAwareTrait;
use Formation\Form\SelectionPlanDeFormation\SelectionPlanDeFormationFormAwareTrait;
use Formation\Service\Abonnement\AbonnementServiceAwareTrait;
use Formation\Service\Formation\FormationServiceAwareTrait;
@@ -24,6 +26,7 @@ class PlanDeFormationController extends AbstractActionController
    use FormationInstanceServiceAwareTrait;

    use PlanDeFormationFormAwareTrait;
    use SelectionFormationFormAwareTrait;
    use SelectionPlanDeFormationFormAwareTrait;

    public function indexAction(): ViewModel
@@ -77,11 +80,19 @@ class PlanDeFormationController extends AbstractActionController

        $formations = $plan->getFormations();

        $sansgroupe = new FormationGroupe();
        $sansgroupe->setLibelle("Formations sans groupe");

        $groupes = [];
        $formationsArrayByGroupe = [];
        foreach ($formations as $formation) {
            if ($formation->getGroupe()) {
                $groupes[$formation->getGroupe()->getId()] = $formation->getGroupe();
                $formationsArrayByGroupe[$formation->getGroupe()->getId()][] = $formation;
            } else {
                $groupes[-1] = $sansgroupe;
                $formationsArrayByGroupe[-1][] = $formation;
            }
        }

        $sessionsArrayByFormation = [];
@@ -174,10 +185,50 @@ class PlanDeFormationController extends AbstractActionController
        return $vm;
    }

    /** Gestion des formations d'un plan de formation **************************************************************/

    public function gererFormationsAction() : ViewModel
    {
        $planDeFormation = $this->getPlanDeFormationService()->getRequestedPlanDeFormation($this);

        $form = $this->getSelectionFormationForm();
        $form->setAttribute('action', $this->url()->fromRoute('plan-de-formation/gerer-formations', ['plan-de-formation' => $planDeFormation->getId()], [], true));
        $form->bind($planDeFormation);

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $formationIds = $data['formations'];

            foreach ($planDeFormation->getFormations() as $formation) {
                if (!in_array($formation->getId(), $formationIds)) {
                    $formation->removePlanDeFormation($planDeFormation);
                    $this->getFormationService()->update($formation);
                }
            }
            foreach ($formationIds as $formationId) {
                $formation = $this->getFormationService()->getFormation($formationId);
                if (!$formation->hasPlanDeFormation($planDeFormation)) {
                    $formation->addPlanDeForamtion($planDeFormation);
                    $this->getFormationService()->update($formation);
                }
            }

            exit();
        }

        $vm = new ViewModel([
            'title' => "Ajouter une formation au plan de formation [".$planDeFormation->getAnnee()."]",
            'form' => $form,
        ]);
        $vm->setTemplate('default/default-form');
        return $vm;
    }

    /** Reprend les formations d'un plan de formation et les ajoute à plan courant */
    public function reprendreAction() : ViewModel
    {
        $planDeFormation = $this->getPlanDeFormationService()->getPlanDeFormationByAnnee();
        $planDeFormation = $this->getPlanDeFormationService()->getRequestedPlanDeFormation($this);

        $form = $this->getSelectionPlanDeFormationForm();
        $form->setAttribute('action', $this->url()->fromRoute('plan-de-formation/reprendre', ['plan-de-formation' => $planDeFormation->getId()], [], true));
@@ -198,6 +249,5 @@ class PlanDeFormationController extends AbstractActionController
        ]);
        $vm->setTemplate('default/default-form');
        return $vm;

    }
}
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Formation\Controller;

use Application\Service\Agent\AgentService;
use Formation\Form\PlanDeFormation\PlanDeFormationForm;
use Formation\Form\SelectionFormation\SelectionFormationForm;
use Formation\Form\SelectionPlanDeFormation\SelectionPlanDeFormationForm;
use Formation\Service\Abonnement\AbonnementService;
use Formation\Service\Formation\FormationService;
@@ -42,9 +43,11 @@ class PlanDeFormationControllerFactory

        /**
         * @var PlanDeFormationForm $planDeFormationForm
         * @var SelectionFormationForm $selectionFormationForm
         * @var SelectionPlanDeFormationForm $selectionPlanDeFormationForm
         */
        $planDeFormationForm = $container->get('FormElementManager')->get(PlanDeFormationForm::class);
        $selectionFormationForm = $container->get('FormElementManager')->get(SelectionFormationForm::class);
        $selectionPlanDeFormationForm = $container->get('FormElementManager')->get(SelectionPlanDeFormationForm::class);

        $controller = new PlanDeFormationController();
@@ -55,6 +58,7 @@ class PlanDeFormationControllerFactory
        $controller->setFormationInstanceService($formationInstanceService);
        $controller->setPlanDeFormationService($planDeFormationService);
        $controller->setPlanDeFormationForm($planDeFormationForm);
        $controller->setSelectionFormationForm($selectionFormationForm);
        $controller->setSelectionPlanDeFormationForm($selectionPlanDeFormationForm);
        return $controller;
    }
+0 −57
Original line number Diff line number Diff line
<?php

namespace Formation\Controller;

use Application\Service\Agent\AgentServiceAwareTrait;
use Formation\Service\Abonnement\AbonnementServiceAwareTrait;
use Formation\Service\Formation\FormationServiceAwareTrait;
use Formation\Service\FormationGroupe\FormationGroupeServiceAwareTrait;
use Formation\Service\FormationInstance\FormationInstanceServiceAwareTrait;
use Formation\Service\PlanDeFormation\PlanDeFormationServiceAwareTrait;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;

class PlanFormationController extends AbstractActionController
{
    use AbonnementServiceAwareTrait;
    use AgentServiceAwareTrait;
    use FormationGroupeServiceAwareTrait;
    use FormationServiceAwareTrait;
    use PlanDeFormationServiceAwareTrait;

    use FormationInstanceServiceAwareTrait;

    public function afficherAction(): ViewModel
    {
        $planDeFormation = $this->getPlanDeFormationService()->getPlanDeFormationByAnnee();


        $formations = $planDeFormation->getFormations();

        $groupes = [];
        $formationsArrayByGroupe = [];
        foreach ($formations as $formation) {
            $groupes[$formation->getGroupe()->getId()] = $formation->getGroupe();
            $formationsArrayByGroupe[$formation->getGroupe()->getId()][] = $formation;
        }

        $sessionsArrayByFormation = [];
        foreach ($formations as $formation) {
            //todo recupérer par lot
            $sessionsArrayByFormation[$formation->getId()] = $this->getFormationInstanceService()->getFormationsInstancesOuvertesByFormation($formation);
        }

        $abonnements = [];
        $agent = $this->getAgentService()->getAgentByConnectedUser();
        if ($agent !== null) $abonnements = $this->getAbonnementService()->getAbonnementsByAgent($agent);

        return new ViewModel([
            'planDeFormation' => $planDeFormation,
            'formations' => $formations,
            'groupes' => $groupes,
            'formationsArrayByGroupe' => $formationsArrayByGroupe,
            'sessionsArrayByFormation' => $sessionsArrayByFormation,
            'abonnements' => $abonnements,
        ]);
    }
}
 No newline at end of file
+0 −50
Original line number Diff line number Diff line
<?php

namespace Formation\Controller;

use Application\Service\Agent\AgentService;
use Formation\Service\Abonnement\AbonnementService;
use Formation\Service\Formation\FormationService;
use Formation\Service\FormationGroupe\FormationGroupeService;
use Formation\Service\FormationInstance\FormationInstanceService;
use Formation\Service\PlanDeFormation\PlanDeFormationService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

class PlanFormationControllerFactory
{

    /**
     * @param ContainerInterface $container
     * @return PlanFormationController
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function __invoke(ContainerInterface $container): PlanFormationController
    {
        /**
         * @var AbonnementService $abonnementService
         * @var AgentService $agentService
         * @var FormationService $formationService
         * @var FormationGroupeService $formationGroupeService
         * @var FormationInstanceService $formationInstanceService
         * @var PlanDeFormationService $planDeFormationService
         */
        $abonnementService = $container->get(AbonnementService::class);
        $agentService = $container->get(AgentService::class);
        $formationService = $container->get(FormationService::class);
        $formationGroupeService = $container->get(FormationGroupeService::class);
        $formationInstanceService = $container->get(FormationInstanceService::class);
        $planDeFormationService = $container->get(PlanDeFormationService::class);

        $controller = new PlanFormationController();
        $controller->setAbonnementService($abonnementService);
        $controller->setAgentService($agentService);
        $controller->setFormationService($formationService);
        $controller->setFormationGroupeService($formationGroupeService);
        $controller->setFormationInstanceService($formationInstanceService);
        $controller->setPlanDeFormationService($planDeFormationService);
        return $controller;
    }
}
 No newline at end of file
Loading