]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/IO/PdfAttendanceSheet.php
67605b2b1aaf2e13815a4903277f6c25b0aeb947
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2016 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2016 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.9.0dev - 2016-02-21
41 use Galette\Core\Preferences
;
42 use Galette\Core\PrintLogo
;
43 use Galette\Entity\PdfModel
;
52 * @abstract Class for expanding TCPDF.
53 * @author Johan Cwiklinski <johan@x-tnd.be>
54 * @copyright 2016 The Galette Team
55 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
56 * @link http://galette.tuxfamily.org
57 * @since Available since 0.9.0dev - 2016-02-21
60 class PdfAttendanceSheet
extends Pdf
62 const SHEET_FONT
= self
::FONT_SIZE
-2;
64 public $doc_title = null;
65 public $sheet_title = null;
66 public $sheet_sub_title = null;
67 public $sheet_date = null;
68 private $wimages = false;
75 public function Header() // phpcs:ignore PSR1.Methods.CamelCapsMethodName
77 if ($this->PageNo() > 1) {
78 $this->SetFont(Pdf
::FONT
, '', self
::SHEET_FONT
);
79 $head_title = $this->doc_title
;
80 if ($this->sheet_title
!== null) {
81 $head_title .= ' - ' . $this->sheet_title
;
83 if ($this->sheet_sub_title
!== null) {
84 $head_title .= ' - ' . $this->sheet_sub_title
;
86 if ($this->sheet_date
!== null) {
87 $head_title .= ' - ' . $this->sheet_date
->format(__("Y-m-d"));
89 $this->Cell(0, 10, $head_title, 1, false, 'C', 0, '', 0, false, 'M', 'M');
94 * Main constructor, set creator and author
96 * @param Db $zdb Database instance
97 * @param Preferences $prefs Preferences
98 * @param array $data Data to set
100 public function __construct(Db
$zdb, Preferences
$prefs, $data = [])
102 $class = PdfModel
::getTypeClass(__CLASS__
);
103 $model = new $class($zdb, $prefs, PdfModel
::MAIN_MODEL
);
105 // Set document and model information
106 $this->doc_title
= $data['doc_title'];
107 $this->SetTitle($data['doc_title']);
109 if (isset($data['title']) && trim($data['title']) != '') {
110 $this->sheet_title
= $data['title'];
111 $model->title
= $this->sheet_title
;
113 if (isset($data['subtitle']) && trim($data['subtitle']) != '') {
114 $this->sheet_sub_title
= $data['subtitle'];
115 $model->subtitle
= $this->sheet_sub_title
;
117 if (isset($data['sheet_date']) && trim($data['sheet_date']) != '') {
118 $dformat = __("Y-m-d");
119 $date = \DateTime
::createFromFormat(
123 $this->sheet_date
= $date;
126 parent
::__construct($prefs, $model);
134 private function init()
136 // Set document information
137 $this->SetSubject(_T("Generated by Galette"));
138 $this->SetKeywords(_T("Attendance sheet"));
140 // No hearders and footers
141 $this->setHeaderMargin(10);
144 $this->SetDrawColor(160, 160, 160);
145 $this->SetTextColor(0);
146 $this->SetFont(Pdf
::FONT
, '', Pdf
::FONT_SIZE
-2);
152 * @param array $members Members
153 * @param string $doc_title Document title
157 public function drawSheet($members, $doc_title)
161 $this->PageHeader($doc_title);
163 if ($this->sheet_date
) {
165 if (PHP_OS
=== 'Linux') {
166 $format = _T("%A, %B %#d%O %Y");
167 $format = str_replace(
169 date('S', $this->sheet_date
->getTimestamp()),
172 $date_fmt = strftime($format, $this->sheet_date
->getTimestamp());
174 $format = __("Y-m-d");
175 $date_fmt = $this->sheet_date
->format($format);
177 $this->Cell(190, 7, $date_fmt, 0, 1, 'C');
181 $this->SetFont('', 'B');
182 $this->SetFillColor(255, 255, 255);
183 $this->Cell(110, 7, _T("Name"), 1, 0, 'C', 1);
184 $this->Cell(80, 7, _T("Signature"), 1, 1, 'C', 1);
189 foreach ($members as $m) {
191 $this->Cell(10, 16, $mcount, 'LTB', 0, 'R');
193 if ($m->hasPicture() && $this->wimages
) {
194 $p = $m->picture
->getPath();
196 // Set logo size to max width 30 mm or max height 25 mm
197 $ratio = $m->picture
->getWidth()/$m->picture
->getHeight();
199 if ($m->picture
->getHeight() > 14) {
202 $hlogo = $m->picture
->getHeight();
204 $wlogo = round($hlogo*$ratio);
206 if ($m->picture
->getWidth() > 14) {
209 $wlogo = $m->picture
->getWidth();
211 $hlogo = round($wlogo/$ratio);
214 $y = $this->getY() +
1;
215 $x = $this->getX() +
1;
216 $this->Cell($wlogo+
2, 16, '', 'LTB', 0);
217 $this->Image($p, $x, $y, $wlogo, $hlogo);
219 $x = $this->getX() +
1;
220 $this->Cell(1, 16, '', 'LTB', 0);
223 $xs = $this->getX() - $x +
1;
224 $this->Cell(100 - $xs, 16, $m->sname
, 'RTB', 0, 'L');
225 $this->Cell(80, 16, '', 1, 1, 'L');
227 $this->Cell(190, 0, '', 'T');
233 * @return PdfAttendanceSheet
235 public function withImages()
237 $this->wimages
= true;