Commit 965f84a1 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Nettoyage du code des substitutions WIP

parent 37afd97c
Loading
Loading
Loading
Loading
+19 −33
Changes for module/Application/src/Application/Controller/SubstitutionController.php: 19 added lines, 33 removed lines.
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ class SubstitutionController extends AbstractController
        ]);
    }

    /** Créer une substitution manuelle */
    public function creerAction() {
        $type = $this->params()->fromRoute('type');
        $structures = $this->getStructureService()->getStructuresSubstituablesByType($type);
@@ -60,6 +61,7 @@ class SubstitutionController extends AbstractController
                return $this->redirect()->toRoute(null, [],[], true);
            }

            // récupération des structures sources
            $sources = [];
            foreach($data['sourceIds'] as $sourceId) {
                $structureConcrete = $this->getStructureService()->getStructuresConcreteByTypeAndStructureId($type, $sourceId);
@@ -69,20 +71,13 @@ class SubstitutionController extends AbstractController
            //creation de la structureCible adequate
            $structureCibleDataObject = $this->getStructureService()->createStructureConcrete($type);
            $this->structureService->updateFromPostData($structureCibleDataObject, $data['cible']);

            $structureCible = $this->structureService->createStructureSubstitutions($sources, $structureCibleDataObject);
            $id = $structureCible->getStructure()->getId();

            $message  = "La substitution <strong>".$structureCible->getLibelle()."</strong> vient d'être créée. Elle regroupe les structures : ";
            $first = true;
            foreach($sources as $source) {
                if (!$first) $message .= ", ";
                $message .= "<i>".$source->getLibelle()."</i>";
                $first = false;
            }
            $message .= implode(", ", array_map(function(StructureConcreteInterface $s) { return "<i>".$s->getLibelle()."</i>";}, $sources));
            $this->flashMessenger()->addSuccessMessage($message);

            return $this->redirect()->toRoute('substitution-modifier', ['cible' => $id], [], true);
            return $this->redirect()->toRoute('substitution-modifier', ['cible' => $structureCible->getStructure()->getId()], [], true);

        } else {
            $cible = new Structure();
@@ -90,7 +85,7 @@ class SubstitutionController extends AbstractController
        }

        $vm = new ViewModel([
            'title' => "Création d'une substitution (".$type.")",
//            'title' => "Création d'une substitution (".$type.")",
            'cible' => $cible,
            'structuresConcretesSubstituees' => $structuresConcretesSubstituees,
            'structuresConcretes' => $structures,
@@ -101,10 +96,13 @@ class SubstitutionController extends AbstractController
        return $vm;
    }

    /** Éditer une substitution manuelle */
    public function modifierAction()
    {
        $idCible = $this->params()->fromRoute('cible');
        $structureCible = $this->getStructureService()->findStructureSubsitutionCibleById($idCible);
        $type=$structureCible->getTypeStructure();

        $structuresSubstituees = $structureCible->getStructuresSubstituees();

        $structuresConcretesSubstituees = [];
@@ -113,45 +111,39 @@ class SubstitutionController extends AbstractController
            $structuresConcretesSubstituees[] = $structureConcreteSubstituee;
        }

        $type=$structureCible->getTypeStructure();
        $structures = $this->getStructureService()->getStructuresSubstituablesByType($type);

        $request = $this->getRequest();
        if ($request->isPost()) {
            $data = $request->getPost();

            // récupération des structures sources
            $sources = [];
            foreach ($data['sourceIds'] as $sourceId) {
                $structureConcrete = $this->getStructureService()->getStructuresConcreteByTypeAndStructureId($type, $sourceId);
                if ($structureConcrete === null) {
                    throw new RuntimeException("Aucune structure concrète cible trouvée avec id=$sourceId.");
                }
                $sources[] = $structureConcrete;
            }

            //mise à jour de la structureCible adequate
            $this->structureService->updateFromPostData($structureCible,$data['cible']);
            $this->structureService->updateStructureSubstitutions($sources, $structureCible);

            $message = "La substitution <strong>".$structureCible->getLibelle()."</strong> vient d'être mise à jour. Elle regroupe les structures : ";
            $first = true;
            foreach($sources as $source) {
                if (!$first) $message .= ", ";
                $message .= "<i>".$source->getLibelle()."</i>";
                $first = false;
            }
            $message .= implode(", ", array_map(function(StructureConcreteInterface $s) { return "<i>".$s->getLibelle()."</i>";}, $sources));
            $this->flashMessenger()->addSuccessMessage($message);

            return $this->redirect()->toRoute(null, [],[], true);
        }



        return new ViewModel([
            'title' => "Modification d'une substitution",
//            'title' => "Modification d'une substitution (".$type.")",
            'cible' => $structureCible,
            'structuresConcretes' => $structures,
            'structuresConcretesSubstituees' => $structuresConcretesSubstituees,
        ]);
    }

    //TODO verifier le comportement
    public function detruireAction() {
        $idCible = $this->params()->fromRoute('cible');
        $structure = $this->structureService->findStructureById($idCible);
@@ -161,6 +153,7 @@ class SubstitutionController extends AbstractController
        return $this->redirect()->toRoute('substitution-index', [],[], true);
    }

    /** Fonction appelée pour construire la div associée à une structure source */
    public function generateSourceInputAction() {
        $id = $this->params()->fromRoute('id');
        $structure = $this->structureService->findStructureById($id);
@@ -171,6 +164,7 @@ class SubstitutionController extends AbstractController
        ]);
    }

    /** Fonction principale des substitutions (appelle checkStructure) */
    public function substitutionAutomatiqueAction()
    {
        $substitutionsEcolesDoctorales  = $this->checkStructure(TypeStructure::CODE_ECOLE_DOCTORALE);
@@ -184,7 +178,8 @@ class SubstitutionController extends AbstractController
        ]);
    }


    // TODO mettre dans le service ...
    /** Identifie les structures substituables en utilisant le sourceCode */
    public function checkStructure($type)
    {
        $structures = [];
@@ -206,15 +201,6 @@ class SubstitutionController extends AbstractController
            $dictionnaire[$identifiant][] = $structure;
        }

