Commit 392df1c1 authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Amélioration vue. Début du clonage des entitées Etapes et Element_pedagogique

parent 3f3088be
Loading
Loading
Loading
Loading
+58 −3
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Application\Controller;
use Application\Entity\Db\ElementPedagogique;
use Application\Entity\Db\Etape;
use Application\Entity\Db\GroupeTypeFormation;
use Application\Entity\Db\Traits\CheminPedagogiqueAwareTrait;
use Application\Entity\Db\TypeFormation;
use Application\Entity\Db\TypeModulateur;
use Application\Entity\NiveauEtape;
@@ -232,10 +233,59 @@ class OffreFormationController extends AbstractController

    public function reconductionAction()
    {


        $structures = $this->getServiceStructure()->getList($this->getServiceStructure()->finderByEnseignement());
        $anneeEnCours = $this->getServiceContext()->getAnnee();
        $anneeSuivante = $this->getServiceContext()->getAnneeSuivante();
        $this->getServiceMiseEnPaiementIntervenantStructure()
        /*$serviceAnnee = $this->getServiceAnnee();
        $selectedAnnee = $this->getServiceAnnee()->get('2020');
        Debug::dump($selectedAnnee);*/


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

        //Reconduction oc selectionnée
        $request = $this->getRequest();
        if ($request->isPost()) {
            $datas = $request->getPost();
            //Duplicate formation
            //TODO : faire un service pour déporter le code du controlleur
            if(!empty($datas['etape']))
            {
                foreach($datas['etape'] as $v)
                {
                    $etapeEnCours = $this->getServiceEtape()->get($v);
                    $reconductionEtape = clone $etapeEnCours;
                    $reconductionEtape->setAnnee($anneeSuivante);
                    $reconductionEtape->setSourceCode(md5(microtime()));
                    // $this->em()->persist($reconductionEtape);
                    //$this->em()->flush();
                    unset($etapeEnCours, $reconductionEtape);

                }
            }

            //duplicate element pédagogique
            if(!empty($datas['element']))
            {
                foreach($datas['element'] as $v)
                {
                    $elementEnCours = $this->getServiceElementPedagogique()->get($v);
                    $reconductionElement = clone $elementEnCours;
                    $reconductionElement->setAnnee($anneeSuivante);
                    $reconductionElement->setSourceCode(md5(microtime()));
                    //$this->em()->persist($reconductionElement);
                   // $this->em()->flush();
                    unset($etapeEnCours, $reconductionEtape);

                }
            }

        }


        $this->getServiceLocalContext()
            ->setStructure($structure)
            ->setNiveau($niveau)
@@ -247,6 +297,8 @@ class OffreFormationController extends AbstractController
        foreach ($etapes as $v)
        {
            $etapesComplementaires[$v->getId()]['etape'] = $v;
            $etapesComplementaires[$v->getId()]['elements_pedagogique'] = [];

        }
        foreach ($elements as $v)
        {
@@ -254,12 +306,15 @@ class OffreFormationController extends AbstractController
            $etapesComplementaires[$structureId]['elements_pedagogique'][] = $v;
        }



        Debug::dump($etapesComplementaires);
        //Load specific JS
        //TODO : A mettre dans un plugin générique
        $viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
        $headScript = $viewHelperManager->get('headScript');
        $headScript->appendFile('/js/reconduction-offre.js');

        return [
            'etapesComplementaires' => $etapesComplementaires,
            'anneeEnCours' => $anneeEnCours,
            'structure'  => $structure,
            'structures' => $structures,
            'niveau'     => $niveau,
+18 −0
Original line number Diff line number Diff line
@@ -154,6 +154,24 @@ class ElementPedagogique implements HistoriqueAwareInterface, AnneeAwareInterfac
        return $this->getCode() . ' - ' . $this->getLibelle();
    }

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


        return $this;
    }



    /**
+11 −0
Original line number Diff line number Diff line
@@ -31,6 +31,17 @@ class Etape implements HistoriqueAwareInterface, AnneeAwareInterface, ResourceIn
        return $this->getLibelle();
    }

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

        return $this;
    }



    /**
+2 −0
Original line number Diff line number Diff line
@@ -201,6 +201,8 @@ class EtapeService extends AbstractEntityService





    /**
     * Retourne une nouvelle entité, initialisée avec les bons paramètres
     *
+25 −52
Original line number Diff line number Diff line
@@ -54,29 +54,38 @@
</div>
<div class="row" style="margin:0 5px 0 5px;">
    <div class="col-11">
        <!---------------- Tableau des éléments pédagogiques --------------->
        <table class="table table-bordered table-condensed table-hover table-sort">
        <h3>Offre de formation complémantaire / Année scolaire :  <?php echo $anneeEnCours->getLibelle(); ?></h3>
        <br/>
        <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">

            <?php foreach ($etapesComplementaires as $ec): ?>
                <table class="reconduction-offre table table-bordered table-condensed table-hover">
                    <thead>
                        <tr>
                <th colspan="3">Formation</th>
                <th colspan="5">Enseignement</th>
                            <th><input type="checkbox" name="etape[]" value="<?= $ec['etape']->getId(); ?>"/></th>
                            <th colspan="6">Formation : <?= $ec['etape']->__toString() . ' (' . $ec['etape']->getAnnee()->getLibelle() . ') -- id / ' . $ec['etape']->getId() . ' / code / ' . $ec['etape']->getCode(); ?></th>
                        </tr>
                        <tr>
                <th><input type="checkbox"/></th>
                <th>Niveau</th>
                <th>Libellé</th>
                <th>Code</th>
                            <th colspan="2">Code</th>
                            <th>Libellé</th>
                            <th>Période</th>
                            <th title="Formation ouverte à distance">FOAD</th>
                            <th title="Régime d'inscription">Rég. d'insc.</th>
                        </tr>
                    </thead>
            <?php foreach ($elements as $ep): /* @var $ep \Application\Entity\Db\ElementPedagogique */ ?>
                    <tbody>
                    <?php
                    if(empty($ec['elements_pedagogique']))
                    {
                    ?>
                    <tr>
                        <td colspan="7" style="text-align: center;">Aucun élément pédagogique</td>
                    </tr>
                    <?php } ?>

                        <?php foreach ($ec['elements_pedagogique'] as $ep): ?>
                            <tr id="<?= $ep->getId() ?>">
                    <td><input type="checkbox"/></td>
                    <td><?= $ep->getEtape()->getNiveauToString() ?></td>
                    <td class="etape"><?= $this->etape($ep->getEtape())->renderLink() ?></td>
                                <td><input class="checkbox-element" type="checkbox" name="element[<?php echo $ec['etape']->getId();?>][]" value="<?= $ep->getId(); ?>"/></td>
                                <td class="element"><?= $ep->getCode() ?></td>
                                <td class="element"><?= $this->elementPedagogique($ep)->renderLink($ep->getLibelle()) ?></td>
                                <td class="periode"><?= $ep->getPeriode() ?: "" ?></td>
