]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/IO/PdfMembersCards.php
2c0b65eb5bfd7bd8b3d00dea7c2d70541d8480ad
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/>.
24 use Galette\Core\Preferences
;
25 use Galette\Core\PrintLogo
;
27 use Galette\Entity\Adherent
;
32 * @author Johan Cwiklinski <johan@x-tnd.be>
35 class PdfMembersCards
extends Pdf
37 public const WIDTH
= 75;
38 public const HEIGHT
= 40;
39 public const COLS
= 2;
40 public const ROWS
= 6;
42 /** @var array<string,float|int> */
44 /** @var array<string,float|int> */
46 /** @var array<string,float|int> */
48 /** @var array<string,float|int> */
56 private int $hspacing;
57 private int $vspacing;
58 private int $max_text_size;
59 private int $year_font_size;
60 private string $an_cot;
61 private string $abrev;
64 private string $logofile;
67 * Main constructor, set creator and author
69 * @param Preferences $prefs Preferences
71 public function __construct(Preferences
$prefs)
73 parent
::__construct($prefs);
75 $this->filename
= __('cards') . '.pdf';
83 private function init(): void
85 // Set document information
86 $this->SetTitle(_T("Member's Cards"));
87 $this->SetSubject(_T("Generated by Galette"));
88 $this->SetKeywords(_T("Cards"));
90 // No hearders and footers
91 $this->SetPrintHeader(false);
92 $this->SetPrintFooter(false);
93 $this->setFooterMargin(0);
94 $this->setHeaderMargin(0);
97 $this->SetDisplayMode('fullpage');
99 // Disable Auto Page breaks
100 $this->SetAutoPageBreak(false, 0);
103 $this->SetDrawColor(160, 160, 160);
104 $this->SetTextColor(0);
105 $this->tcol
= $this->colorHex2Dec($this->preferences
->pref_card_tcol
);
106 $this->scol
= $this->colorHex2Dec($this->preferences
->pref_card_scol
);
107 $this->bcol
= $this->colorHex2Dec($this->preferences
->pref_card_bcol
);
108 $this->hcol
= $this->colorHex2Dec($this->preferences
->pref_card_hcol
);
112 $this->preferences
->pref_card_marges_h
,
113 $this->preferences
->pref_card_marges_v
117 $this->SetFont(self
::FONT
);
121 $this->xorigin
= $this->preferences
->pref_card_marges_h
;
122 $this->yorigin
= $this->preferences
->pref_card_marges_v
;
125 $this->wi
= self
::getWidth();
127 $this->he
= self
::getHeight();
129 $this->nbcol
= self
::getCols();
131 $this->nbrow
= self
::getRows();
132 // Spacing between cards
133 $this->hspacing
= $this->preferences
->pref_card_hspace
;
134 $this->vspacing
= $this->preferences
->pref_card_vspace
;
136 //maximum size for visible text. May vary with fonts.
137 $this->max_text_size
= 80;
138 $this->year_font_size
= 8;
140 // Get fixed data from preferences
141 $this->an_cot
= $this->preferences
->pref_card_year
;
142 $this->abrev
= $this->preferences
->pref_card_abrev
;
144 $print_logo = new PrintLogo();
145 $this->logofile
= $print_logo->getPath();
147 // Set logo size to max width 30mm (113px) or max height 17mm (64px)
148 $ratio = $print_logo->getWidth() / $print_logo->getHeight();
150 if ($print_logo->getHeight() > 64) {
153 // Convert original pixels size to millimeters
154 $this->hlogo
= $print_logo->getHeight() / 3.78;
156 $this->wlogo
= round($this->hlogo
* $ratio);
158 if ($print_logo->getWidth() > 113) {
161 // Convert original pixels size to millimeters
162 $this->wlogo
= $print_logo->getWidth() / 3.78;
164 $this->hlogo
= round($this->wlogo
/ $ratio);
171 * @param array<Adherent> $members Members
175 public function drawCards(array $members): void
178 foreach ($members as $member) {
179 // Detect page breaks
180 if ($nb_card %
($this->nbcol
* $this->nbrow
) == 0) {
184 // Compute card position on page
185 $col = $nb_card %
$this->nbcol
;
186 $row = (int)(($nb_card / $this->nbcol
)) %
$this->nbrow
;
188 $x0 = $this->xorigin +
$col * (round($this->wi
) +
round($this->hspacing
));
189 $y0 = $this->yorigin +
$row * (round($this->he
) +
round($this->vspacing
));
191 $xl = round($x0 +
$this->wi
- $this->wlogo
);
194 switch ($this->preferences
->pref_card_address
) {
196 $email .= $member->email
;
199 $email .= $member->zipcode
. ' - ' . $member->town
;
202 $email .= $member->nickname
;
205 $email .= $member->job
;
208 $email .= $member->number
;
212 // Select strip color according to status
213 switch ($member->status
) {
229 if ($this->preferences
->pref_bool_display_title
) {
230 $nom_adh_ext .= $member->stitle
;
232 $nom_adh_ext .= $member->sname
;
233 $photo = $member->picture
;
234 $photofile = $photo->getPath();
236 // Photo 100x130 and logo
237 $this->Image($photofile, $x0, $y0, 25);
238 $this->Image($this->logofile
, $xl, $y0, round($this->wlogo
));
240 // Color=#8C8C8C: Shadow of the year
241 $this->SetTextColor(140);
242 $this->SetFontSize($this->year_font_size
);
244 $an_cot = $this->an_cot
;
245 if ($an_cot === 'DEADLINE') {
246 //get current member deadline
247 $an_cot = $member->due_date
;
250 $xan_cot = $x0 +
$this->wi
- $this->GetStringWidth(
254 $this->year_font_size
256 $this->SetXY($xan_cot, $y0 +
$this->hlogo
- 0.3);
257 $this->writeHTML('<strong>' . $an_cot . '</strong>', false, false);
259 // Colored Text (Big label, id, year)
260 $this->SetTextColor($fcol['R'], $fcol['G'], $fcol['B']);
262 $this->SetFontSize(8);
264 if (!empty($this->preferences
->pref_show_id
) ||
!empty($member->number
)) {
265 $member_id = (!empty($member->number
)) ?
$member->number
: $member->id
;
266 $xid = $x0 +
$this->wi
- $this->GetStringWidth($member_id, self
::FONT
, 'B', 8) - 0.2;
267 $this->SetXY($xid, $y0 +
28);
268 $this->writeHTML('<strong>' . $member_id . '</strong>', false, false);
270 $this->SetFontSize($this->year_font_size
);
271 $xan_cot = $xan_cot - 0.3;
272 $this->SetXY($xan_cot, $y0 +
$this->hlogo
- 0.3);
273 $this->writeHTML('<strong>' . $an_cot . '</strong>', false, false);
275 // Abbrev: Adapt font size to text length
278 $this->max_text_size
,
282 $this->SetXY($x0 +
27, $y0 +
12);
283 $this->writeHTML('<strong>' . $this->abrev
. '</strong>', true, false);
285 // Name: Adapt font size to text length
286 $this->SetTextColor(0);
289 $this->max_text_size
,
293 $this->SetXY($x0 +
27, $this->getY() +
4);
294 //$this->setX($x0 + 27);
295 $this->writeHTML('<strong>' . $nom_adh_ext . '</strong>', true, false);
300 $this->max_text_size
,
304 $this->setX($x0 +
27);
305 $this->writeHTML('<strong>' . $email . '</strong>', false, false);
307 // Lower colored strip with long text
308 $this->SetFillColor($fcol['R'], $fcol['G'], $fcol['B']);
314 $this->SetFont(self
::FONT
, 'B', 6);
315 $this->SetXY($x0, $y0 +
33);
319 $this->preferences
->pref_card_strip
,
326 // Draw a gray frame around the card
327 $this->Rect($x0, $y0, $this->wi
, $this->he
);
337 public static function getWidth(): int
339 return defined('GALETTE_CARD_WIDTH') ? GALETTE_CARD_WIDTH
: self
::WIDTH
;
347 public static function getHeight(): int
349 return defined('GALETTE_CARD_HEIGHT') ? GALETTE_CARD_HEIGHT
: self
::HEIGHT
;
353 * Get number of columns
357 public static function getCols(): int
359 return defined('GALETTE_CARD_COLS') ? GALETTE_CARD_COLS
: self
::COLS
;
367 public static function getRows(): int
369 return defined('GALETTE_CARD_ROWS') ? GALETTE_CARD_ROWS
: self
::ROWS
;