//        /** @var StructureConcreteInterface $structure */
//        $tmpres = [];
//        foreach ($dictionnaire as $key => $structures) {
//            foreach ($structures as $structure) {
//                $tmpres[$key][] = $structure->getId() . " " . $structure->getSourceCode();
//            }
//        }
//        var_dump($tmpres);

        $substitutions = [];
        foreach ($dictionnaire as $identifiant => $structures) {
            if (count($structures) >= 2) {
+56 −51
Changes for module/Application/src/Application/View/Helper/StructureSubstitHelper.php: 56 added lines, 51 removed lines.
Original line number Diff line number Diff line
@@ -12,59 +12,55 @@ class StructureSubstitHelper extends AbstractHelper {
    public function render()     {    }

    /**
     * @param StructureConcreteInterface $structure
     * @param StructureConcreteInterface $structurestructureConcrete
     * @return string
     */
    public function structureSource(StructureConcreteInterface $structure)
    public function structureSource(StructureConcreteInterface $structurestructureConcrete)
    {
        $htexte  =   '<div class="panel-heading">';
        $htexte .=   $structure->getSource() ."/". $structure->getId() . " " . $structure->getId() ;
        $htexte .=   '</div>';

        $sygleTexte  = "<span>";
        $sygleTexte .= "     <input champ='sigle' id='sigle_".$structure->getSigle()."' type='radio' name='sigle'/> &nbsp; ";
        $sygleTexte .= "     <span class='texte'>" . $structure->getSigle() ."</span>";
        $sygleTexte .= "</span>";

        $libTexte  = "<span>";
        $libTexte .= "     <input champ='libelle' id='libelle_".$structure->getSigle()."' type='radio' name='libelle'/> &nbsp; ";
        $libTexte .= "     <span name='txt' class='texte'>" . $structure->getLibelle() . "</span>";
        $libTexte .= "</span>";


        $imgTexte  = "<div id='logo-div' class='pull-right '>";
        if ($structure->getCheminLogo() !== null) $imgTexte .= '<input champ="logo" id="logo_' . $structure->getSigle() .'" type="radio" name="logo" /> &nbsp; ';
        $imgTexte .= "      <img class='current' style='max-width: 125px; max-height: 125px; border: 1px solid black; background-color: white;' src='data:image/png;base64," . base64_encode($structure->getLogoContent()) ."'/>";
        $imgTexte .= '      <input class="path" type="hidden" champ="cheminLogo" name="cheminLogo" value="'.$structure->getStructure()->getCheminLogo().'"/>';
        $imgTexte .= "</div>";

        $buttonTexte  = "<button class='btn btn-danger supprimer'>";
        $buttonTexte .= "    <span class='glyphicon glyphicon-remove'></span>";
        $buttonTexte .= "    Retirer de la substitution";
        $buttonTexte .= "</button>";

        $texte =    "";
        $texte .=   '<div class="panel panel-warning" id="panel_'.$structure->getId().'" >';
        $texte .= $htexte;
        $texte  = '<div class="panel panel-info" id="panel_'.$structurestructureConcrete->getId().'" >';
        $texte .=   '<div class="panel-heading">';
        $texte .=       'Source : '. $structurestructureConcrete->getSource() ." - Identifiant : ". $structurestructureConcrete->getStructure()->getId() ;
        $texte .=   '</div>';

        $texte .=   '<div class="panel-body">';
        $texte .=   '       <div class="" id="structure_'.$structure->getId().'">';
        $texte .=   '           <input type="hidden" name="sourceIds[]" value="'.$structure->getStructure()->getId().'"/>';
        $texte .= $imgTexte;

        $texte .=   "<br/>";

        $texte .= $sygleTexte;
        $texte .=   "<br/>";

        $texte .= $libTexte;
        $texte .=   "<br/>";
        $texte .=       '<div class="pull-left">';
        $texte .=       '<input type="hidden" id="source" name="sourceIds[]" value="'.$structurestructureConcrete->getStructure()->getId().'" />';
        $texte .=       '<table>';
        $texte .=           '<tr>';
        $texte .=               '<td><input champ="sigle" id="sigle_'.$structurestructureConcrete->getSigle().'" type="radio" name="sigle"/> </td>';
        $texte .=               '<th> &nbsp; Sigle : &nbsp; </th>';
        $texte .=               '<td>'. $structurestructureConcrete->getSigle() .'</td>';
        $texte .=           '</tr>';
        $texte .=           '<tr>';
        $texte .=               '<td><input champ="libelle" id="sigle_'.$structurestructureConcrete->getSigle().'" type="radio" name="libelle"/> </td>';
        $texte .=               '<th> &nbsp; Libellé : &nbsp; </th>';
        $texte .=               '<td>'. $structurestructureConcrete->getLibelle() .'</td>';
        $texte .=           '</tr>';
        $texte .=           '<tr>';
        $texte .=               '<td><input champ="code" id="sigle_'.$structurestructureConcrete->getSigle().'" type="radio" name="code"/> </td>';
        $texte .=               '<th> &nbsp; Code : &nbsp; </th>';
        $texte .=               '<td>'. $structurestructureConcrete->getStructure()->getCode() .'</td>';
        $texte .=           '</tr>';
        $texte .=       '</table>';

        $texte .= '<br/>';

        $texte  .=       '<button class="btn btn-danger supprimer">';
        $texte .=           '<span class="glyphicon glyphicon-remove"></span>';
        $texte .=           'Retirer de la substitution';
        $texte .=       '</button>';
        $texte .=       '</div>';

        $texte .= $buttonTexte;
        $texte .=       '<div id="logo-div" class="pull-right ">';
        if ($structurestructureConcrete->getCheminLogo() !== null)
            $texte .=       '<input champ="logo" id="logo_' . $structurestructureConcrete->getSigle() .'" type="radio" name="logo" /> &nbsp; ';
        $texte .=           '<img class="current" style="max-width: 125px; max-height: 125px; border: 1px solid black; background-color: white;" src="data:image/png;base64,' . base64_encode($structurestructureConcrete->getLogoContent()) .'"/>';
        $texte .=           '<input class="path" type="hidden" champ="cheminLogo" name="cheminLogo" value="'.$structurestructureConcrete->getStructure()->getCheminLogo().'"/>';
        $texte .=       '</div>';
        $texte .=   '</div>';
        $texte .= '</div>';

        $texte .=   "</div>";
        $texte .=   "</div>";
        $texte .=   "</div>";
        return $texte;

    }
@@ -78,7 +74,7 @@ class StructureSubstitHelper extends AbstractHelper {
        $texte .=   '<div class="panel panel-success">';

        $texte .=   '    <div class="panel-heading">';
        $texte .= $structure->getSource() ."/". $structure->getId() . " " . $structure->getId() ;
        $texte .=   'Source : '. $structure->getSource() ." - Identifiant : ". $structure->getId() ;
        $texte .=   '    </div>';

        $texte .=   '    <div class="panel-body">';
@@ -87,13 +83,22 @@ class StructureSubstitHelper extends AbstractHelper {
        $texte .= "<img id='logo_tmp' style='max-width: 125px; max-height: 125px; border: 1px solid black; background-color: white;' src='data:image/png;base64," . base64_encode($structure->getLogoContent()) ."'/>";
        $texte .= "</div>";


        $texte .=   "<br/>";

        $texte .= "<input type='text' name='cible[sigle]' id='sigle' value='".$structure->getSigle()."'/>";
        $texte .=   "<br/>";

        $texte .= "<input type='text' name='cible[libelle]' id='libelle' value='".$structure->getLibelle()."'/>";
        $texte .= '<table>';
        $texte .= '    <tr>';
        $texte .= '        <th> Sigle  </th>';
        $texte .= '        <td><input type="text" name="cible[sigle]" id="sigle" value="'.$structure->getSigle().'"/></td>';
        $texte .= '    </tr>';
        $texte .= '    <tr>';
        $texte .= '        <th> Libellé  &nbsp; </th>';
        $texte .= '        <td><input type="text" name="cible[libelle]" id="libelle" value="'.$structure->getLibelle().'"/></td>';
        $texte .= '    </tr>';
        $texte .= '    <tr>';
        $texte .= '        <th> Code  </th>';
        $texte .= '        <td><input type="text" name="cible[code]" id="code" value="'.$structure->getCode().'"/></td>';
        $texte .= '    </tr>';
        $texte .= '</table>';

        $texte .=   "</div>";
        $texte .=   "</div>";
+5 −2
Changes for module/Application/view/application/substitution/modifier.phtml: 5 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,8 @@

namespace Application;

use Application\Entity\Db\EcoleDoctorale;use Application\Entity\Db\Structure;
use Application\Entity\Db\EcoleDoctorale;
use Application\Entity\Db\Structure;
use Application\Entity\Db\StructureConcreteInterface;
use Application\Entity\Db\TypeStructure;
use Application\Provider\Privilege\SubstitutionPrivileges;
@@ -104,7 +105,9 @@ function generateSelect($structuresConcretes, \Zend\View\Renderer\PhpRenderer $r
        //remplacement dans la structure cible
        $("div#sources").on("click", "input[type='radio']", function () {
            var type = $(this).attr('name');
            var texte = ($(this).parent().find(".texte").text());

            // var texte = ($(this).parent().find(".texte").text());
            var texte = ($(this).parent().parent().children(":last-child").text());
            if (type === 'logo') {
                texte = ($(this).parent().find(".path").val());
                var src = ($(this).parent().find(".current").attr("src"));