]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/IO/PdfAttendanceSheet.php
4 * Copyright © 2003-2024 The Galette Team
6 * This file is part of Galette (https://galette.eu).
8 * Galette is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * Galette is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
25 use Galette\Core\Preferences
;
26 use Galette\Entity\Adherent
;
27 use Galette\Entity\PdfModel
;
32 * @author Johan Cwiklinski <johan@x-tnd.be>
35 class PdfAttendanceSheet
extends Pdf
37 public const SHEET_FONT
= self
::FONT_SIZE
- 2;
38 public const ATT_SHEET_MODEL
= 100;
40 public ?
string $doc_title = null;
41 public ?
string $sheet_title = null;
42 public ?
string $sheet_sub_title = null;
43 public ?\DateTime
$sheet_date = null;
44 private bool $wimages = false;
51 public function Header(): void
// phpcs:ignore PSR1.Methods.CamelCapsMethodName
53 if ($this->PageNo() > 1) {
54 $this->setTopMargin(15);
56 $this->SetFont(Pdf
::FONT
, '', self
::SHEET_FONT
);
57 $head_title = $this->doc_title
;
58 if ($this->sheet_title
!== null) {
59 $head_title .= ' - ' . $this->sheet_title
;
61 /* Removed to prevent long lines */
62 /*if ($this->sheet_sub_title !== null) {
63 $head_title .= ' - ' . $this->sheet_sub_title;
65 if ($this->sheet_date
!== null) {
66 $head_title .= ' - ' . $this->sheet_date
->format(__("Y-m-d"));
68 $this->Cell(0, 10, $head_title, 0, 0, 'C', false, '', 0, false, 'M', 'M');
73 * Main constructor, set creator and author
75 * @param Db $zdb Database instance
76 * @param Preferences $prefs Preferences
77 * @param array<string,mixed> $data Data to set
79 public function __construct(Db
$zdb, Preferences
$prefs, array $data = [])
81 $this->filename
= __('attendance_sheet') . '.pdf';
82 $class = PdfModel
::getTypeClass(self
::ATT_SHEET_MODEL
);
83 $model = new $class($zdb, $prefs);
85 // Set document and model information
86 $this->doc_title
= $data['doc_title'];
87 $this->SetTitle($data['doc_title']);
89 if (isset($data['title']) && trim($data['title']) != '') {
90 $this->sheet_title
= $data['title'];
91 $model->title
= $this->sheet_title
;
93 if (isset($data['subtitle']) && trim($data['subtitle']) != '') {
94 $this->sheet_sub_title
= $data['subtitle'];
95 $model->subtitle
= $this->sheet_sub_title
;
97 if (isset($data['sheet_date']) && trim($data['sheet_date']) != '') {
98 $dformat = __("Y-m-d");
99 $date = \DateTime
::createFromFormat(
103 $this->sheet_date
= $date;
106 parent
::__construct($prefs, $model);
107 // Enable Auto Page breaks
108 $this->SetAutoPageBreak(true, $this->footer_height +
10);
116 public function init(): void
118 // Set document information
119 $this->SetSubject(_T("Generated by Galette"));
120 $this->SetKeywords(_T("Attendance sheet"));
122 $this->setHeaderMargin(10);
125 $this->SetDrawColor(160, 160, 160);
126 $this->SetTextColor(0);
127 $this->SetFont(Pdf
::FONT
, '', Pdf
::FONT_SIZE
- 2);
130 $this->showPagination();
138 * @param array<Adherent> $members Members
142 public function drawSheet(array $members): void
144 $this->PageHeader($this->doc_title
);
146 if ($this->sheet_date
) {
147 $format = __("MMMM, EEEE d y");
148 $formatter = new \
IntlDateFormatter(
149 $this->i18n
->getLongID(),
150 \IntlDateFormatter
::FULL
,
151 \IntlDateFormatter
::NONE
,
152 \
date_default_timezone_get(),
153 \IntlDateFormatter
::GREGORIAN
,
156 $datetime = new \
DateTimeImmutable($this->sheet_date
->format('Y-m-d'));
157 $date = \DateTime
::createFromImmutable($datetime);
158 $date_fmt = mb_convert_case($formatter->format($date), MB_CASE_TITLE
);
159 $this->Cell(190, 7, $date_fmt, 0, 1, 'C');
163 $this->SetFont('', 'B');
164 $this->SetFillColor(255, 255, 255);
165 $this->Cell(110, 7, _T("Name"), 1, 0, 'C', true);
166 $this->Cell(80, 7, _T("Signature"), 1, 1, 'C', true);
171 foreach ($members as $m) {
173 $this->Cell(10, 16, (string)$mcount, ($this->i18n
->isRTL() ?
'R' : 'L') . 'TB', 0, 'R');
175 if ($m->hasPicture() && $this->wimages
) {
176 $p = $m->picture
->getPath();
178 // Set logo size to max width 30 mm or max height 25 mm
179 $ratio = $m->picture
->getWidth() / $m->picture
->getHeight();
181 if ($m->picture
->getHeight() > 14) {
184 $hlogo = $m->picture
->getHeight();
186 $wlogo = round($hlogo * $ratio);
188 if ($m->picture
->getWidth() > 14) {
191 $wlogo = $m->picture
->getWidth();
193 $hlogo = round($wlogo / $ratio);
196 $y = $this->getY() +
1;
197 $x = $this->getX() +
1;
199 if ($this->i18n
->isRTL()) {
200 $ximg = $this->getPageWidth() - $x - $wlogo;
202 $this->Cell($wlogo +
2, 16, '', ($this->i18n
->isRTL() ?
'R' : 'L') . 'TB', 0);
203 $this->Image($p, $ximg, $y, $wlogo, $hlogo);
205 $x = $this->getX() +
1;
206 $this->Cell(1, 16, '', ($this->i18n
->isRTL() ?
'R' : 'L') . 'TB', 0);
209 $xs = $this->getX() - $x +
1;
210 $this->Cell(100 - $xs, 16, $m->sname
, ($this->i18n
->isRTL() ?
'L' : 'R') . 'TB', 0, ($this->i18n
->isRTL() ?
'R' : 'L'));
211 $this->Cell(80, 16, '', 1, 1, ($this->i18n
->isRTL() ?
'R' : 'L'));
213 $this->Cell(190, 0, '', 'T');
221 public function withImages(): self
223 $this->wimages
= true;