]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/IO/PdfMembersCards.php
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2021 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 2021 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.8.2dev - 2014-11-30
39 use Galette\Core\Preferences
;
40 use Galette\Core\PrintLogo
;
49 * @abstract Class for expanding TCPDF.
50 * @author Johan Cwiklinski <johan@x-tnd.be>
51 * @copyright 2021 The Galette Team
52 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
53 * @link http://galette.tuxfamily.org
54 * @since Available since 0.8.2dev - 2014-11-30
57 class PdfMembersCards
extends Pdf
59 public const WIDTH
= 75;
60 public const HEIGHT
= 40;
61 public const COLS
= 2;
62 public const ROWS
= 6;
76 private $max_text_size;
77 private $year_font_size;
85 * Main constructor, set creator and author
87 * @param Preferences $prefs Preferences
89 public function __construct(Preferences
$prefs)
91 parent
::__construct($prefs);
93 $this->filename
= __('cards') . '.pdf';
101 private function init()
103 // Set document information
104 $this->SetTitle(_T("Member's Cards"));
105 $this->SetSubject(_T("Generated by Galette"));
106 $this->SetKeywords(_T("Cards"));
108 // No hearders and footers
109 $this->SetPrintHeader(false);
110 $this->SetPrintFooter(false);
111 $this->setFooterMargin(0);
112 $this->setHeaderMargin(0);
115 $this->SetDisplayMode('fullpage');
117 // Disable Auto Page breaks
118 $this->SetAutoPageBreak(false, 0);
121 $this->SetDrawColor(160, 160, 160);
122 $this->SetTextColor(0);
123 $this->tcol
= $this->colorHex2Dec($this->preferences
->pref_card_tcol
);
124 $this->scol
= $this->colorHex2Dec($this->preferences
->pref_card_scol
);
125 $this->bcol
= $this->colorHex2Dec($this->preferences
->pref_card_bcol
);
126 $this->hcol
= $this->colorHex2Dec($this->preferences
->pref_card_hcol
);
130 $this->preferences
->pref_card_marges_h
,
131 $this->preferences
->pref_card_marges_v
135 $this->SetFont(self
::FONT
);
139 $this->xorigin
= $this->preferences
->pref_card_marges_h
;
140 $this->yorigin
= $this->preferences
->pref_card_marges_v
;
143 $this->wi
= self
::getWidth();
145 $this->he
= self
::getHeight();
147 $this->nbcol
= self
::getCols();
149 $this->nbrow
= self
::getRows();
150 // Spacing between cards
151 $this->hspacing
= $this->preferences
->pref_card_hspace
;
152 $this->vspacing
= $this->preferences
->pref_card_vspace
;
154 //maximum size for visible text. May vary with fonts.
155 $this->max_text_size
= 80;
156 $this->year_font_size
= 8;
158 // Get fixed data from preferences
159 $this->an_cot
= $this->preferences
->pref_card_year
;
160 $this->abrev
= $this->preferences
->pref_card_abrev
;
162 $print_logo = new PrintLogo();
163 $this->logofile
= $print_logo->getPath();
165 // Set logo size to max width 30 mm or max height 25 mm
166 $ratio = $print_logo->getWidth() / $print_logo->getHeight();
168 if ($print_logo->getHeight() > 16) {
171 $this->hlogo
= $print_logo->getHeight();
173 $this->wlogo
= round($this->hlogo
* $ratio);
175 if ($print_logo->getWidth() > 16) {
178 $this->wlogo
= $print_logo->getWidth();
180 $this->hlogo
= round($this->wlogo
/ $ratio);
187 * @param array $members Members
191 public function drawCards($members)
194 foreach ($members as $member) {
195 // Detect page breaks
196 if ($nb_card %
($this->nbcol
* $this->nbrow
) == 0) {
200 // Compute card position on page
201 $col = $nb_card %
$this->nbcol
;
202 $row = ($nb_card / $this->nbcol
) %
$this->nbrow
;
204 $x0 = $this->xorigin +
$col * (round($this->wi
) +
round($this->hspacing
));
205 $y0 = $this->yorigin +
$row * (round($this->he
) +
round($this->vspacing
));
207 $xl = round($x0 +
$this->wi
- $this->wlogo
);
210 switch ($this->preferences
->pref_card_address
) {
212 $email .= $member->email
;
215 $email .= $member->zipcode
. ' - ' . $member->town
;
218 $email .= $member->nickname
;
221 $email .= $member->job
;
224 $email .= $member->number
;
228 // Select strip color according to status
229 switch ($member->status
) {
245 if ($this->preferences
->pref_bool_display_title
) {
246 $nom_adh_ext .= $member->stitle
;
248 $nom_adh_ext .= $member->sname
;
249 $photo = $member->picture
;
250 $photofile = $photo->getPath();
252 // Photo 100x130 and logo
253 $this->Image($photofile, $x0, $y0, 25);
254 $this->Image($this->logofile
, $xl, $y0, round($this->wlogo
));
256 // Color=#8C8C8C: Shadow of the year
257 $this->SetTextColor(140);
258 $this->SetFontSize($this->year_font_size
);
260 $an_cot = $this->an_cot
;
261 if ($an_cot === 'DEADLINE') {
262 //get current member deadline
263 $an_cot = $member->due_date
;
266 $xan_cot = $x0 +
$this->wi
- $this->GetStringWidth(
270 $this->year_font_size
272 $this->SetXY($xan_cot, $y0 +
$this->hlogo
- 0.3);
273 $this->writeHTML('<strong>' . $an_cot . '</strong>', false, 0);
275 // Colored Text (Big label, id, year)
276 $this->SetTextColor($fcol['R'], $fcol['G'], $fcol['B']);
278 $this->SetFontSize(8);
280 $xid = $x0 +
$this->wi
- $this->GetStringWidth($member->id
, self
::FONT
, 'B', 8) - 0.2;
281 $this->SetXY($xid, $y0 +
28);
282 $this->writeHTML('<strong>' . $member->id
. '</strong>', false, 0);
283 $this->SetFontSize($this->year_font_size
);
284 $xan_cot = $xan_cot - 0.3;
285 $this->SetXY($xan_cot, $y0 +
$this->hlogo
- 0.3);
286 $this->writeHTML('<strong>' . $an_cot . '</strong>', false, 0);
288 // Abbrev: Adapt font size to text length
291 $this->max_text_size
,
295 $this->SetXY($x0 +
27, $y0 +
12);
296 $this->writeHTML('<strong>' . $this->abrev
. '</strong>', true, 0);
298 // Name: Adapt font size to text length
299 $this->SetTextColor(0);
302 $this->max_text_size
,
306 $this->SetXY($x0 +
27, $this->getY() +
4);
307 //$this->setX($x0 + 27);
308 $this->writeHTML('<strong>' . $nom_adh_ext . '</strong>', true, 0);
313 $this->max_text_size
,
317 $this->setX($x0 +
27);
318 $this->writeHTML('<strong>' . $email . '</strong>', false, 0);
320 // Lower colored strip with long text
321 $this->SetFillColor($fcol['R'], $fcol['G'], $fcol['B']);
327 $this->SetFont(self
::FONT
, 'B', 6);
328 $this->SetXY($x0, $y0 +
33);
332 $this->preferences
->pref_card_strip
,
339 // Draw a gray frame around the card
340 $this->Rect($x0, $y0, $this->wi
, $this->he
);
350 public static function getWidth()
352 return defined('GALETTE_CARD_WIDTH') ? GALETTE_CARD_WIDTH
: self
::WIDTH
;
360 public static function getHeight()
362 return defined('GALETTE_CARD_HEIGHT') ? GALETTE_CARD_HEIGHT
: self
::HEIGHT
;
366 * Get number of columns
370 public static function getCols()
372 return defined('GALETTE_CARD_COLS') ? GALETTE_CARD_COLS
: self
::COLS
;
380 public static function getRows()
382 return defined('GALETTE_CARD_ROWS') ? GALETTE_CARD_ROWS
: self
::ROWS
;