Commit 25df747b authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Debut de changement

parent a50d9178
Loading
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -90,4 +90,16 @@ class Formulaire implements HistoriqueAwareInterface {
        }
        return false;
    }

    /** @return Champ[] */
    public function getChamps(): array
    {
        $champs = [];
        foreach ($this->getCategories() as $categorie) {
            foreach ($categorie->getChamps() as $champ) {
                $champs[] = $champ;
            }
        }
        return $champs;
    }
}
 No newline at end of file
+25 −36
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace UnicaenAutoform\Entity\Db;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use UnicaenAutoform\View\Helper\ChampAsResultHelper;
use UnicaenUtilisateur\Entity\Db\HistoriqueAwareInterface;
use UnicaenUtilisateur\Entity\Db\HistoriqueAwareTrait;

@@ -106,53 +107,41 @@ class FormulaireInstance implements HistoriqueAwareInterface {
        return $text;
    }

    public function fetchChampReponseByMotsClefs(array $mots) : string
    public function fetchChampReponseByMotsClefs(array $mots, bool $displayIfEmpty = true) : string
    {
        $a =1;
        $champs = $this->getFormulaire()->getChamps();
        $champToLookFor = null;
        foreach ($champs as $champ_) {
            if ($champ_?->hasMotsClefs($mots)) {
                $champToLookFor = $champ_;
                break;
            }
        }
        if ($champToLookFor === null) {
            return "<span style='font-weight: bold; color: red;'>Aucun champ trouvé avec les mots clefs ". implode(',', $mots)."</span>";
        }

        foreach ($this->getReponses() as $reponse) {
            $champ = $reponse?->getChamp();
            if ($champ?->hasMotsClefs($mots) AND $reponse->estNonHistorise()) {
                $type = $champ?->getType();
                if ($type?->getCode() === Champ::TYPE_PLUS_CUSTOM) {
                    $fields = explode(';',$champ->getOptions());
                    $nbFields = count($fields);

                    $libelles = [];
                    foreach ($fields as $field) {
                        $liste = explode('|',$field);
                        $libelles[] = $liste[1]??"Aucun·e";
                    }

                    $reponses = explode(Champ::SEPARATOR_PLUS_CUSTOM_GROUP, (string) $reponse->getReponse());

                    $texte = $champ->getLibelle();
                    if (empty($reponses) OR str_replace(";","",$reponses[0]) === "") {
                        $texte .= 'aucun·e';
                    } else {

                        foreach ($reponses as $item) {
                            $splits = explode(Champ::SEPARATOR_PLUS_CUSTOM_FIELD, $item);
                            $position = 0;
                            $texte .= "<ul style='margin-bottom: 0.5rem;'>";
                            foreach ($splits as $split) {
                                if ($split !== '') {
                                    $tLibelle =  str_replace(["\'"],["'"],$libelles[$position]);
                                    $texte .= '<li>' . $tLibelle . ' : '. $split . '</li>';
                                }
                                $position++;
                            }
                            $texte .= "</ul>";
                        }
                    }
                    return $texte;
                }
                if ($type?->getCode() === Champ::TYPE_CHECKBOX)
                    return ChampAsResultHelper::render_checkbox($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_NOMBRE) return ChampAsResultHelper::render_nombre($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_TEXT) return ChampAsResultHelper::render_text($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_TEXTAREA) return ChampAsResultHelper::render_textarea($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_PLUS_TEXTE) return ChampAsResultHelper::render_plus_text($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_PLUS_CUSTOM) return ChampAsResultHelper::render_plus_custom($champ, $reponse?->getReponse());
                if ($reponse->getChamp()->getType()->getCode() !== 'Multiple') return $reponse->getReponse();
                else {
                    return str_replace('on_','',$reponse->getReponse());
                }
            }
        }
        return "";

        //cas spécial les checkbox reviennent avec null du coup si une checkbox faut renvoyer vers
        if ($champToLookFor->getType()->getCode() === Champ::TYPE_CHECKBOX) return ChampAsResultHelper::render_checkbox($champToLookFor, null);
        return "<span class='input-libelle'>".$champToLookFor->getLibelle()." :</span> ".ChampAsResultHelper::AUCUNE_REPONSE;
    }

    public function fetchChampsReponseByMotsClefs(array $mots) : string
