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

Poursuite des modification

parent 25df747b
Loading
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -118,16 +118,23 @@ class FormulaireInstance implements HistoriqueAwareInterface {
            }
        }
        if ($champToLookFor === null) {
            return "<span style='font-weight: bold; color: red;'>Aucun champ trouvé avec les mots clefs ". implode(',', $mots)."</span>";
//            return "<span style='font-weight: bold; color: red;'>Aucun champ trouvé avec les mots clefs ". implode(',', $mots)."</span>";
            return "";
        }

        foreach ($this->getReponses() as $reponse) {
            $champ = $reponse?->getChamp();
            if ($champ?->hasMotsClefs($mots) AND $reponse->estNonHistorise()) {
                $type = $champ?->getType();
                if ($type?->getCode() === Champ::TYPE_CHECKBOX)
                    return ChampAsResultHelper::render_checkbox($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_ANNEE) return ChampAsResultHelper::render_annee($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_CHECKBOX) return ChampAsResultHelper::render_checkbox($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_CUSTOM) return ChampAsResultHelper::render_custom($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_FORMATION) return ChampAsResultHelper::render_formation($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_MULTIPLE) return ChampAsResultHelper::render_multiple($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_NOMBRE) return ChampAsResultHelper::render_nombre($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_PERIODE) return ChampAsResultHelper::render_periode($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_SELECT) return ChampAsResultHelper::render_select($champ, $reponse?->getReponse());
                if ($type?->getCode() === Champ::TYPE_SELECT_TEXT) return ChampAsResultHelper::render_select_text($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());
+172 −37
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ 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\ChampService;
use UnicaenAutoform\Service\Champ\ChampServiceAwareTrait;

class ChampAsResultHelper extends AbstractHelper
@@ -40,50 +41,51 @@ class ChampAsResultHelper extends AbstractHelper

            case Champ::TYPE_SPACER :
                return "<br>";


            case Champ::TYPE_ANNEE :
                return self::render_annee($champ, $data);
            case Champ::TYPE_CHECKBOX :
                return self::render_checkbox($champ, $data);
            case Champ::TYPE_TEXT :
                return self::render_text($champ, $data);
            case Champ::TYPE_MULTIPLE_TEXT :
                $texte .= $view->partial('result/multiple_text', ['champ' => $champ, 'data' => $data]);
                break;
            case Champ::TYPE_CUSTOM :
                $texte .= $view->partial('result/custom', ['champ' => $champ, 'data' => $data]);
                break;
            case Champ::TYPE_TEXTAREA :
                return self::render_textarea($champ, $data);
                return self::render_custom($champ, $data);
            case Champ::TYPE_FORMATION :
                return self::render_formation($champ, $data);
            case Champ::TYPE_MULTIPLE :
                return self::render_multiple($champ, $data);
            case Champ::TYPE_MULTIPLE_TEXT :
                return self::render_multiple_text($champ, $data);
            case Champ::TYPE_NOMBRE :
                return self::render_nombre($champ, $data);
            case Champ::TYPE_PERIODE :
                return self::render_periode($champ, $data);
            case Champ::TYPE_PLUS_TEXTE :
                return self::render_plus_text($champ, $data);
            case Champ::TYPE_PLUS_CUSTOM :
                return self::render_plus_custom($champ, $data);
            case Champ::TYPE_SELECT :
                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]);
                break;
            case Champ::TYPE_ANNEE :
                $texte .= $view->partial('result/annee', ['champ' => $champ, 'data' => $data]);
                break;
            case Champ::TYPE_PERIODE :
                $texte .= $view->partial('result/periode', ['champ' => $champ, 'data' => $data]);
                break;
            case Champ::TYPE_FORMATION :
                $texte .= $view->partial('result/formation', ['champ' => $champ, 'data' => $data]);
                break;
            case Champ::TYPE_MULTIPLE :
                $texte .= $view->partial('result/multiple', ['champ' => $champ, 'data' => $data]);
                break;
            case Champ::TYPE_ENTITY :
                return self::render_select_text($champ, $data);
            case Champ::TYPE_TEXT :
                return self::render_text($champ, $data);
            case Champ::TYPE_TEXTAREA :
                return self::render_textarea($champ, $data);


            case Champ::TYPE_ENTITY : //todo gerer le problème de champService
                //return self::render_entity($champ, $data, $this->getChampService());
                $options = $this->getChampService()->getAllInstance($champ->getOptions());
                $reponse = "NOT FOUND !!!";
                foreach ($options as $id => $option) {
                    if ($id == $data) {
                    if ($id == $reponse) {
                        $reponse = $option;
                        break;
                    }
                }
                $texte .= $view->partial('result/entity', ['champ' => $champ, 'data' => $reponse]);
                $texte .= $view->partial('result/entity-multiple', ['champ' => $champ, 'data' => $reponse]);
                break;
            case Champ::TYPE_ENTITY_MULTI :
            case Champ::TYPE_ENTITY_MULTI : //todo gerer le problème de champService
                $options = $this->getChampService()->getAllInstance($champ->getOptions());
                $ids = explode(";", (string) $data);
                $reponse = [];
@@ -92,10 +94,8 @@ class ChampAsResultHelper extends AbstractHelper
                }
                $texte .= $view->partial('result/entity-multiple', ['champ' => $champ, 'data' => $reponse]);
                break;
            case Champ::TYPE_PLUS_TEXTE :
                return self::render_plus_text($champ, $data);
            case Champ::TYPE_PLUS_CUSTOM :
                return self::render_plus_custom($champ, $data);


            default :
                $texte .= 'Type [' . $champ->getType()->getCode() . '] inconnu !';
                break;
