Commit 42ba438b authored by Anthony Gautreau's avatar Anthony Gautreau
Browse files

Merge

parents de80ad6d 1c5750b5
Loading
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
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).
+90 −32
Original line number Diff line number Diff line
<?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.
     *
@@ -151,6 +159,9 @@ class Pdf implements ExporterInterface
        $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.
     *
@@ -243,6 +280,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;
    }
    
@@ -595,16 +663,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é
     * avec le paramètre DESTINATION_FILE.
+2 −24
Original line number Diff line number Diff line
@@ -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;
        }