]> git.agnieray.net Git - galette.git/commitdiff
Use main model headers and footers on emargement lists; closes #1346
authorJohan Cwiklinski <jcwiklinski@teclib.com>
Sun, 17 Nov 2019 22:49:01 +0000 (23:49 +0100)
committerJohan Cwiklinski <jcwiklinski@teclib.com>
Sun, 17 Nov 2019 22:49:01 +0000 (23:49 +0100)
galette/includes/routes/members.routes.php
galette/lib/Galette/Core/Preferences.php
galette/lib/Galette/IO/Pdf.php
galette/lib/Galette/IO/PdfAttendanceSheet.php

index bdf9aa3a798204df9b48b3f5ea8fdc383d020582..b6064c6a433412172eabcda70a99481a61005f78 100644 (file)
@@ -2740,25 +2740,13 @@ $app->post(
             $doc_title = $post['sheet_type'];
         }
 
-        $pdf = new Galette\IO\PdfAttendanceSheet($this->preferences);
-        $pdf->doc_title = $doc_title;
-        // Set document information
-        $pdf->SetTitle($doc_title);
-
-        if (isset($post['sheet_title']) && trim($post['sheet_title']) != '') {
-            $pdf->sheet_title = $post['sheet_title'];
-        }
-        if (isset($post['sheet_sub_title']) && trim($post['sheet_sub_title']) != '') {
-            $pdf->sheet_sub_title = $post['sheet_sub_title'];
-        }
-        if (isset($post['sheet_date']) && trim($post['sheet_date']) != '') {
-            $dformat = __("Y-m-d");
-            $date = DateTime::createFromFormat(
-                $dformat,
-                $post['sheet_date']
-            );
-            $pdf->sheet_date = $date;
-        }
+        $data = [
+            'doc_title' => $doc_title,
+            'title'     => $post['sheet_title'] ?? null,
+            'subtitle'  => $post['sheet_sub_title'] ?? null,
+            'sheet_date'=> $post['sheet_date'] ?? null
+        ];
+        $pdf = new Galette\IO\PdfAttendanceSheet($this->zdb, $this->preferences, $data);
         //with or without images?
         if (isset($post['sheet_photos']) && $post['sheet_photos'] === '1') {
             $pdf->withImages();
index d9c3372f09954e993b2a3daf81b21d8211ac1036..ca6fc8f323686a265199894f22c6ffade8457c75 100644 (file)
@@ -663,8 +663,8 @@ class Preferences
                 $_address .= "\n" . $this->prefs['pref_adresse2'];
             }
             $replacements = array(
-                '',
-                '',
+                $this->prefs['pref_nom'],
+                "\n",
                 $_address,
                 $this->prefs['pref_cp'],
                 $this->prefs['pref_ville'],
index a7364fc2c249a9ea4d4098c1520479cf8a033682..88a1925c34a153e9dedfc3cce915c363b00ebc3c 100644 (file)
@@ -253,7 +253,7 @@ class Pdf extends \TCPDF
             $hfooter .= $this->model->hfooter;
             $this->writeHtml($hfooter);
         } else {
-            $this->SetFont(self::FONT, '', self::FONT_SIZE);
+            $this->SetFont(self::FONT, '', self::FONT_SIZE - 2);
             $this->SetTextColor(0, 0, 0);
 
             $name = preg_replace(
@@ -262,34 +262,14 @@ class Pdf extends \TCPDF
                 _T("Association %s")
             );
 
-            /** FIXME: get configured postal address */
-            $coordonnees_line1 = $name . ' - ' . $this->preferences->pref_adresse;
-            /** FIXME: pref_adresse2 should be removed */
-            if (trim($this->preferences->pref_adresse2) != '') {
-                $coordonnees_line1 .= ', ' . $this->preferences->pref_adresse2;
-            }
-            $coordonnees_line2 = $this->preferences->pref_cp . ' ' .
-                $this->preferences->pref_ville;
+            $address = $this->preferences->getPostalAddress();
 
-            $this->Cell(
+            $this->MultiCell(
                 0,
                 4,
-                $coordonnees_line1,
+                $address,
                 0,
-                1,
                 'C',
-                0,
-                $this->preferences->pref_website
-            );
-            $this->Cell(
-                0,
-                4,
-                $coordonnees_line2,
-                0,
-                0,
-                'C',
-                0,
-                $this->preferences->pref_website
             );
 
             if ($this->paginated) {
@@ -378,15 +358,12 @@ class Pdf extends \TCPDF
             $this->Ln(2);
             $ystart = $this->GetY();
 
-            $this->Cell(
-                0,
+            $this->MultiCell(
+                180 - $wlogo,
                 6,
                 $this->preferences->pref_nom,
                 0,
-                1,
-                'L',
-                0,
-                $this->preferences->pref_website
+                'L'
             );
             $this->SetFont(self::FONT, 'B', self::FONT_SIZE + 2);
 
index 4d0d67e45e51e8ed836e6ab6ca906057d4b212bb..67605b2b1aaf2e13815a4903277f6c25b0aeb947 100644 (file)
 
 namespace Galette\IO;
 
+use Galette\Core\Db;
 use Galette\Core\Preferences;
 use Galette\Core\PrintLogo;
+use Galette\Entity\PdfModel;
 use Analog\Analog;
 
 /**
@@ -72,28 +74,56 @@ class PdfAttendanceSheet extends Pdf
      */
     public function Header() // phpcs:ignore PSR1.Methods.CamelCapsMethodName
     {
-        $this->SetFont(Pdf::FONT, '', self::SHEET_FONT);
-        $head_title = $this->doc_title;
-        if ($this->sheet_title !== null) {
-            $head_title .= ' - ' . $this->sheet_title;
-        }
-        if ($this->sheet_sub_title !== null) {
-            $head_title .= ' - ' . $this->sheet_sub_title;
-        }
-        if ($this->sheet_date !== null) {
-            $head_title .= ' - ' . $this->sheet_date->format(__("Y-m-d"));
+        if ($this->PageNo() > 1) {
+            $this->SetFont(Pdf::FONT, '', self::SHEET_FONT);
+            $head_title = $this->doc_title;
+            if ($this->sheet_title !== null) {
+                $head_title .= ' - ' . $this->sheet_title;
+            }
+            if ($this->sheet_sub_title !== null) {
+                $head_title .= ' - ' . $this->sheet_sub_title;
+            }
+            if ($this->sheet_date !== null) {
+                $head_title .= ' - ' . $this->sheet_date->format(__("Y-m-d"));
+            }
+            $this->Cell(0, 10, $head_title, 1, false, 'C', 0, '', 0, false, 'M', 'M');
         }
-        $this->Cell(0, 10, $head_title, 0, false, 'C', 0, '', 0, false, 'M', 'M');
     }
 
     /**
      * Main constructor, set creator and author
      *
+     * @param Db          $zdb   Database instance
      * @param Preferences $prefs Preferences
+     * @param array       $data  Data to set
      */
-    public function __construct(Preferences $prefs)
+    public function __construct(Db $zdb, Preferences $prefs, $data = [])
     {
-        parent::__construct($prefs);
+        $class = PdfModel::getTypeClass(__CLASS__);
+        $model = new $class($zdb, $prefs, PdfModel::MAIN_MODEL);
+
+        // Set document and model information
+        $this->doc_title = $data['doc_title'];
+        $this->SetTitle($data['doc_title']);
+
+        if (isset($data['title']) && trim($data['title']) != '') {
+            $this->sheet_title = $data['title'];
+            $model->title = $this->sheet_title;
+        }
+        if (isset($data['subtitle']) && trim($data['subtitle']) != '') {
+            $this->sheet_sub_title = $data['subtitle'];
+            $model->subtitle = $this->sheet_sub_title;
+        }
+        if (isset($data['sheet_date']) && trim($data['sheet_date']) != '') {
+            $dformat = __("Y-m-d");
+            $date = \DateTime::createFromFormat(
+                $dformat,
+                $data['sheet_date']
+            );
+            $this->sheet_date = $date;
+        }
+
+        parent::__construct($prefs, $model);
         $this->init();
     }
     /**
@@ -130,12 +160,6 @@ class PdfAttendanceSheet extends Pdf
         $this->AddPage();
         $this->PageHeader($doc_title);
 
-        if ($this->sheet_title !== null) {
-            $this->Cell(190, 7, $this->sheet_title, 0, 1, 'C');
-        }
-        if ($this->sheet_sub_title) {
-            $this->Cell(190, 7, $this->sheet_sub_title, 0, 1, 'C');
-        }
         if ($this->sheet_date) {
             $date_fmt = null;
             if (PHP_OS === 'Linux') {