@@ -110,6 +110,15 @@ class ChampAsResultHelper extends AbstractHelper
        return $texte;
    }

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

    static public function render_checkbox(Champ $champ, ?string $reponse): string
    {
        $texte = "<div data-champ-type='" . Champ::TYPE_CHECKBOX . "' data-empty='false'>";
@@ -119,25 +128,73 @@ class ChampAsResultHelper extends AbstractHelper
        return $texte;
    }

    static public function render_text(Champ $champ, ?string $reponse): string
    //todo ici on a un problème car on ne pourra pas récupérer le service depuis FormulaireInstance ...
    static public function render_entity(Champ $champ, ?string $reponse, ?ChampService $champService): string
    {
        $texte = "<div data-champ-type='" . Champ::TYPE_TEXT . "' data-empty='false'>";
        $options = $champService->getAllInstance($champ->getOptions());
        $reponse = "NOT FOUND !!!";
        foreach ($options as $id => $option) {
            if ($id == $reponse) {
                $reponse = $option;
                break;
            }
        }

        $texte = "<div data-champ-type='" . Champ::TYPE_ENTITY . "' 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
    static public function render_formation(Champ $champ, ?string $reponse): string
    {
        $texte = "<div data-champ-type='" . Champ::TYPE_TEXTAREA . "' data-empty='false'>";
        $split = explode("|",$reponse);
        $text = (count($split) === 2)?$split[0]:"";
        $select = (count($split) === 2)?$split[1]:"";

        $texte = "<div data-champ-type='" . Champ::TYPE_FORMATION . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span> ";
        if ($champ->getTexte() !== 'Échéance') $texte .= $text . " sur la période ".$select;
        else  $texte .= $text . " à l'échéance ".$select;
        $texte .= "</div>";
        return $texte;
    }

    static public function render_multiple(Champ $champ, ?string $reponse): string
    {
        $splits = explode(";", (string) $reponse);

        $texte = "<div data-champ-type='" . Champ::TYPE_MULTIPLE . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span> ";
        $texte .= "<ul>";
        foreach ($splits as $split) {
            $resplits = str_replace("_"," ",substr($split,3));
            $texte .= "<li>". $resplits."</li>";
        }
        $texte .= "</ul>";
        $texte .= "</div>";
        return $texte;
    }

    static public function render_multiple_text(Champ $champ, ?string $reponse): string
    {
        $splits = explode(";", (string) $reponse);

        $texte = "<div data-champ-type='" . Champ::TYPE_MULTIPLE . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span> ";
        $texte .= "<ul>";
        foreach ($splits as $split) {
            $resplits = str_replace("_"," ",substr($split,3));
            $texte .= "<li>". $resplits."</li>";
        }
        $texte .= "</ul>";
        $texte .= $reponse;
        $texte .= "</div>";
        return $texte;
    }

    static public function render_nombre(Champ $champ, string $reponse): string
    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> ";
@@ -146,15 +203,62 @@ class ChampAsResultHelper extends AbstractHelper
        return $texte;
    }

    static public function render_periode(Champ $champ, ?string $reponse): string
    {
        $texte = "<div data-champ-type='" . Champ::TYPE_PERIODE . "' 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_TEXT . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span> ";
        $texte .= $reponse;
        $texte .= "</div>";
        return $texte;
    }

    static public function render_select_text(Champ $champ, ?string $reponse): string
    {
        [$select, $text] = explode(":::", (string) $reponse);

        if (substr($select, -1) === '*') {
            $select = substr($select, 0, -1);
        }

        $texte  = "<div data-champ-type='" . Champ::TYPE_SELECT . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span> ";
        $texte .= $select;
        if ($text) $texte .= "<br><span class='input-sublibelle'>Complément :</span> " . $text;
        $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_plus_text(Champ $champ, ?string $reponse): string
    {
        $texte  = "<div data-champ-type='" . Champ::TYPE_PLUS_CUSTOM . "' data-empty='false'>";
@@ -169,6 +273,37 @@ class ChampAsResultHelper extends AbstractHelper
        return $texte;
    }

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

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

        $texte = "<div data-champ-type='" . Champ::TYPE_PLUS_CUSTOM . "' data-empty='false'>";
        $texte .= "<span class='input-libelle' >" . $champ->getLibelle() . " :</span>";

        $texte .= "<ul>";
        $splits = explode(Champ::SEPARATOR_PLUS_CUSTOM_FIELD, $reponse);
        $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 .= "</div>";
        return $texte;
    }

    static public function render_plus_custom(Champ $champ, ?string $reponse): string
    {
        $fields = explode(';', $champ->getOptions());
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ if ($champ->getOptions() != "") {
    $split = explode(";", $champ->getOptions());
    if (!empty($split)) $periode = $split;
}
$split = explode("|",$reponse);
$split = explode("|",$reponse??"");
$text = (count($split) === 2)?$split[0]:"";
$select = (count($split) === 2)?$split[1]:"";
?>
+0 −14
Original line number Diff line number Diff line
<?php
/**
 * @var Champ $champ
 * @var string $data
 */

use UnicaenAutoform\Entity\Db\Champ;

?>

<?php echo $champ->getLibelle(); ?>&nbsp;:
<?php if ($data !== 'null') : ?>
    <?php echo $data; ?>
<?php endif; ?>
 No newline at end of file
+0 −17
Original line number Diff line number Diff line
<?php
/**
 * @var Champ $champ
 * @var string $data
 */

use UnicaenAutoform\Entity\Db\Champ;

?>

<?php if ($data === "on") : ?>
    <?php if ($champ->getTexte()) : ?>
        <?php echo $champ->getTexte(); ?>
    <?php else : ?>
        <?php echo $champ->getLibelle(); ?>
    <?php endif; ?>
<?php endif; ?>
Loading