Commit c0b3c7eb authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

- Suppression des injections de service dans le processus redonduction,...

- Suppression des injections de service dans le processus redonduction, utilisation des traits à la place
- Création d'un service offre de formation pour déporter la logique métier du controller offre de formation
- Ajout d'un filtre pour récupérer que l'offre complémentaire
- Ajout d'un filtre sur le role pour n'afficher que les structures concernées par l'utilisateur.
- Réglage JS pour l'UX
- Suppression méthode clone au profit d'une duplication d'entité plus simple (a finaliser)
parent c21e5ef0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ ENV APACHE_CONF_DIR=/etc/apache2 \
    APPLICATION_ENV=dev

## Installation de packages requis.
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install -y unoconv

# Nettoyage
+47 −50
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ use Application\Service\Traits\ElementPedagogiqueServiceAwareTrait;
use Application\Service\Traits\EtapeServiceAwareTrait;
use Application\Service\Traits\LocalContextServiceAwareTrait;
use Application\Service\Traits\NiveauEtapeServiceAwareTrait;
use Application\Service\Traits\OffreFormationServiceAwareTrait;
use Application\Service\Traits\StructureServiceAwareTrait;
use UnicaenApp\View\Model\CsvModel;
use Zend\Session\Container;
@@ -35,6 +36,7 @@ class OffreFormationController extends AbstractController
    use NiveauEtapeServiceAwareTrait;
    use AnneeServiceAwareTrait;
    use ReconductionProcessusAwareTrait;
    use OffreFormationServiceAwareTrait;

    /**
     * @var Container
@@ -43,8 +45,6 @@ class OffreFormationController extends AbstractController





    public function indexAction()
    {
        $this->initFilters();
@@ -67,7 +67,6 @@ class OffreFormationController extends AbstractController
        if ($etape) $params['etape'] = $etape->getId();



        // élément pédagogique sélectionné dans le champ de recherche
        if (($element = $this->params()->fromPost('element')) && isset($element['id'])) {
            $form->get('element')->setValue($element);
@@ -130,7 +129,7 @@ class OffreFormationController extends AbstractController
                $element->getPeriode(),
                $element->getTauxFoad(),
                $element->getTauxFi(),
                $element->getTauxFa(),
                $elemendockt->getTauxFa(),
                $element->getTauxFc(),
                $effectifs ? $effectifs->getFi() : null,
                $effectifs ? $effectifs->getFa() : null,
@@ -142,13 +141,15 @@ class OffreFormationController extends AbstractController
        return $csvModel;
    }



    public function reconductionAction()
    {

        $this->initFilterHistorique();
        list($structure, $niveau, $etape) = $this->getParams();

        $structures = $this->getServiceStructure()->getList($this->getServiceStructure()->finderByEnseignement());
        //Get role of user
        $role         = $this->getServiceContext()->getSelectedIdentityRole();
        $structures   = $this->getServiceStructure()->getList($this->getServiceStructure()->finderByRole($role));
        $anneeEnCours = $this->getServiceContext()->getAnnee();
        list($offresComplementaires, $mappingEtape, $reconductionTotale) = $this->getOffreComplementaire();

@@ -167,20 +168,16 @@ class OffreFormationController extends AbstractController
            $datas['mappingEtape'] = $mappingEtape;
            $reconductionProcessus = $this->getProcessusReconduction();
            try {
                if($reconductionProcessus->reconduction($datas))
                {
                    $this->flashMessenger()->addSuccessMessage("Les éléments ont bien été reconduit pour l'année universitaire prochaine.");
                }
                else{
                    $this->flashMessenger()->addErrorMessage("Les éléments n'ont pas pu être reconduit. Merci de contacter le support.");
                }

                if ($reconductionProcessus->reconduction($datas)) {
                    $this->flashMessenger()->addSuccessMessage("Les éléments ont bien été reconduits pour l'année universitaire prochaine.");
                } else {
                    $this->flashMessenger()->addErrorMessage("Les éléments n'ont pas pu être reconduits. Merci de contacter le support.");
                }
            catch(\Exception $e){
            } catch (\Exception $e) {
                $reconductionStep = false;
                $messageStep      = $e->getMessage();
                echo $e->getMessage();
            }

        }


@@ -198,11 +195,8 @@ class OffreFormationController extends AbstractController
            'structures'            => $structures,
            'anneeEnCours'          => $anneeEnCours,
            'reconductionStep'      => $reconductionStep,
            'messageStep'           => $messageStep
            'messageStep'           => $messageStep,
        ];



    }


@@ -211,9 +205,10 @@ class OffreFormationController extends AbstractController
    {
        $this->initFilterAnnee();
        $this->initFilterHistorique();

    }



    protected function initFilterAnnee()
    {
        $this->em()->getFilters()->enable('annee')->init([
@@ -222,6 +217,8 @@ class OffreFormationController extends AbstractController
        ]);
    }



    protected function initFilterHistorique()
    {
        /* Mise en place des filtres */
