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

Ajout de la vue en catalogue

parent 8388fed0
Loading
Loading
Loading
Loading
+26 −1
Changes for module/Formation/config/others/module.config.php: 26 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Formation;

use Formation\Controller\FormationController;
use Formation\Controller\ModuleController;
use Formation\Controller\ModuleControllerFactory;
use Formation\Form\Module\ModuleForm;
@@ -20,6 +19,15 @@ return [
    'bjyauthorize' => [
        'guards' => [
            PrivilegeController::class => [
                [
                    'controller' => ModuleController::class,
                    'action' => [
                        'catalogue',
                    ],
                    'privileges' => [
                        ModulePrivileges::MODULE_INDEX,
                    ],
                ],
                [
                    'controller' => ModuleController::class,
                    'action' => [
@@ -85,6 +93,12 @@ return [
                'pages' => [
                    'formation' => [
                        'pages' => [
                            'catalogue' => [
                                'label'    => 'Catalogue des formations',
                                'route'    => 'formation/catalogue',
                                'resource' => PrivilegeController::getResourceId(ModuleController::class, 'catalogue') ,
                                'order'    => 0,
                            ],
                            'module' => [
                                'label'    => 'Modules',
                                'route'    => 'formation/module',
@@ -111,6 +125,17 @@ return [
        'routes' => [
            'formation' => [
                'child_routes' => [
                    'catalogue' => [
                        'type'  => Literal::class,
                        'may_terminate' => true,
                        'options' => [
                            'route'    => '/catalogue',
                            'defaults' => [
                                'controller' => ModuleController::class,
                                'action'     => 'catalogue',
                            ],
                        ],
                    ],
                    'module' => [
                        'type'  => Literal::class,
                        'may_terminate' => true,
+42
Changes for module/Formation/src/Formation/Controller/ModuleController.php: 42 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -147,4 +147,46 @@ class ModuleController extends AbstractController {
        }
        return $vm;
    }

    public function catalogueAction()
    {
        /** @var Module[] $modules */
        $modules = $this->getEntityManager()->getRepository(Module::class)->findAll();
        usort($modules, function (Module $a, Module $b) { return $a->getLibelle() > $b->getLibelle(); });
        /** @var Formation[] $formations */
        $formations = $this->getEntityManager()->getRepository(Formation::class)->findAll();

        $catalogue = [];
        foreach ($modules as $module) {
            if ($module->estNonHistorise()) {
                $liste = [];
                foreach ($formations as $formation) {
                    if ($formation->estNonHistorise() AND $formation->getModule() === $module) {
                        $liste[] = $formation;
                    }
                }
                usort($liste, function (Formation $a, Formation $b) { return $a->getLibelle() > $b->getLibelle();});

                $catalogue[$module->getId()]["module"] = $module;
                $catalogue[$module->getId()]["formations"] = $liste;
            }
        }

        {
            $liste = [];
            foreach ($formations as $formation) {
                if ($formation->estNonHistorise() AND $formation->getModule() === null) {
                    $liste[] = $formation;
                }
            }
            usort($liste, function (Formation $a, Formation $b) { return $a->getLibelle() > $b->getLibelle();});

            $catalogue[-1]["module"] = null;
            $catalogue[-1]["formations"] = $liste;
        }

        return new ViewModel([
            'catalogue' => $catalogue
        ]);
    }
}
 No newline at end of file
+18
Changes for module/Formation/src/Formation/Form/Formation/FormationForm.php: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Formation\Form\Formation;

use Application\Service\Etablissement\EtablissementServiceAwareTrait;
use Application\Service\Structure\StructureServiceAwareTrait;
use Formation\Service\Module\ModuleServiceAwareTrait;
use UnicaenApp\Form\Element\SearchAndSelect;
use Zend\Form\Element\Button;
use Zend\Form\Element\Number;
@@ -16,6 +17,7 @@ use Zend\InputFilter\Factory;
class FormationForm extends Form {
    use EtablissementServiceAwareTrait;
    use StructureServiceAwareTrait;
    use ModuleServiceAwareTrait;

    /** @var string */
    private $urlResponsable;
@@ -57,6 +59,21 @@ class FormationForm extends Form {
                'class' => 'tinymce',
            ],
        ]);
        //site
        $this->add([
            'type' => Select::class,
            'name' => 'module',
            'options' => [
                'label' => "Module associé à la formation :",
                'empty_option' => "Aucun module",
                'value_options' => $this->getModuleService()->getModulesAsOptions(),
            ],
            'attributes' => [
                'id' => 'structure',
                'class' => 'show-tick',
                'data-live-search' => 'true',
            ],
        ]);

        //site
        $this->add([
@@ -171,6 +188,7 @@ class FormationForm extends Form {
        $this->setInputFilter((new Factory())->createInputFilter([
            'libelle'       => [ 'required' => true, ],
            'description'   => [ 'required' => false, ],
            'module'        => [ 'required' => false, ],
            'site'          => [ 'required' => false, ],
            'responsable'   => [ 'required' => false, ],
            'modalite'      => [ 'required' => false, ],
+8 −2
Changes for module/Formation/src/Formation/Form/Formation/FormationFormFactory.php: 8 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Formation\Form\Formation;

use Application\Service\Etablissement\EtablissementService;
use Application\Service\Structure\StructureService;
use Formation\Service\Module\ModuleService;
use Interop\Container\ContainerInterface;
use Zend\View\Helper\Url;

@@ -15,9 +16,13 @@ class FormationFormFactory {
     */
    public function __invoke(ContainerInterface $container) : FormationForm
    {
        /** @var EtablissementService $etablissementService */
        /** @var StructureService $structureService */
        /**
         * @var EtablissementService $etablissementService
         * @var ModuleService $moduleService
         * @var StructureService $structureService
        **/
        $etablissementService = $container->get(EtablissementService::class);
        $moduleService = $container->get(ModuleService::class);
        $structureService = $container->get(StructureService::class);

        /** @var FormationHydrator $hydrator */
@@ -31,6 +36,7 @@ class FormationFormFactory {
        $urlResponsable =  $urlManager->__invoke('utilisateur/rechercher-individu', [], [], true);
        $form->setUrlResponsable($urlResponsable);
        $form->setEtablissementService($etablissementService);
        $form->setModuleService($moduleService);
        $form->setStructureService($structureService);
        $form->setHydrator($hydrator);
        return $form;
+7
Changes for module/Formation/src/Formation/Form/Formation/FormationHydrator.php: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,11 +9,14 @@ use Application\Service\Etablissement\EtablissementServiceAwareTrait;
use Application\Service\Individu\IndividuServiceAwareTrait;
use Application\Service\Structure\StructureServiceAwareTrait;
use Formation\Entity\Db\Formation;
use Formation\Entity\Db\Module;
use Formation\Service\Module\ModuleServiceAwareTrait;
use Zend\Hydrator\HydratorInterface;

class FormationHydrator implements HydratorInterface {
    use EtablissementServiceAwareTrait;
    use IndividuServiceAwareTrait;
    use ModuleServiceAwareTrait;
    use StructureServiceAwareTrait;

    /**
@@ -25,6 +28,7 @@ class FormationHydrator implements HydratorInterface {
        $data = [
            'libelle' => $object->getLibelle(),
            'description' => $object->getDescription(),
            'module' => ($object->getModule())?$object->getModule()->getId():null,
            'site' => ($object->getSite())?$object->getSite()->getId():null,
            'responsable' => ($object->getResponsable())?['id' => $object->getResponsable()->getId(), 'label' => $object->getResponsable()->getNomComplet()]:null,
            'modalite' => $object->getModalite(),
@@ -45,6 +49,8 @@ class FormationHydrator implements HydratorInterface {
    {
        $libelle = (isset($data['libelle']) AND trim($data['libelle']) !== '')?trim($data['libelle']):null;
        $description = (isset($data['description']) AND trim($data['description']) !== '')?trim($data['description']):null;
        /** @var Module|null $module */
        $module = (isset($data['module']) AND trim($data['module']) !== '')?$this->getModuleService()->getRepository()->find($data['module']):null;
        /** @var Etablissement|null $site */
        $site = (isset($data['site']))?$this->getEtablissementService()->getRepository()->find($data['site']):null;
        /** @var Individu|null $responsable */
@@ -58,6 +64,7 @@ class FormationHydrator implements HydratorInterface {

        $object->setLibelle($libelle);
        $object->setDescription($description);
        $object->setModule($module);
        $object->setSite($site);
        $object->setResponsable($responsable);
        $object->setModalite($modalite);
Loading