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

Reprise d'un plan de formation dans un autre

parent 648128a2
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -8,6 +8,10 @@ use Formation\Form\PlanDeFormation\PlanDeFormationForm;
use Formation\Form\PlanDeFormation\PlanDeFormationFormFactory;
use Formation\Form\PlanDeFormation\PlanDeFormationHydrator;
use Formation\Form\PlanDeFormation\PlanDeFormationHydratorFactory;
use Formation\Form\SelectionPlanDeFormation\SelectionPlanDeFormationForm;
use Formation\Form\SelectionPlanDeFormation\SelectionPlanDeFormationFormFactory;
use Formation\Form\SelectionPlanDeFormation\SelectionPlanDeFormationHydrator;
use Formation\Form\SelectionPlanDeFormation\SelectionPlanDeFormationHydratorFactory;
use Formation\Provider\Privilege\PlanformationPrivileges;
use Formation\Service\PlanDeFormation\PlanDeFormationService;
use Formation\Service\PlanDeFormation\PlanDeFormationServiceFactory;
@@ -50,6 +54,7 @@ return [
                    'controller' => PlanDeFormationController::class,
                    'action' => [
                        'ajouter',
                        'reprendre',
                    ],
                    'privileges' => [
                        PlanformationPrivileges::PLANFORMATION_AJOUTER
@@ -149,6 +154,17 @@ return [
                            ],
                        ],
                    ],
                    'reprendre' => [
                        'type'  => Segment::class,
                        'options' => [
                            /** @see PlanDeFormationController::reprendreAction() */
                            'route'    => '/reprendre/:plan-de-formation',
                            'defaults' => [
                                'controller' => PlanDeFormationController::class,
                                'action'     => 'reprendre',
                            ],
                        ],
                    ],
                    'afficher' => [
                        'type'  => Segment::class,
                        'options' => [
@@ -201,11 +217,13 @@ return [
    'form_elements' => [
        'factories' => [
            PlanDeFormationForm::class => PlanDeFormationFormFactory::class,
            SelectionPlanDeFormationForm::class => SelectionPlanDeFormationFormFactory::class,
        ],
    ],
    'hydrators' => [
        'factories' => [
            PlanDeFormationHydrator::class => PlanDeFormationHydratorFactory::class,
            SelectionPlanDeFormationHydrator::class => SelectionPlanDeFormationHydratorFactory::class,
        ],
    ]

+29 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Formation\Controller;
use Application\Service\Agent\AgentServiceAwareTrait;
use Formation\Entity\Db\PlanDeFormation;
use Formation\Form\PlanDeFormation\PlanDeFormationFormAwareTrait;
use Formation\Form\SelectionPlanDeFormation\SelectionPlanDeFormationFormAwareTrait;
use Formation\Service\Abonnement\AbonnementServiceAwareTrait;
use Formation\Service\Formation\FormationServiceAwareTrait;
use Formation\Service\FormationGroupe\FormationGroupeServiceAwareTrait;
@@ -23,6 +24,7 @@ class PlanDeFormationController extends AbstractActionController
    use FormationInstanceServiceAwareTrait;

    use PlanDeFormationFormAwareTrait;
    use SelectionPlanDeFormationFormAwareTrait;

    public function indexAction(): ViewModel
    {
@@ -171,4 +173,31 @@ class PlanDeFormationController extends AbstractActionController
        }
        return $vm;
    }

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

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

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();
            $toRecopy = $this->getPlanDeFormationService()->getPlanDeFormation($data['plan']);
            if ($toRecopy !== null) {
                $this->getPlanDeFormationService()->transferer($toRecopy, $planDeFormation);
            }
            exit();
        }

        $vm = new ViewModel([
            'title' => "Reprendre un plan de formation pour le plan de formation [".$planDeFormation->getAnnee()."]",
            'form' => $form,
        ]);
        $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\SelectionPlanDeFormation\SelectionPlanDeFormationForm;
use Formation\Service\Abonnement\AbonnementService;
use Formation\Service\Formation\FormationService;
use Formation\Service\FormationGroupe\FormationGroupeService;
@@ -41,8 +42,10 @@ class PlanDeFormationControllerFactory

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

        $controller = new PlanDeFormationController();
        $controller->setAbonnementService($abonnementService);
@@ -52,6 +55,7 @@ class PlanDeFormationControllerFactory
        $controller->setFormationInstanceService($formationInstanceService);
        $controller->setPlanDeFormationService($planDeFormationService);
        $controller->setPlanDeFormationForm($planDeFormationForm);
        $controller->setSelectionPlanDeFormationForm($selectionPlanDeFormationForm);
        return $controller;
    }
}
 No newline at end of file
+0 −1
Original line number Diff line number Diff line
@@ -44,5 +44,4 @@ class PlanDeFormation {
        return $this->formations->toArray();
    }


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

namespace Formation\Form\SelectionPlanDeFormation;

use Formation\Service\Formation\FormationServiceAwareTrait;
use Formation\Service\PlanDeFormation\PlanDeFormationServiceAwareTrait;
use Laminas\Form\Element\Button;
use Laminas\Form\Element\Select;
use Laminas\Form\Form;
use Laminas\InputFilter\Factory;

class SelectionPlanDeFormationForm extends Form
{
    use PlanDeFormationServiceAwareTrait;

    public function init(): void
    {

        //select multiple avec groupe
        $this->add([
            'type' => Select::class,
            'name' => 'plan',
            'options' => [
                'label' => "Plan de formation :",
                'empty_option' => "Sélectionner un plan de formation ...",
                'value_options' => $this->getPlanDeFormationService()->getPlansDeFormationAsOption(),
            ],
            'attributes' => [
                'id' => 'plan',
                'class' => 'bootstrap-selectpicker show-tick',
                'data-live-search' => 'true',
            ],
        ]);
        //button
        $this->add([
            'type' => Button::class,
            'name' => 'enregistrer',
            'options' => [
                'label' => 'Sélectionner',
                'label_options' => [
                    'disable_html_escape' => true,
                ],
            ],
            'attributes' => [
                'type' => 'submit',
                'class' => 'btn btn-primary',
            ],
        ]);
        //inputfilter
        $this->setInputFilter((new Factory())->createInputFilter([
            'plan' => ['required' => false,],
        ]));
    }
}
 No newline at end of file
Loading