+123 −19
Original line number Diff line number Diff line
@@ -3,18 +3,27 @@
namespace UnicaenAutoform\View\Helper;

use DateTime;
use UnicaenAutoform\Entity\Db\Champ;
use UnicaenAutoform\Service\Champ\ChampServiceAwareTrait;
use Laminas\Form\View\Helper\AbstractHelper;
use Laminas\View\Renderer\PhpRenderer;
use Laminas\View\Resolver\TemplatePathStack;
use UnicaenAutoform\Entity\Db\Champ;
use UnicaenAutoform\Service\Champ\ChampServiceAwareTrait;

class ChampAsResultHelper extends AbstractHelper
{
    use ChampServiceAwareTrait;

    public function render(Champ $champ, $data = null, ?DateTime $date = null) : string
    const AUCUNE_REPONSE = "<span class='missing-data'> Aucune réponse </span>";
    const NO_RESULT = [Champ::TYPE_LABEL, Champ::TYPE_SPACER, Champ::TYPE_CHECKBOX];

    public function render(Champ $champ, $data = null, ?DateTime $date = null, bool $displayIfEmpty = true): string
    {
        $a = 1;
        if ($data === null and !in_array($champ->getType()->getCode(), self::NO_RESULT))
            if ($displayIfEmpty) {
                return "<div data-champ-type='" . $champ->getType()->getCode() . "' data-empty='true'><span class='input-libelle'>" . $champ->getLibelle() . " :</span> " . ChampAsResultHelper::AUCUNE_REPONSE . "</div>";
            } else return "";

        $texte = "";

        /** @var PhpRenderer $view */
@@ -23,14 +32,18 @@ class ChampAsResultHelper extends AbstractHelper

        switch ($champ->getType()->getCode()) {
            case Champ::TYPE_LABEL :
                $texte = "<div data-champ-type='" . Champ::TYPE_LABEL . "' class='autoform-texte'>";
                if ($champ->getLibelle() !== 'empty') $texte .= "<h4>" . $champ->getLibelle() . "</h4>";
                if ($champ->getTexte()) $texte .= $champ->getTexte();
                $texte .= "</div>";
                return $texte;

            case Champ::TYPE_SPACER :
                return "";
                return "<br>";
            case Champ::TYPE_CHECKBOX :
                $texte .= $view->partial('result/checkbox', ['champ' => $champ, 'data' => $data]);
                break;
                return self::render_checkbox($champ, $data);
            case Champ::TYPE_TEXT :
                $texte .= $view->partial('result/text', ['champ' => $champ, 'data' => $data]);
                break;
                return self::render_text($champ, $data);
            case Champ::TYPE_MULTIPLE_TEXT :
                $texte .= $view->partial('result/multiple_text', ['champ' => $champ, 'data' => $data]);
                break;
@@ -38,14 +51,11 @@ class ChampAsResultHelper extends AbstractHelper
                $texte .= $view->partial('result/custom', ['champ' => $champ, 'data' => $data]);
                break;
            case Champ::TYPE_TEXTAREA :
                $texte .= $view->partial('result/textarea', ['champ' => $champ, 'data' => $data]);
                break;
                return self::render_textarea($champ, $data);
            case Champ::TYPE_NOMBRE :
                $texte .= $view->partial('result/nombre', ['champ' => $champ, 'data' => $data]);
                break;
                return self::render_nombre($champ, $data);
            case Champ::TYPE_SELECT :
                $texte .= $view->partial('result/select', ['champ' => $champ, 'data' => $data]);
                break;
                return self::render_select($champ, $data);
            case Champ::TYPE_SELECT_TEXT :
                $reponse = explode(":::", (string)$data);
                $texte .= $view->partial('result/select_text', ['champ' => $champ, 'data' => $reponse]);
@@ -83,11 +93,9 @@ class ChampAsResultHelper extends AbstractHelper
                $texte .= $view->partial('result/entity-multiple', ['champ' => $champ, 'data' => $reponse]);
                break;
            case Champ::TYPE_PLUS_TEXTE :
                $texte .= $view->partial('result/plus_text', ['champ' => $champ, 'data' => $data]);
                break;
                return self::render_plus_text($champ, $data);
            case Champ::TYPE_PLUS_CUSTOM :
                $texte .= $view->partial('result/plus_custom', ['champ' => $champ, 'data' => $data]);
                break;
                return self::render_plus_custom($champ, $data);
            default :
                $texte .= 'Type [' . $champ->getType()->getCode() . '] inconnu !';
                break;
@@ -96,9 +104,105 @@ class ChampAsResultHelper extends AbstractHelper
        if (!$champ->estNonHistorise($date)) {
            $texte = "<span class='result-historiser'>" . $texte . "</span>";
        }
        if ($texte != "") $texte = "<li>".$texte."</li>";
        if ($texte != "") $texte = $texte . "<br>";


        return $texte;
    }

    static public function render_checkbox(Champ $champ, ?string $reponse): string
    {
        $texte = "<div data-champ-type='" . Champ::TYPE_CHECKBOX . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " ?</span> ";
        $texte .= ($reponse === null)?"Non":"Oui";
        $texte .= "</div>";
        return $texte;
    }

    static public function render_text(Champ $champ, ?string $reponse): string
    {
        $texte = "<div data-champ-type='" . Champ::TYPE_TEXT . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span> ";
        $texte .= $reponse;
        $texte .= "</div>";
        return $texte;
    }

    static public function render_textarea(Champ $champ, ?string $reponse): string
    {
        $texte = "<div data-champ-type='" . Champ::TYPE_TEXTAREA . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span> ";
        $texte .= $reponse;
        $texte .= "</div>";
        return $texte;
    }

    static public function render_nombre(Champ $champ, string $reponse): string
    {
        $texte = "<div data-champ-type='" . Champ::TYPE_NOMBRE . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span> ";
        $texte .= $reponse;
        $texte .= "</div>";
        return $texte;
    }

    static public function render_select(Champ $champ, ?string $reponse): string
    {
        $texte  = "<div data-champ-type='" . Champ::TYPE_SELECT . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span> ";
        $texte .= $reponse;
        $texte .= "</div>";
        return $texte;
    }

    static public function render_plus_text(Champ $champ, ?string $reponse): string
    {
        $texte  = "<div data-champ-type='" . Champ::TYPE_PLUS_CUSTOM . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span>";
        if ($champ->getTexte()) $texte .= "<br>" . $champ->getTexte();

        $reponses = explode(Champ::SEPARATOR_PLUS_CUSTOM_FIELD, $reponse);
        $texte .= "<ul>";
        foreach ($reponses as $reponse_) $texte .= "<li>" . $reponse_ . "</li>";
        $texte .= "</ul>";
        $texte .= "</div>";
        return $texte;
    }

    static public function render_plus_custom(Champ $champ, ?string $reponse): string
    {
        $fields = explode(';', $champ->getOptions());

        $libelles = [];
        foreach ($fields as $field) {
            $liste = explode('|', $field);
            $libelles[] = $liste[1] ?? "Aucun·e";
        }

        $reponses = explode(Champ::SEPARATOR_PLUS_CUSTOM_GROUP, (string)$reponse);
        $texte = "<div data-champ-type='" . Champ::TYPE_PLUS_CUSTOM . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span>";
        $texte .= "<ol>";
        foreach ($reponses as $item) {
            $texte .= "<li>";
            $splits = explode(Champ::SEPARATOR_PLUS_CUSTOM_FIELD, $item);
            $position = 0;
            $texte .= "<ul style='margin-bottom: 0.5rem;'>";
            foreach ($splits as $split) {
                $splitReponse = (trim($split) !== '') ? trim($split) : "<span class='missing-data'>Aucune réponse</span>";
                $tLibelle = str_replace(["\'"], ["'"], $libelles[$position]);
                $texte .= '<li>';
                $texte .= "<span class='input-sublibelle'>" . $tLibelle . ' :</span> ';
                $texte .= $splitReponse;
                $texte .= '</li>';
                //                    }
                $position++;
            }
            $texte .= "</ul>";
            $texte .= "</li>";
        }
        $texte .= "</ol>";
        $texte .= "</div>";
        return $texte;
    }
}
 No newline at end of file
+9 −14
Original line number Diff line number Diff line
@@ -11,12 +11,7 @@ use UnicaenAutoform\Entity\Db\FormulaireReponse;

class InstanceAsTextHelper extends AbstractHelper
{
    /**
     * @param FormulaireInstance $instance
     * @param string $categorie_code
     * @return string
     */
    public function render(FormulaireInstance $instance, ?DateTime $date = null, string $categorie_code = null)
    public function render(FormulaireInstance $instance, ?DateTime $date = null, string $categorie_code = null, bool $displayIfEmpty = false) : string
    {
        $formulaire = $instance->getFormulaire();
        $reponsesTMP = $instance->getReponses();
@@ -59,18 +54,18 @@ class InstanceAsTextHelper extends AbstractHelper
//                }

//                if (!empty($champs) && !(empty($results))) {
                    $text .= "<div class='autoform-categorie'>";
                    $text .= '<h3 class="categorie">' . $categorie->getLibelle() . '</h3>';
                    $text .= '<ul>';
//                    $text .= '<ul>';
                    /** @var Champ $champ */
                    foreach ($champs as $champ) {
                        if (isset($reponses[$champ->getId()])) {
//                            var_dump($reponses[$champ->getId()]->getReponse());
                            $text .= $this->getView()->champAsResult()->render($champ, $reponses[$champ->getId()]->getReponse(), $date);
                        } else {
                            $text .= $this->getView()->champAsResult()->render($champ, "<span class='missing-data'>Aucune réponse</span>", $date);
                            $reponse = null;
                            if (isset($reponses[$champ->getId()])) $reponse = $reponses[$champ->getId()]->getReponse();
                            /** @see ChampAsResultHelper::render() */
                            $text .= $this->getView()->champAsResult()->render($champ, $reponse, $date, $displayIfEmpty);
                    }
                    }
                    $text .= '</ul>';
                    $text .= "</div>";
//                    $text .= '</ul>';
//                }

            }
+3 −1
Original line number Diff line number Diff line
@@ -9,11 +9,13 @@ use UnicaenAutoform\Entity\Db\Champ;
$options = explode(';', $champ->getOptions());
$min     = null;
$max     = null;
$value   = null;

foreach ($options as $option) {
    $option_ = explode(":", $option);
    if ($option_[0] === 'min') $min = $option_[1];
    if ($option_[0] === 'max') $max = $option_[1];
    if ($option_[0] === 'value') $value = $option_[1];
}
?>

@@ -28,7 +30,7 @@ foreach ($options as $option) {
        <div class="col-sm-9">
            <input class="form-control" type="number" id="text_<?php echo $champ->getId() ?>" name="<?php echo $champ->getId() ?>"
                <?php if ($champ->isObligatoire()) echo " required "; ?>
                   value="<?php echo $reponse ? trim($reponse) : null; ?>"
                   value="<?php echo $reponse ? trim($reponse) : $value; ?>"
                <?php if ($min !== null) : ?>
                    min="<?php echo $min; ?>"
                <?php endif; ?>
Loading