]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/IO/PdfAttendanceSheet.php
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
33 * @link http://galette.tuxfamily.org
34 * @since Available since 0.9.0dev - 2016-02-21
40 use Galette\Core\Preferences
;
41 use Galette\Core\PrintLogo
;
42 use Galette\Entity\PdfModel
;
51 * @abstract Class for expanding TCPDF.
52 * @author Johan Cwiklinski <johan@x-tnd.be>
53 * @copyright 2016 The Galette Team
54 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
55 * @link http://galette.tuxfamily.org
56 * @since Available since 0.9.0dev - 2016-02-21
59 class PdfAttendanceSheet
extends Pdf
61 public const SHEET_FONT
= self
::FONT_SIZE
- 2;
62 public const ATT_SHEET_MODEL
= 100;
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->setTopMargin(15);
80 $this->SetFont(Pdf
::FONT
, '', self
::SHEET_FONT
);
81 $head_title = $this->doc_title
;
82 if ($this->sheet_title
!== null) {
83 $head_title .= ' - ' . $this->sheet_title
;
85 /* Removed to prevent long lines */
86 /*if ($this->sheet_sub_title !== null) {
87 $head_title .= ' - ' . $this->sheet_sub_title;
89 if ($this->sheet_date
!== null) {
90 $head_title .= ' - ' . $this->sheet_date
->format(__("Y-m-d"));
92 $this->Cell(0, 10, $head_title, 0, false, 'C', 0, '', 0, false, 'M', 'M');
97 * Main constructor, set creator and author
99 * @param Db $zdb Database instance
100 * @param Preferences $prefs Preferences
101 * @param array $data Data to set
103 public function __construct(Db
$zdb, Preferences
$prefs, $data = [])
105 $this->filename
= __('attendance_sheet') . '.pdf';
106 $class = PdfModel
::getTypeClass(self
::ATT_SHEET_MODEL
);
107 $model = new $class($zdb, $prefs);
109 // Set document and model information
110 $this->doc_title
= $data['doc_title'];
111 $this->SetTitle($data['doc_title']);
113 if (isset($data['title']) && trim($data['title']) != '') {
114 $this->sheet_title
= $data['title'];
115 $model->title
= $this->sheet_title
;
117 if (isset($data['subtitle']) && trim($data['subtitle']) != '') {
118 $this->sheet_sub_title
= $data['subtitle'];
119 $model->subtitle
= $this->sheet_sub_title
;
121 if (isset($data['sheet_date']) && trim($data['sheet_date']) != '') {
122 $dformat = __("Y-m-d");
123 $date = \DateTime
::createFromFormat(
127 $this->sheet_date
= $date;
130 parent
::__construct($prefs, $model);
138 private function init()
140 // Set document information
141 $this->SetSubject(_T("Generated by Galette"));
142 $this->SetKeywords(_T("Attendance sheet"));
144 // No hearders and footers
145 $this->setHeaderMargin(10);
148 $this->SetDrawColor(160, 160, 160);
149 $this->SetTextColor(0);
150 $this->SetFont(Pdf
::FONT
, '', Pdf
::FONT_SIZE
- 2);
156 * @param array $members Members
160 public function drawSheet($members)
164 $this->PageHeader($this->doc_title
);
166 if ($this->sheet_date
) {
168 if (PHP_OS
=== 'Linux') {
169 $format = _T("%A, %B %#d%O %Y");
170 $format = str_replace(
172 date('S', $this->sheet_date
->getTimestamp()),
175 $date_fmt = strftime($format, $this->sheet_date
->getTimestamp());
177 $format = __("Y-m-d");
178 $date_fmt = $this->sheet_date
->format($format);
180 $this->Cell(190, 7, $date_fmt, 0, 1, 'C');
184 $this->SetFont('', 'B');
185 $this->SetFillColor(255, 255, 255);
186 $this->Cell(110, 7, _T("Name"), 1, 0, 'C', 1);
187 $this->Cell(80, 7, _T("Signature"), 1, 1, 'C', 1);
192 foreach ($members as $m) {
194 $this->Cell(10, 16, $mcount, ($this->i18n
->isRTL() ?
'R' : 'L') . 'TB', 0, 'R');
196 if ($m->hasPicture() && $this->wimages
) {
197 $p = $m->picture
->getPath();
199 // Set logo size to max width 30 mm or max height 25 mm
200 $ratio = $m->picture
->getWidth() / $m->picture
->getHeight();
202 if ($m->picture
->getHeight() > 14) {
205 $hlogo = $m->picture
->getHeight();
207 $wlogo = round($hlogo * $ratio);
209 if ($m->picture
->getWidth() > 14) {
212 $wlogo = $m->picture
->getWidth();
214 $hlogo = round($wlogo / $ratio);
217 $y = $this->getY() +
1;
218 $x = $this->getX() +
1;
220 if ($this->i18n
->isRTL()) {
221 $ximg = $this->getPageWidth() - $x - $wlogo;
223 $this->Cell($wlogo +
2, 16, '', ($this->i18n
->isRTL() ?
'R' : 'L') . 'TB', 0);
224 $this->Image($p, $ximg, $y, $wlogo, $hlogo);
226 $x = $this->getX() +
1;
227 $this->Cell(1, 16, '', ($this->i18n
->isRTL() ?
'R' : 'L') . 'TB', 0);
230 $xs = $this->getX() - $x +
1;
231 $this->Cell(100 - $xs, 16, $m->sname
, ($this->i18n
->isRTL() ?
'L' : 'R') . 'TB', 0, ($this->i18n
->isRTL() ?
'R' : 'L'));
232 $this->Cell(80, 16, '', 1, 1, ($this->i18n
->isRTL() ?
'R' : 'L'));
234 $this->Cell(190, 0, '', 'T');
240 * @return PdfAttendanceSheet
242 public function withImages()
244 $this->wimages
= true;