@@ -234,6 +231,7 @@ class OffreFormationController extends AbstractController
    }



    protected function disableFilters($name)
    {
        $this->em()->getFilters()->disable($name);
@@ -247,6 +245,7 @@ class OffreFormationController extends AbstractController
        $niveau    = $this->context()->niveauFromQuery();
        $etape     = $this->context()->etapeFromQuery();
        if ($niveau) $niveau = $this->getServiceNiveauEtape()->get($niveau); // entité Niveau

        return [$structure, $niveau, $etape];
    }

@@ -254,8 +253,8 @@ class OffreFormationController extends AbstractController

    protected function getNeep($structure, $niveau, $etape, $annee = null)
    {
        if(is_null($annee))
        {

        if (is_null($annee)) {
            $annee = $this->getServiceContext()->getAnnee();
        }

@@ -323,6 +322,7 @@ class OffreFormationController extends AbstractController
    }



    /**
     * @return array
     */
@@ -343,9 +343,10 @@ class OffreFormationController extends AbstractController


        //Offre année en cours
        list($niveaux, $etapes, $elements) = $this->getNeep($structure, $niveau, $etape, $anneeEnCours);
        list($niveaux, $etapes, $elements) = $this->getServiceOffreFormation()->getNeepComplementaire($structure, $niveau, $etape, $anneeEnCours);
        //Offre année suivante
        list($niveauxN1, $etapesN1, $elementsN1) = $this->getNeep($structure, $niveau, $etape, $anneeSuivante);
        list($niveauxN1, $etapesN1, $elementsN1) = $this->getServiceOffreFormation()->getNeepComplementaire($structure, $niveau, $etape, $anneeSuivante);

        //Organisation pour traitement dans la vue
        $codesEtapeN1          = [];
        $codesElementN1        = [];
@@ -353,35 +354,37 @@ class OffreFormationController extends AbstractController
        $elementsNonReconduits = array_diff($elements, $elementsN1);

        $reconductionTotale = 'non';
        if(empty($etapesNonReconduits) && empty($elementsNonReconduits))
        {
        if (empty($etapesNonReconduits) && empty($elementsNonReconduits)) {
            $reconductionTotale = 'oui';
        }

        foreach($elementsN1 as $v)
        {
        foreach ($elementsN1 as $v) {
            $codesElementN1[] = $v->getCode();
        }
        foreach($etapesN1 as $v)
        {
        foreach ($etapesN1 as $v) {
            $codesEtapeN1[] = $v->getCode();
        }

        foreach ($etapes as $v)
        {
        foreach ($etapes as $v) {

            /*if (!$v->isFromSourceOse()) {
                continue;
            }*/
            $offresComplementaires[$v->getId()]['reconduction_partiel'] = 'non';
            $offresComplementaires[$v->getId()]['reconduction']         = (in_array($v->getCode(), $codesEtapeN1)) ? 'oui' : 'non';
            $offresComplementaires[$v->getId()]['etape']                = $v;
            $offresComplementaires[$v->getId()]['elements_pedagogique'] = [];
        }

        foreach ($elements as $v)
        {
        foreach ($elements as $v) {

            /*if (!$v->getEtape()->isFromSourceOse()) {
                continue;
            }*/

            $etapeId = $v->getEtape()->getId();

            if(!in_array($v->getCode(), $codesElementN1))
            {
            if (!in_array($v->getCode(), $codesElementN1)) {
                $offresComplementaires[$etapeId]['reconduction_partiel'] = 'oui';
            }

@@ -391,10 +394,11 @@ class OffreFormationController extends AbstractController

        $mappingEtape = $this->createMappingEtapeNEtapeN1($etapes, $etapesN1);


        return [$offresComplementaires, $mappingEtape, $reconductionTotale];
    }



    public function createMappingEtapeNEtapeN1($etapesN, $etapesN1)
    {
        $codesEtapeN  = [];
@@ -402,28 +406,21 @@ class OffreFormationController extends AbstractController
        $mappingEtape = [];


        foreach($etapesN1 as $v)
        {
        foreach ($etapesN1 as $v) {
            $codesEtapeN1[$v->getCode()] = $v->getId();
        }

        foreach($etapesN as $v)
        {
        foreach ($etapesN as $v) {
            $codesEtapeN[$v->getCode()] = $v->getId();
        }

        foreach($codesEtapeN as $k => $v)
        {
            if(array_key_exists($k, $codesEtapeN1))
            {
        foreach ($codesEtapeN as $k => $v) {
            if (array_key_exists($k, $codesEtapeN1)) {
                $mappingEtape[$v] = $codesEtapeN1[$k];
            }
        }

        return $mappingEtape;



    }

}
+49 −44
Original line number Diff line number Diff line
@@ -2,13 +2,17 @@

namespace Application\Processus;

use Application\Entity\Db\VolumeHoraire;
use Application\Entity\Db\VolumeHoraireEns;
use Application\Service\AnneeService;
use Application\Service\CheminPedagogiqueService;
use Application\Service\ContextService;
use Application\Service\ElementPedagogiqueService;
use Application\Service\EtapeService;
use Application\Service\Traits\AnneeServiceAwareTrait;
use Application\Service\Traits\CheminPedagogiqueServiceAwareTrait;
use Application\Service\Traits\ContextServiceAwareTrait;
use Application\Service\Traits\ElementPedagogiqueServiceAwareTrait;
use Application\Service\Traits\EtapeServiceAwareTrait;
use Application\Service\Traits\VolumeHoraireServiceAwareTrait;
use Application\Service\VolumeHoraireEnsService;
use Zend\Debug\Debug;
use Zend\Stdlib\Parameters;
@@ -20,99 +24,102 @@ use Zend\Stdlib\Parameters;
 */
class ReconductionProcessus extends AbstractProcessus
{

    use EtapeServiceAwareTrait;
    use ElementPedagogiqueServiceAwareTrait;
    use CheminPedagogiqueServiceAwareTrait;
    use VolumeHoraireServiceAwareTrait;
    use AnneeServiceAwareTrait;
    use ContextServiceAwareTrait;

    protected $etapeService;

    protected $elementPedagogiqueService;

    protected $cheminPedagogiqueService;

    protected $volumeHoraireEnsService;

    protected $anneeService;

    protected $contextService;


    public function __construct(EtapeService $etapeService,
                                ElementPedagogiqueService $elementPedagogiqueService,
                                CheminPedagogiqueService $cheminPedagogiqueService,
                                VolumeHoraireEnsService $volumeHoraireEnsService,
                                AnneeService $anneeService,
                                ContextService $contextService)

    public function __construct()
    {
        $this->etapeService = $etapeService;
        $this->elementPedagogiqueService = $elementPedagogiqueService;
        $this->cheminPedagogiqueService = $cheminPedagogiqueService;
        $this->volumeHoraireEnsService = $volumeHoraireEnsService;
        $this->anneeService = $anneeService;
        $this->contextService = $contextService;
        $this->etapeService              = $this->getServiceEtape();
        $this->elementPedagogiqueService = $this->getServiceElementPedagogique();
        $this->cheminPedagogiqueService  = $this->getServiceCheminPedagogique();
        $this->volumeHoraireEnsService   = $this->getServiceVolumeHoraire();
        $this->anneeService              = $this->getServiceAnnee();
        $this->contextService            = $this->getServiceContext();
    }



    public function reconduction(Parameters $datas)
    {
        if(empty($datas['element']) && empty($datas['etape']))
        {
        if (empty($datas['element']) && empty($datas['etape'])) {
            Throw new \Exception('Aucune donnée à reconduire');
        }

        if(empty($datas['etape']))
        {
        if (empty($datas['etape'])) {
            $datas['etape'] = [];
        }
        $etapeOfElements = array_keys($datas['element']);
        $etapeManquante  = array_diff($etapeOfElements, $datas['etape']);
        $etapes          = array_merge($datas['etape'], $etapeManquante);

        if(!empty($etapes))
        {
        if (!empty($etapes)) {
            $anneeEnCours = $this->contextService->getAnnee();
            $em           = $this->getEntityManager();
            $dateDuJour   = new \DateTime();
            $dateDuJour->format('d/m/Y');
            foreach($etapes as $idEtape)
            {
                if(in_array($idEtape, $etapeManquante))
                {
                    if(!array_key_exists($idEtape, $datas['mappingEtape']))
                    {
            foreach ($etapes as $idEtape) {
                if (in_array($idEtape, $etapeManquante)) {
                    if (!array_key_exists($idEtape, $datas['mappingEtape'])) {
                        Throw new \Exception('Impossible de reconduire les éléments sélectionné');
                    }
                    $idEtapeN1      = $datas['mappingEtape'][$idEtape];
                    $etapeReconduit = $this->etapeService->get($idEtapeN1);
                }
                else{
                } else {

                    $etapeEnCours   = $this->etapeService->get($idEtape);
                    $etapeReconduit= clone $etapeEnCours;
                    $etapeReconduit = $this->getServiceEtape()->newEntity();
                    $etapeReconduit->setAnnee($this->anneeService->getSuivante($anneeEnCours));
                    $etapeReconduit->setSpecifiqueEchanges(false);
                    $etapeReconduit->setHistoCreation($dateDuJour);
                    $etapeReconduit->setLibelle($etapeEnCours->getLibelle());
                    $etapeReconduit->setCode($etapeEnCours->getCode());
                    $etapeReconduit->setTypeFormation(($etapeEnCours->getTypeFormation()));
                    $etapeReconduit->setStructure($etapeEnCours->getStructure());
                    $etapeReconduit->setDomaineFonctionnel($etapeEnCours->getDomaineFonctionnel());
                    $etapeReconduit->setSourceCode($etapeEnCours->getSourceCode());

                    $em->persist($etapeReconduit);
                }
                //Reconduction des éléments pédagogiques pour cette étape
                if(array_key_exists($idEtape, $datas['element']))
                {
                    foreach($datas['element'][$idEtape] as $idElement)
                    {
                if (array_key_exists($idEtape, $datas['element'])) {
                    foreach ($datas['element'][$idEtape] as $idElement) {
                        $elementEnCours   = $this->elementPedagogiqueService->get($idElement);
                        $elementReconduit = clone $elementEnCours;
                        $elementReconduit->setAnnee($this->anneeService->getSuivante($anneeEnCours));
                        $elementReconduit->setEtape($etapeReconduit);
                        $elementReconduit->setHistoCreation($dateDuJour);
                        //ajout de l'élément à l'étape
                        $etapeReconduit->addElementPedagogique($elementReconduit);
                        $em->persist($elementReconduit);
                        //Reconduction des chemins pédagogiques
                        $cheminsPedagogique = $elementEnCours->getCheminPedagogique();
                        foreach($cheminsPedagogique as $chemin)
                        {
                        foreach ($cheminsPedagogique as $chemin) {
                            $cheminReconduit = clone $chemin;
                            $cheminReconduit->setElementPedagogique($elementReconduit);
                            $cheminReconduit->setEtape($etapeReconduit);
                            $cheminReconduit->setHistoCreation($dateDuJour);
                            $em->persist($cheminReconduit);
                        }
                        //Reconduction des volumes horaires
                        $volumesHoraire = $elementEnCours->getVolumeHoraireEns();
                        foreach($volumesHoraire as $volume)
                        {
                        foreach ($volumesHoraire as $volume) {
                            $volumeReconduit = clone $volume;
                            $volumeReconduit->setHistoCreation($dateDuJour);
                            $volumeReconduit->setElementPedagogique($elementReconduit);
                            $elementReconduit->addVolumeHoraireEns($volumeReconduit);
                            $em->persist($volumeReconduit);
@@ -123,10 +130,8 @@ class ReconductionProcessus extends AbstractProcessus

                $em->flush();
                unset($etapeEnCours, $etapeReconduit);

            }
            }
        else{
        } else {
            Throw new \Exception('Aucune donnée à reconduire');
        }

+118 −0
Original line number Diff line number Diff line
<?php

namespace Application\Service;


use Application\Entity\Db\ElementPedagogique;
use Application\Entity\Db\Etape;
use Application\Entity\NiveauEtape;
use Application\Service\Traits\ContextServiceAwareTrait;
use Application\Service\Traits\SourceServiceAwareTrait;

/**
 * Description of OffreFormationService
 *
 *
 */
class OffreFormationService extends AbstractEntityService
{
    use ContextServiceAwareTrait;
    use SourceServiceAwareTrait;



    public function getEntityClass()
    {
    }



    public function getAlias()
    {
    }



    public function getNeepComplementaire($structure, $niveau, $etape, $annee = null)
    {

        if (is_null($annee)) {
            $annee = $this->getServiceContext()->getAnnee();
        }


        //Source OSE
        $source = $this->getServiceSource()->get('1');


        if (!$structure) return [[], [], []];

        $niveaux  = [];
        $etapes   = [];
        $elements = [];

        $query = $this->em()->createQuery('SELECT
                partial e.{id,code,annee,libelle,sourceCode,niveau,histoDestruction},
                partial tf.{id},
                partial gtf.{id, libelleCourt, ordre},
                partial ep.{id,code,libelle,sourceCode,etape,periode,tauxFoad,fi,fc,fa,tauxFi,tauxFc,tauxFa}
            FROM
              Application\Entity\Db\Etape e
              JOIN e.structure s
              JOIN e.typeFormation tf
              JOIN tf.groupe gtf
              LEFT JOIN e.elementPedagogique ep
            WHERE
              (s = :structure OR ep.structure = :structure) AND e.annee = :annee AND e.source = :source
            ORDER BY
              gtf.ordre, e.niveau
            ');
        $query->setParameter('structure', $structure);
        $query->setParameter('annee', $annee);
        $query->setParameter('source', $source);
        $result = $query->getResult();

        foreach ($result as $object) {
            if ($object instanceof Etape) {
                $n = NiveauEtape::getInstanceFromEtape($object);
                if ($object->estNonHistorise()) {
                    $niveaux[$n->getId()] = $n;
                }
                if (!$niveau || $niveau->getId() == $n->getId()) {
                    if ($object->estNonHistorise() || $object->getElementPedagogique()->count() > 0) {
                        $etapes[] = $object;
                    }
                    if (!$etape || $etape === $object) {
                        foreach ($object->getElementPedagogique() as $ep) {
                            $elements[$ep->getId()] = $ep;
                        }
                    }
                }
            }
        }

        /* Tris */
        uasort($etapes, function (Etape $e1, Etape $e2) {
            $e1Lib = ($e1->getElementPedagogique()->isEmpty() ? 'a_' : 'z_') . strtolower(trim($e1->getLibelle()));
            $e2Lib = ($e2->getElementPedagogique()->isEmpty() ? 'a_' : 'z_') . strtolower(trim($e2->getLibelle()));

            return $e1Lib > $e2Lib;
        });

        uasort($elements, function (ElementPedagogique $e1, ElementPedagogique $e2) {
            $e1Lib = strtolower(trim($e1->getEtape()->getLibelle() . ' ' . $e1->getLibelle()));
            $e2Lib = strtolower(trim($e2->getEtape()->getLibelle() . ' ' . $e2->getLibelle()));

            return $e1Lib > $e2Lib;
        });

        return [$niveaux, $etapes, $elements];
    }



    protected function em()
    {
        return \Application::$container->get(\Application\Constants::BDD);
    }
}
 No newline at end of file
+43 −0
Original line number Diff line number Diff line
<?php

namespace Application\Service\Traits;


use Application\Service\OffreFormationService;

trait OffreFormationServiceAwareTrait
{
    /**
     * @var OffreFormationService
     */
    private $serviceOffreFormation;



    /**
     * @param ServiceOffreFormation $offreFormation
     *
     * @return self
     */
    public function setServiceOffreFormation(OffreFormationService $serviceOffreFormation)
    {
        $this->serviceOffreFormation = $serviceOffreFormation;

        return $this;
    }



    /**
     * @return OffreFormationService
     */
    public function getServiceOffreFormation()
    {
        if (empty($this->serviceOffreFormation)) {
            $this->serviceOffreFormation = \Application::$container->get(OffreFormationService::class);
        }

        return $this->serviceOffreFormation;
    }

}
 No newline at end of file
Loading