@@ -84,53 +93,17 @@
                                <td><?= $ep->getRegimesInscription(true) ?></td>
                            </tr>
                        <?php endforeach; ?>
            <tbody>
                    </tbody>
                </table>

        <?php foreach ($etapesComplementaires as $ec): ?>
            <table class="table table-bordered table-condensed table-hover table-sort">
                <thead>
                <tr>
                    <th colspan="3">Formation : <?= $ec['etape']->__toString();?></th>
                    <th colspan="5">Enseignement</th>
                </tr>
                <tr>
                    <th><input type="checkbox"/></th>
                    <th>Niveau</th>
                    <th>Libellé</th>
                    <th>Code</th>
                    <th>Libellé</th>
                    <th>Période</th>
                    <th title="Formation ouverte à distance">FOAD</th>
                    <th title="Régime d'inscription">Rég. d'insc.</th>
                </tr>
                </thead>
            </table>

            <?php endforeach; ?>
            <input class="btn btn-primary" type="submit" value="Reconduire l'offre séléctionnée" name="submit"/>
        </form>

    </div>
</div>

<script>
    $("document").ready(function()
    {
        $("body").on("change", "#reconduction-filters select", function(event)
        {
            $("*").css('cursor', 'wait');
            var structure = $('select.structure').val();
            var niveau = $('select.niveau').val();
            var etape = $('select.etape').val();
            var query = '';
            if(structure){ query += 'structure='+structure+'&';}
            if(niveau){ query += 'niveau='+niveau+'&';}
            if(etape){query += 'etape='+etape+'&';}
            var url = '<?= $this->url('of/reconduction'); ?>';
            url += '?' + query;
            $(location).attr('href', url);
        });
<script type="text/javascript">

    });

</script>