diff --git a/CHANGELOG.md b/CHANGELOG.md index f97861e720bfff502d1850bb5e4afcf9e36f29f2..ebd5a887bacf58b119fdd9d64940e5bc669a95be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ CHANGELOG ========= +5.1.1 +----- +- Suppression du fix pour bootstrap-select-1.14.0-beta2 donc nécessaité de passer à bootstrap-select-1.14.0-beta3 dans vos applis. + +5.1.0 +----- +- Exporteur PDF : nouvelles méthodes set(Footer|Header)ScriptToDefault() et set(Footer|Header)ScriptToNone(). + +5.0.1 +----- +- [FIX] FormControlGroup : prise en compte de la classe CSS des labels de checkboxes. + 5.0.0 ----- - Migration vers Bootstrap 5 (front-end). diff --git a/src/UnicaenApp/Exporter/Pdf.php b/src/UnicaenApp/Exporter/Pdf.php index 8fd0571c214ec4652d0e37fb353090a3ff0b00ce..3e3ecb77453afd9101e1348552af83dd62bec1f4 100644 --- a/src/UnicaenApp/Exporter/Pdf.php +++ b/src/UnicaenApp/Exporter/Pdf.php @@ -1,6 +1,7 @@ <?php namespace UnicaenApp\Exporter; +use Laminas\View\Resolver\TemplatePathStack; use Mpdf\Mpdf as mPDF; use UnicaenApp\Exception\LogicException; use UnicaenApp\Exception\RuntimeException; @@ -129,6 +130,13 @@ class Pdf implements ExporterInterface */ private $logo; + /** + * Chemin absolu du répertoire contenant les scripts de vue par défaut. + * + * @var string + */ + protected $defaultScriptsDirPath = __DIR__ . '/scripts'; + /** * Constructeur. * @@ -146,11 +154,14 @@ class Pdf implements ExporterInterface if (null !== $renderer) { $this->setRenderer($renderer); } - + $this->format = $format; $this->orientationPaysage = $orientationPaysage; $this->defaultFontSize = $defaultFontSize; + $this->setHeaderScriptToDefault(); + $this->setFooterScriptToDefault(); + $this->setLogo(file_get_contents(__DIR__ . "/../../../public/unicaen/app/img/logo-unicaen.png")); } @@ -179,6 +190,32 @@ class Pdf implements ExporterInterface return $this; } + /** + * Spécifie qu'aucun script ne soit utilisé pour les entêtes de pages. + * Autrement dit, les pages du document PDF n'auront pas d'entête ! + * + * @return self + */ + public function setHeaderScriptToNone() + { + $this->headerScripts = array(); + + return $this; + } + + /** + * Restaure le script de vue par défaut pour les entêtes de pages (pages paires et impaires). + * + * @return self + */ + public function setHeaderScriptToDefault() + { + $this->headerScripts['O'] = 'header-odd.phtml'; + $this->headerScripts['E'] = 'header-even.phtml'; + + return $this; + } + /** * Ajoute un script de vue à inclure dans le rendu du corps du document PDF. * @@ -242,6 +279,32 @@ class Pdf implements ExporterInterface } return $this; } + + /** + * Restaure le script de vue par défaut pour les pieds de pages (pages paires et impaires). + * + * @return self + */ + public function setFooterScriptToDefault() + { + $this->footerScripts['O'] = 'footer-odd.phtml'; + $this->footerScripts['E'] = 'footer-even.phtml'; + + return $this; + } + + /** + * Spécifie qu'aucun script ne soit utilisé pour les pieds de pages. + * Autrement dit, les pages du document PDF n'auront pas de pied de page ! + * + * @return self + */ + public function setFooterScriptToNone() + { + $this->footerScripts = array(); + + return $this; + } /** * Génère le document PDF et l'envoie éventuellement au navigateur. @@ -366,7 +429,7 @@ class Pdf implements ExporterInterface $parts = array(); // styles de base fournis par la librairie Unicaen - if (file_exists(($filepath = $this->getDefaultScriptsPath() . '/pdf.css'))) { + if (file_exists(($filepath = $this->defaultScriptsDirPath . '/pdf.css'))) { $css = file_get_contents($filepath); $this->getMpdf()->WriteHTML($css, 1); $parts[] = $css; @@ -409,20 +472,20 @@ class Pdf implements ExporterInterface if (isset($this->headerScripts['O'])) { $headerOdd = $this->getRenderer()->render($this->headerScripts['O'], $scriptVars); } - elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/header-odd.phtml')) { - ob_start(); - include $filepath; - $headerOdd = ob_get_clean(); - } +// elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/header-odd.phtml')) { +// ob_start(); +// include $filepath; +// $headerOdd = ob_get_clean(); +// } if (isset($this->headerScripts['E'])) { $headerEven = $this->getRenderer()->render($this->headerScripts['E'], $scriptVars); } - elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/header-even.phtml')) { - ob_start(); - include $filepath; - $headerEven = ob_get_clean(); - } +// elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/header-even.phtml')) { +// ob_start(); +// include $filepath; +// $headerEven = ob_get_clean(); +// } if ($headerOdd) { $this->getMpdf()->SetHTMLHeader($headerOdd, 'O'); @@ -498,20 +561,20 @@ class Pdf implements ExporterInterface if (isset($this->footerScripts['O'])) { $footerOdd = $this->getRenderer()->render($this->footerScripts['O'], $scriptVars); } - elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/footer-odd.phtml')) { - ob_start(); - include $filepath; - $footerOdd = ob_get_clean(); - } +// elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/footer-odd.phtml')) { +// ob_start(); +// include $filepath; +// $footerOdd = ob_get_clean(); +// } if (isset($this->footerScripts['E'])) { $footerEven = $this->getRenderer()->render($this->footerScripts['E'], $scriptVars); } - elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/footer-even.phtml')) { - ob_start(); - include $filepath; - $footerEven = ob_get_clean(); - } +// elseif (file_exists($filepath = $this->getDefaultScriptsPath() . '/footer-even.phtml')) { +// ob_start(); +// include $filepath; +// $footerEven = ob_get_clean(); +// } if ($footerOdd) { $this->getMpdf()->SetHTMLFooter($footerOdd, 'O'); @@ -532,6 +595,11 @@ class Pdf implements ExporterInterface public function setRenderer(PhpRenderer $renderer) { $this->renderer = $renderer; + + $this->renderer->resolver()->attach(new TemplatePathStack(['script_paths' => [ + $this->defaultScriptsDirPath, + ]])); + return $this; } @@ -594,16 +662,6 @@ class Pdf implements ExporterInterface return $this->mpdf; } - - /** - * Retourne le chemin absolu du répertoire contenant les scripts de vue par défaut. - * - * @return string - */ - public function getDefaultScriptsPath() - { - return __DIR__ . '/scripts'; - } /** * Spécifie le chemin absolu dans lequel enregistrer le document PDF généré diff --git a/src/UnicaenApp/Form/View/Helper/FormControlGroup.php b/src/UnicaenApp/Form/View/Helper/FormControlGroup.php index 96f18b852d8c5f3cdf793fa87d4a744ddfc014cf..b1c0f099b3e9f376f6080df73edf1cdb95ea5da3 100644 --- a/src/UnicaenApp/Form/View/Helper/FormControlGroup.php +++ b/src/UnicaenApp/Form/View/Helper/FormControlGroup.php @@ -138,29 +138,6 @@ class FormControlGroup extends AbstractHelper private function normalizeElement(ElementInterface $element) { - // FIX pour "bootstrap-select-1.14.0-beta2" qui ne supporte pas les 'optgroup' avec Bootstrap 5 : - // on transforme en select sans optgroup (le nom du groupe est répété en tête de chaque option). - if ($element instanceof Select) { - $valueOptions = $element->getValueOptions(); - $newValueOptions = []; - foreach ($valueOptions as $key => $value) { - if (is_array($value) && array_key_exists('options', $value)) { // détection d'un optgroup ! - $options = $value['options']; - $groupName = $value['label']; - foreach ($options as $k => $v) { - if (is_array($v)) { - $k = $v['value']; - $v = $v['label']; - } - $newValueOptions[$k] = $groupName . ' > ' . $v; // nom du groupe en tête de l'option - } - } else { - $newValueOptions[$key] = $value; - } - } - $element->setValueOptions($newValueOptions); - } - if (!$element instanceof Button && !is_a($element, Checkbox::class)) { $class = $element->getAttribute('class'); $element->setAttribute('class', $class . ' form-control'); @@ -296,10 +273,11 @@ class FormControlGroup extends AbstractHelper $id = $element->getAttribute('id'); $label = $element->getLabel(); $title = $element->getLabelAttributes()['title'] ?? $element->getAttributes()['title'] ?? null; + $class = $element->getLabelAttributes()['class'] ?? $element->getAttributes()['class'] ?? null; $html = <<<EOS <div class="form-check"> $html - <label class="form-check-label" for="$id" title="$title">$label</label> + <label class="form-check-label $class" for="$id" title="$title">$label</label> </div> EOS; }