Commit 2da24195 authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

- Supprime toutes les méthodes _clone pour passer sur un clonage plus manuelle et moins héritant

- Déport méthode du controller formation dans le service OffreFormation
parent c0b3c7eb
Loading
Loading
Loading
Loading
+3 −179
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ use Application\Entity\Db\Etape;
use Application\Entity\Db\GroupeTypeFormation;
use Application\Entity\Db\TypeFormation;
use Application\Entity\Db\TypeModulateur;
use Application\Entity\NiveauEtape;
use Application\Processus\Traits\ReconductionProcessusAwareTrait;
use Application\Service\Traits\AnneeServiceAwareTrait;
use Application\Service\Traits\ContextServiceAwareTrait;
@@ -59,7 +58,7 @@ class OffreFormationController extends AbstractController
            ->setEtape($etape);

        $structures = $this->getServiceStructure()->getList($this->getServiceStructure()->finderByEnseignement());
        list($niveaux, $etapes, $elements) = $this->getNeep($structure, $niveau, $etape);
        list($niveaux, $etapes, $elements) = $this->getServiceOffreFormation()->getNeep($structure, $niveau, $etape);

        $params = [];
        if ($structure) $params['structure'] = $structure->getId();
@@ -93,7 +92,7 @@ class OffreFormationController extends AbstractController

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

        $elements = $this->getNeep($structure, $niveau, $etape)[2];
        $elements = $this->getServiceOffreFormation()->getNeep($structure, $niveau, $etape)[2];
        /* @var $elements ElementPedagogique[] */

        $csvModel = new CsvModel();
@@ -151,8 +150,7 @@ class OffreFormationController extends AbstractController
        $role         = $this->getServiceContext()->getSelectedIdentityRole();
        $structures   = $this->getServiceStructure()->getList($this->getServiceStructure()->finderByRole($role));
        $anneeEnCours = $this->getServiceContext()->getAnnee();
        list($offresComplementaires, $mappingEtape, $reconductionTotale) = $this->getOffreComplementaire();

        list($offresComplementaires, $mappingEtape, $reconductionTotale) = $this->getServiceOffreFormation()->getOffreComplementaire($structure, $niveau, $etape);

        $reconductionStep = '';
        $messageStep      = '';
@@ -249,178 +247,4 @@ class OffreFormationController extends AbstractController
        return [$structure, $niveau, $etape];
    }



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

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

        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
            ORDER BY
              gtf.ordre, e.niveau
            ');
        $query->setParameter('structure', $structure);
        $query->setParameter('annee', $annee);
        $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];
    }



    /**
     * @return array
     */

    public function getOffreComplementaire()
    {
        $offresComplementaires = [];
        $anneeEnCours          = $this->getServiceContext()->getAnnee();
        $anneeSuivante         = $this->getServiceAnnee()->getSuivante($anneeEnCours);

        //Récupération des paramètres GET
        list($structure, $niveau, $etape) = $this->getParams();

        $this->getServiceLocalContext()
            ->setStructure($structure)
            ->setNiveau($niveau)
            ->setEtape($etape);


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

        //Organisation pour traitement dans la vue
        $codesEtapeN1          = [];
        $codesElementN1        = [];
        $etapesNonReconduits   = array_diff($etapes, $etapesN1);
        $elementsNonReconduits = array_diff($elements, $elementsN1);

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

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

        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) {

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

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

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

            $offresComplementaires[$etapeId]['elements_pedagogique'][$v->getId()]['reconduction'] = (in_array($v->getCode(), $codesElementN1)) ? 'oui' : 'non';
            $offresComplementaires[$etapeId]['elements_pedagogique'][$v->getId()]['element']      = $v;
        }

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

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



    public function createMappingEtapeNEtapeN1($etapesN, $etapesN1)
    {
        $codesEtapeN  = [];
        $codesEtapeN1 = [];
        $mappingEtape = [];


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

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

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

        return $mappingEtape;
    }

}
+1 −13
Original line number Diff line number Diff line
<?php

namespace Application\Entity\Db;

use UnicaenApp\Entity\HistoriqueAwareInterface;
use UnicaenApp\Entity\HistoriqueAwareTrait;
use UnicaenImport\Entity\Db\Interfaces\ImportAwareInterface;
@@ -35,19 +36,6 @@ class CheminPedagogique implements HistoriqueAwareInterface, ImportAwareInterfac
    protected $etape;

    
    public function __clone()
    {
        if($this->id)
        {
            $this->id = null;
        }
        $this->etape = null;
        $this->elementPedagogique = null;

        return $this;
    }



    /**
     * Set ordre
+6 −22
Original line number Diff line number Diff line
@@ -154,25 +154,6 @@ class ElementPedagogique implements HistoriqueAwareInterface, AnneeAwareInterfac
        return $this->getCode() . ' - ' . $this->getLibelle();
    }

    public function __clone()
    {
        if($this->id)
        {
            $this->id = null;
        }
        $this->etape = null;
        $this->elementModulateur = null;
        $this->effectifs = null;
        $this->centreCoutEp = null;
        $this->volumeHoraireEns = null;
        $this->service = null;
        $this->typeHeures = null;
        $this->cheminPedagogique = null;


        return $this;
    }



    /**
@@ -398,9 +379,12 @@ class ElementPedagogique implements HistoriqueAwareInterface, AnneeAwareInterfac
    public function getTaux(TypeHeures $typeHeures)
    {
        switch ($typeHeures->getCode()) {
            case TypeHeures::FI: return $this->getTauxFi();
            case TypeHeures::FC: return $this->getTauxFc();
            case TypeHeures::FA: return $this->getTauxFa();
            case TypeHeures::FI:
                return $this->getTauxFi();
            case TypeHeures::FC:
                return $this->getTauxFc();
            case TypeHeures::FA:
                return $this->getTauxFa();
        }

        return null;
+0 −10
Original line number Diff line number Diff line
@@ -37,16 +37,6 @@ class VolumeHoraireEns implements HistoriqueAwareInterface, ImportAwareInterface
    protected $groupes;


    public function __clone()
    {
        if($this->id)
        {
            $this->id = null;
        }
        return $this;
    }



    /**
     * Get id
+30 −15
Original line number Diff line number Diff line
@@ -2,19 +2,12 @@

namespace Application\Processus;

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 Application\Service\Traits\VolumeHoraireEnsServiceAwareTrait;
use Zend\Stdlib\Parameters;

/**
@@ -28,7 +21,7 @@ class ReconductionProcessus extends AbstractProcessus
    use EtapeServiceAwareTrait;
    use ElementPedagogiqueServiceAwareTrait;
    use CheminPedagogiqueServiceAwareTrait;
    use VolumeHoraireServiceAwareTrait;
    use VolumeHoraireEnsServiceAwareTrait;
    use AnneeServiceAwareTrait;
    use ContextServiceAwareTrait;

@@ -51,7 +44,7 @@ class ReconductionProcessus extends AbstractProcessus
        $this->etapeService              = $this->getServiceEtape();
        $this->elementPedagogiqueService = $this->getServiceElementPedagogique();
        $this->cheminPedagogiqueService  = $this->getServiceCheminPedagogique();
        $this->volumeHoraireEnsService   = $this->getServiceVolumeHoraire();
        $this->volumeHoraireEnsService   = $this->getServiceVolumeHoraireEns();
        $this->anneeService              = $this->getServiceAnnee();
        $this->contextService            = $this->getServiceContext();
    }
@@ -86,9 +79,9 @@ class ReconductionProcessus extends AbstractProcessus
                } else {

                    $etapeEnCours   = $this->etapeService->get($idEtape);
                    $etapeReconduit = $this->getServiceEtape()->newEntity();
                    $etapeReconduit = $this->etapeService->newEntity();
                    $etapeReconduit->setAnnee($this->anneeService->getSuivante($anneeEnCours));
                    $etapeReconduit->setSpecifiqueEchanges(false);
                    $etapeReconduit->setSpecifiqueEchanges(0);
                    $etapeReconduit->setLibelle($etapeEnCours->getLibelle());
                    $etapeReconduit->setCode($etapeEnCours->getCode());
                    $etapeReconduit->setTypeFormation(($etapeEnCours->getTypeFormation()));
@@ -102,24 +95,46 @@ class ReconductionProcessus extends AbstractProcessus
                if (array_key_exists($idEtape, $datas['element'])) {
                    foreach ($datas['element'][$idEtape] as $idElement) {
                        $elementEnCours   = $this->elementPedagogiqueService->get($idElement);
                        $elementReconduit = clone $elementEnCours;
                        $elementReconduit = $this->elementPedagogiqueService->newEntity();
                        $elementReconduit->setAnnee($this->anneeService->getSuivante($anneeEnCours));
                        $elementReconduit->setEtape($etapeReconduit);
                        $elementReconduit->setLibelle($elementEnCours->getLibelle());
                        $elementReconduit->setSourceCode($elementEnCours->getSourceCode());
                        $elementReconduit->setCode($elementEnCours->getCode());
                        $elementReconduit->setStructure($etapeReconduit->getStructure());
                        $elementReconduit->setFa($elementEnCours->getFa());
                        $elementReconduit->setFc($elementEnCours->getFc());
                        $elementReconduit->setFi($elementEnCours->getFi());
                        $elementReconduit->setTauxFa($elementEnCours->getTauxFa());
                        $elementReconduit->setTauxFi($elementEnCours->getTauxFi());
                        $elementReconduit->setTauxFc($elementEnCours->getTauxFc());
                        $elementReconduit->setTauxFoad($elementEnCours->getTauxFoad());
                        $elementReconduit->setDiscipline($elementEnCours->getDiscipline());
                        $elementReconduit->setPeriode($elementEnCours->getPeriode());
                        //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) {
                            $cheminReconduit = clone $chemin;
                            $chemin;
                            $cheminReconduit = $this->cheminPedagogiqueService->newEntity();
                            $cheminReconduit->setElementPedagogique($elementReconduit);
                            $cheminReconduit->setEtape($etapeReconduit);
                            $cheminReconduit->setSourceCode($chemin->getSourceCode());
                            $cheminReconduit->setSource($chemin->getSource());
                            $cheminReconduit->setOrdre($chemin->getOrdre());
                            $em->persist($cheminReconduit);
                        }
                        //Reconduction des volumes horaires
                        $volumesHoraire = $elementEnCours->getVolumeHoraireEns();
                        foreach ($volumesHoraire as $volume) {
                            $volumeReconduit = clone $volume;
                            $volumeReconduit = $this->volumeHoraireEnsService->newEntity();
                            $volumeReconduit->setSource($volume->getSource());
                            $volumeReconduit->setSourceCode($volume->getSourceCode());
                            $volumeReconduit->setTypeIntervention($volume->getTypeIntervention());
                            $volumeReconduit->setGroupes($volume->getGroupes());
                            $volumeReconduit->setHeures($volume->getHeures());
                            $volumeReconduit->setElementPedagogique($elementReconduit);
                            $elementReconduit->addVolumeHoraireEns($volumeReconduit);
                            $em->persist($volumeReconduit);
Loading