From 4410efe0c19b89989e20b19476fc17e33aa7dc99 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Metivier <jean-philippe.metivier@unicaen.fr> Date: Fri, 17 Jun 2022 17:42:13 +0200 Subject: [PATCH] Modification --- Module.php | 10 ------ src/UnicaenAutoform/Entity/Db/Categorie.php | 2 ++ .../Entity/Db/FormulaireInstance.php | 7 +++- ...nicaenAutoform.Entity.Db.Categorie.dcm.xml | 1 + .../View/Helper/partial/input/custom.phtml | 5 +-- .../formulaire/afficher-formulaire.phtml | 4 ++- .../formulaire/modifier.phtml | 35 +++++++++++++++++-- 7 files changed, 48 insertions(+), 16 deletions(-) diff --git a/Module.php b/Module.php index 57d23f5..a6f5d60 100644 --- a/Module.php +++ b/Module.php @@ -17,16 +17,6 @@ class Module $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); - /* Active un layout spécial si la requête est de type AJAX. Valable pour TOUS les modules de l'application. */ - $eventManager->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', - function (MvcEvent $e) { - $request = $e->getRequest(); - if ($request instanceof HttpRequest && $request->isXmlHttpRequest()) { - $e->getTarget()->layout('layout/ajax.phtml'); - } - } - ); - } public function getConfig() diff --git a/src/UnicaenAutoform/Entity/Db/Categorie.php b/src/UnicaenAutoform/Entity/Db/Categorie.php index c38c511..a872ed0 100644 --- a/src/UnicaenAutoform/Entity/Db/Categorie.php +++ b/src/UnicaenAutoform/Entity/Db/Categorie.php @@ -5,9 +5,11 @@ namespace UnicaenAutoform\Entity\Db; use Doctrine\Common\Collections\ArrayCollection; use UnicaenApp\Entity\HistoriqueAwareInterface; use UnicaenApp\Entity\HistoriqueAwareTrait; +use UnicaenAutoform\Entity\HasMotsClefsAwareTrait; class Categorie implements HistoriqueAwareInterface { use HistoriqueAwareTrait; + use HasMotsClefsAwareTrait; /** @var integer */ private $id; diff --git a/src/UnicaenAutoform/Entity/Db/FormulaireInstance.php b/src/UnicaenAutoform/Entity/Db/FormulaireInstance.php index e77d90d..8ad53cd 100644 --- a/src/UnicaenAutoform/Entity/Db/FormulaireInstance.php +++ b/src/UnicaenAutoform/Entity/Db/FormulaireInstance.php @@ -190,7 +190,12 @@ class FormulaireInstance implements HistoriqueAwareInterface { public function fetchChampReponseByMotsClefs(array $mots) : string { foreach ($this->getReponses() as $reponse) { - if ($reponse->getChamp()->hasMotsClefs($mots) AND $reponse->estNonHistorise()) return $reponse->getReponse(); + if ($reponse->getChamp()->hasMotsClefs($mots) AND $reponse->estNonHistorise()) { + if ($reponse->getChamp()->getElement() !== 'Multiple') return $reponse->getReponse(); + else { + return str_replace('on_','',$reponse->getReponse()); + } + } } return ""; } diff --git a/src/UnicaenAutoform/Entity/Db/Mapping/UnicaenAutoform.Entity.Db.Categorie.dcm.xml b/src/UnicaenAutoform/Entity/Db/Mapping/UnicaenAutoform.Entity.Db.Categorie.dcm.xml index a967a26..53ab2f2 100644 --- a/src/UnicaenAutoform/Entity/Db/Mapping/UnicaenAutoform.Entity.Db.Categorie.dcm.xml +++ b/src/UnicaenAutoform/Entity/Db/Mapping/UnicaenAutoform.Entity.Db.Categorie.dcm.xml @@ -9,6 +9,7 @@ <field name="code" column="code" type="string" length="64" nullable="false" /> <field name="libelle" column="libelle" type="string" length="256" nullable="false" /> <field name="ordre" column="ordre" type="integer" nullable="false" /> + <field name="motsClefs" column="mots_clefs" type="string" length="1024" nullable="true" /> <many-to-one target-entity="UnicaenAutoform\Entity\Db\Formulaire" field="formulaire"> <join-column name="formulaire" referenced-column-name="id"/> diff --git a/src/UnicaenAutoform/View/Helper/partial/input/custom.phtml b/src/UnicaenAutoform/View/Helper/partial/input/custom.phtml index 13b0938..8f4902c 100644 --- a/src/UnicaenAutoform/View/Helper/partial/input/custom.phtml +++ b/src/UnicaenAutoform/View/Helper/partial/input/custom.phtml @@ -32,7 +32,7 @@ $reponses = explode(';', $reponse); <?php $found = true; ?> <input class="form-control" type="text" id="<?php echo $champ->getId()?>_<?php echo $position; ?>" name="<?php echo $champ->getId()?>_<?php echo $position; ?>" - value="<?php echo trim($reponses[$position]); ?>" + value="<?php echo isset($reponses[$position])?trim($reponses[$position]):null; ?>" /> <?php endif; ?> <?php if ($params[0] === 'texte long') : ?> @@ -47,7 +47,8 @@ $reponses = explode(';', $reponse); id="<?php echo $champ->getId(); ?>_<?php echo $position; ?>" name="<?php echo $champ->getId(); ?>_<?php echo $position; ?>" > <?php for ($param_position = 2; $param_position < count($params) ; $param_position++) : ?> - <option value="<?php echo $params[$param_position]; ?>" <?php if ($params[$param_position]===$reponses[$position]) echo " selected "; ?>> + <?php $creponse = isset($reponses[$position])?trim($reponses[$position]):null; ?> + <option value="<?php echo $params[$param_position]; ?>" <?php if ($params[$param_position]===$creponse) echo " selected "; ?>> <?php echo $params[$param_position]; ?> </option> <?php endfor; ?> diff --git a/view/unicaen-autoform/formulaire/afficher-formulaire.phtml b/view/unicaen-autoform/formulaire/afficher-formulaire.phtml index 9df5189..5964fc6 100644 --- a/view/unicaen-autoform/formulaire/afficher-formulaire.phtml +++ b/view/unicaen-autoform/formulaire/afficher-formulaire.phtml @@ -48,7 +48,9 @@ $a=1; </div> <div class="panel-body body-reductible"> <?php foreach ($champs as $champ) : ?> - <div> <?php echo $this->champAsInput()->render($champ, $reponses); ?> </div> + <div> + <?php echo $this->champAsInput()->render($champ, $reponses); ?> + </div> <?php endforeach; ?> </div> </div> diff --git a/view/unicaen-autoform/formulaire/modifier.phtml b/view/unicaen-autoform/formulaire/modifier.phtml index ab3c3f5..9e3afde 100644 --- a/view/unicaen-autoform/formulaire/modifier.phtml +++ b/view/unicaen-autoform/formulaire/modifier.phtml @@ -83,6 +83,15 @@ $canDetruireChamp = $this->isAllowed(ChampPrivileges::getResourceId(Ch <?php if ($categorie->estHistorise()) : ?> <small>(<?php echo count($categorie->getChamps()); ?> champs)</small> <?php endif; ?> + <br/> + <?php + $mots = explode(";",$categorie->getMotsClefs()); + $mots = array_filter($mots, function ($a) { return trim($a) !== '';}); + ?> + + <?php foreach ($mots as $motclef) : ?> + <span class="motclef"> <?php echo $motclef; ?> </span> + <?php endforeach; ?> </div> <div class="col-md-2"> @@ -157,8 +166,16 @@ $canDetruireChamp = $this->isAllowed(ChampPrivileges::getResourceId(Ch <div class="row survol"> <div class="col-md-10"> <?php - echo $this->champAsInput()->render($champ); + echo $this->champAsInput()->render($champ); + ?> + <?php + $mots = explode(";",$champ->getMotsClefs()); + $mots = array_filter($mots, function ($a) { return trim($a) !== '';}); ?> + + <?php foreach ($mots as $motclef) : ?> + <span class="motclef"> <?php echo $motclef; ?> </span> + <?php endforeach; ?> </div> <div class="col-md-2"> <?php if ($canModifierChamp) : ?> @@ -232,4 +249,18 @@ $canDetruireChamp = $this->isAllowed(ChampPrivileges::getResourceId(Ch window.location.reload(); }); }); -</script> \ No newline at end of file +</script> + +<style> + .motclef { + background: lightgrey; + color: black; + font-family: monospace; + border: 1px grey solid; + border-radius: 0.5rem; + margin-left: 0.5rem; + margin-bottom: 0.5rem; + padding-left: 1rem; + padding-right: 1rem; + } +</style> \ No newline at end of file -- GitLab