Skip to content
Snippets Groups Projects
Commit 24e94e83 authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Récup des champs historisés pour la partie as Text ou Result (todo ? From)

parent 3e974f1a
No related branches found
No related tags found
No related merge requests found
Pipeline #38411 passed
......@@ -2,6 +2,7 @@
namespace UnicaenAutoform\View\Helper;
use DateTime;
use UnicaenAutoform\Entity\Db\Champ;
use UnicaenAutoform\Service\Champ\ChampServiceAwareTrait;
use Laminas\Form\View\Helper\AbstractHelper;
......@@ -12,12 +13,8 @@ class ChampAsResultHelper extends AbstractHelper
{
use ChampServiceAwareTrait;
/**
* @param Champ $champ
* @param array $data
* @return string
*/
public function render($champ, $data = null) {
public function render(Champ $champ, $data = null, ?DateTime $date = null) : string
{
$texte = "";
/** @var PhpRenderer $view */
......@@ -25,10 +22,9 @@ class ChampAsResultHelper extends AbstractHelper
$view->resolver()->attach(new TemplatePathStack(['script_paths' => [__DIR__ . "/partial"]]));
switch($champ->getType()->getCode()) {
case Champ::TYPE_LABEL : return "";
break;
case Champ::TYPE_SPACER : return "";
break;
case Champ::TYPE_LABEL :
case Champ::TYPE_SPACER :
return "";
case Champ::TYPE_CHECKBOX :
$texte .= $view->partial('result/checkbox', ['champ' => $champ, 'data' => $data]);
break;
......@@ -97,7 +93,7 @@ class ChampAsResultHelper extends AbstractHelper
break;
}
if (! $champ->estNonHistorise()) {
if (! $champ->estNonHistorise($date)) {
$texte = "<span class='result-historiser'>".$texte."</span>";
}
if ($texte != "") $texte = "<li>".$texte."</li>";
......
......@@ -2,6 +2,7 @@
namespace UnicaenAutoform\View\Helper;
use DateTime;
use UnicaenAutoform\Entity\Db\Categorie;
use UnicaenAutoform\Entity\Db\Champ;
use UnicaenAutoform\Entity\Db\FormulaireInstance;
......@@ -15,7 +16,8 @@ class InstanceAsTextHelper extends AbstractHelper
* @param string $categorie_code
* @return string
*/
public function render($instance, $categorie_code = null) {
public function render(FormulaireInstance $instance, ?DateTime $date = null, string $categorie_code = null)
{
$formulaire = $instance->getFormulaire();
$reponsesTMP = $instance->getReponses();
$reponsesTMP = array_filter($reponsesTMP, function (FormulaireReponse $r) { return $r->estNonHistorise(); });
......@@ -27,7 +29,11 @@ class InstanceAsTextHelper extends AbstractHelper
$text = "";
$categories = $formulaire->getCategories();
$categories = array_filter($categories, function (Categorie $categorie) { return $categorie->estNonHistorise();});
$categories = array_filter($categories, function (Categorie $categorie) use ($date) {
$wasExisting = ($categorie->getHistoCreation() === null or $categorie->getHistoCreation() <= $date);
$wasntHistorise = ($categorie->getHistoDestruction() === null or $categorie->getHistoDestruction() >= $date);
return ($wasExisting and $wasntHistorise);
});
usort($categories, function (Categorie $a, Categorie $b) { return $a->getOrdre() - $b->getOrdre();});
......@@ -35,8 +41,10 @@ class InstanceAsTextHelper extends AbstractHelper
if ($categorie_code === null OR $categorie_code === $categorie->getCode()) {
$champs = $categorie->getChamps();
$champs = array_filter($champs, function (Champ $champ) {
return $champ->estNonHistorise();
$champs = array_filter($champs, function (Champ $champ) use ($date) {
$wasExisting = ($champ->getHistoCreation() === null or $champ->getHistoCreation() <= $date);
$wasntHistorise = ($champ->getHistoDestruction() === null or $champ->getHistoDestruction() >= $date);
return ($wasExisting and $wasntHistorise);
});
usort($champs, function (Champ $a, Champ $b) {
return $a->getOrdre() <=> $b->getOrdre();
......@@ -55,7 +63,7 @@ class InstanceAsTextHelper extends AbstractHelper
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());
$text .= $this->getView()->champAsResult()->render($champ, $reponses[$champ->getId()]->getReponse(), $date);
}
}
$text .= '</ul>';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment