From 04c64e267701ea5059b53461660b0f4d4700b6f9 Mon Sep 17 00:00:00 2001 From: tguillon <theo.guillon@libriciel.coop> Date: Mon, 27 Feb 2023 13:16:04 +0100 Subject: [PATCH] Ajout : script migration pb btn radio migration --- .../Command/UpdateLigneFormulaireShell.php | 148 ++++++++++++++++++ .../ongletShowInformationGenerale.ctp | 104 +++++++----- 2 files changed, 209 insertions(+), 43 deletions(-) create mode 100644 app/Console/Command/UpdateLigneFormulaireShell.php diff --git a/app/Console/Command/UpdateLigneFormulaireShell.php b/app/Console/Command/UpdateLigneFormulaireShell.php new file mode 100644 index 00000000..fbbe2bd8 --- /dev/null +++ b/app/Console/Command/UpdateLigneFormulaireShell.php @@ -0,0 +1,148 @@ +<?php + +/** + * Installations Shell + * + * web-DPO : Outil de gestion de vos traitements dans le cadre de la + * réglementation relative à la protection des données personnelles (RGPD) + * + * Copyright (c) Libriciel SCOP (https://www.libriciel.fr/) + * + * Licensed under the GNU Affero General Public License version 3 License - AGPL v3 + * For full copyright and license information, please see the "LICENSE" file. + * Redistributions of files must retain the above copyright notice. + * + * @copyright Copyright (c) Libriciel SCOP (https://www.libriciel.fr/) + * @link https://www.libriciel.fr/web-dpo/ + * @since web-DPO v1.0.0 + * @license [GNU Affero General Public License version 3](http://www.gnu.org/licenses/agpl-3.0.html) - AGPL v3 + * @version v2.1.0 + * @package App.Console.Command.Shell + */ + +class UpdateLigneFormulaireShell extends Shell { + + public $uses = [ + 'Formulaire', + 'Champ' + ]; + + + public function getOptionParser(): ConsoleOptionParser + { + $parser = parent::getOptionParser(); + + $parser->description([ + 'Recalcule position champ dans la meme colonne', + '', + '', + ]); + + $options = [ + 'formulaireId' => [ + 'help' => "Id du formulaire", + 'default' => null, + 'required' => true, + ], + 'colonne' => [ + 'help' => "Numéro de colonne 1 ou 2", + 'default' => 1, + 'required' => true, + ] + ]; + $parser->addOptions($options); + + return $parser; + } + + public function updateForm() + { + $formulaire_id = Hash::get($this->params, 'formulaireId'); + $colonne = Hash::get($this->params, 'colonne'); + + $success = true; + $this->Champ->begin(); + + $formChamps = $this->Champ->find('all', [ + 'conditions' => [ + 'formulaire_id' => $formulaire_id, + 'colonne' => $colonne, + 'champ_coresponsable' => false, + 'champ_soustraitant' => false, + ], + 'fields' => [ + 'id', + 'ligne', + 'type', + ], + 'order' => 'ligne' + ]); + + foreach ($formChamps as $key => $formChamp) { + if ($key === 0) { + continue; + } + + if ($formChamps[$key-1]['Champ']['type'] === 'date' || + $formChamps[$key-1]['Champ']['type'] === 'input' || + $formChamps[$key-1]['Champ']['type'] === 'texte' || + $formChamps[$key-1]['Champ']['type'] === 'title' + ) { + if ($formChamp['Champ']['ligne'] - $formChamps[$key - 1]['Champ']['ligne'] < 2) { + $formChamps[$key]['Champ']['ligne'] = $formChamps[$key - 1]['Champ']['ligne'] + 2; + } + } + + if ($formChamps[$key-1]['Champ']['type'] === 'textarea' || + $formChamps[$key-1]['Champ']['type'] === 'checkboxes' || + $formChamps[$key-1]['Champ']['type'] === 'radios' + ) { + if ($formChamp['Champ']['ligne'] - $formChamps[$key - 1]['Champ']['ligne'] < 5) { + $formChamps[$key]['Champ']['ligne'] = $formChamps[$key - 1]['Champ']['ligne'] + 5; + } + } + } + +// foreach ($formChamps as $key => $formChamp) { +// if ($key === 0) { +// continue; +// } +// +// if ($formChamp['Champ']['type'] === 'date' || +// $formChamp['Champ']['type'] === 'input' || +// $formChamp['Champ']['type'] === 'texte' +// ) { +// //ecart de 2 +// if ($formChamp['Champ']['ligne'] - $formChamps[$key - 1]['Champ']['ligne'] < 2) { +// $formChamps[$key]['Champ']['ligne'] = $formChamps[$key - 1]['Champ']['ligne'] + 2; +// +// //update caleur de results[$key -1] +// } +// continue; +// } +// +// if ($formChamp['Champ']['type'] === 'title' || +// $formChamp['Champ']['type'] === 'radios' || +// $formChamp['Champ']['type'] === 'textarea' || +// $formChamp['Champ']['type'] === 'checkboxes' +// ) { +// //ecart de 5 +// if ($formChamp['Champ']['ligne'] - $formChamps[$key - 1]['Champ']['ligne'] < 5) { +// $formChamps[$key]['Champ']['ligne'] = $formChamps[$key - 1]['Champ']['ligne'] + 5; +// } +// } +// +// } + + foreach ($formChamps as $formChamp) { + $this->Champ->create($formChamp); + $success = false !== $this->Champ->save(null, ['atomic' => false]); + } + + if ($success === true) { + $this->Champ->commit(); + } else { + $this->Champ->rollback(); + } + } +} \ No newline at end of file diff --git a/app/View/Elements/Formulaires/oldOnglets/ongletShowInformationGenerale.ctp b/app/View/Elements/Formulaires/oldOnglets/ongletShowInformationGenerale.ctp index 3b20edc1..4085c9a9 100644 --- a/app/View/Elements/Formulaires/oldOnglets/ongletShowInformationGenerale.ctp +++ b/app/View/Elements/Formulaires/oldOnglets/ongletShowInformationGenerale.ctp @@ -70,11 +70,11 @@ <!-- Information concernant le traitement --> <div class="col-md-12"> - <span class='labelFormulaire'> - <?php - echo __d('fiche', 'fiche.textInfoTraitement'); - ?> - </span> + <span class='labelFormulaire'> + <?php + echo __d('fiche', 'fiche.textInfoTraitement'); + ?> + </span> <div class="row row35"></div> </div> @@ -91,15 +91,27 @@ ], 'Fiche.transfert_hors_ue' => [ 'id' => 'transfert_hors_ue', + 'options' => [ + true => 'Oui', + false => 'Non' + ], + 'default' => false, 'required' => true, 'placeholder' => false, - 'readonly' => true + 'readonly' => true, + 'class' => 'transformSelect form-control', ], 'Fiche.donnees_sensibles' => [ 'id' => 'donnees_sensibles', + 'options' => [ + true => 'Oui', + false => 'Non' + ], + 'default' => false, 'required' => true, 'placeholder' => false, - 'readonly' => true + 'readonly' => true, + 'class' => 'transformSelect form-control', ] ]); ?> @@ -117,53 +129,59 @@ ]); ?> </div> + </div> - <!-- Co-responsabilité sur le traitement --> - <div class="col-md-12"> - <span class='labelFormulaire'> - <?php - echo __d('fiche', 'fiche.textInfoCoresponsable'); - ?> - </span> - <div class="row row35"></div> - </div> - - <div class="row"> - <!-- Colonne de gauche --> - <div class="col-md-6"> + <div class="row"> + <!-- Colonne de gauche --> + <div class="col-md-6"> + <!-- Co-responsabilité sur le traitement --> + <span class='labelFormulaire'> <?php - echo $this->WebcilForm->input('Fiche.coresponsable', [ - 'type' => 'text', - 'required' => true, - 'placeholder' => false, - 'readonly' => true - ]); + echo __d('fiche', 'fiche.textInfoCoresponsable'); ?> + </span> + + <?php + echo $this->WebcilForm->input('Fiche.coresponsable', [ + 'options' => [ + true => 'Oui', + false => 'Non' + ], + 'default' => false, + 'class' => 'transformSelect form-control', + 'placeholder' => false, + 'required' => true, + 'readonly' => true, + 'data-placeholder' => ' ' + ]); + ?> </div> - </div> + </div> - <!-- Sous-traitance sur le traitement --> - <div class="col-md-12"> + <div class="row"> + <!-- Colonne de gauche --> + <div class="col-md-6"> + <!-- Sous-traitance sur le traitement --> <span class='labelFormulaire'> <?php echo __d('fiche', 'fiche.textInfoSousTraitance'); ?> </span> - <div class="row row35"></div> - </div> - <div class="row"> - <!-- Colonne de gauche --> - <div class="col-md-6"> - <?php - echo $this->WebcilForm->input('Fiche.soustraitance', [ - 'type' => 'text', - 'required' => true, - 'placeholder' => false, - 'readonly' => true - ]); - ?> - </div> + <?php + echo $this->WebcilForm->input('Fiche.soustraitance', [ + 'options' => [ + true => 'Oui', + false => 'Non' + ], + 'default' => false, + 'class' => 'transformSelect form-control', + 'placeholder' => false, + 'required' => true, + 'readonly' => true, + 'data-placeholder' => ' ' + ]); + ?> </div> </div> </div> -- GitLab