]>
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 © 2014 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 2014 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.8.2dev - 2014-11-30
40 use Galette\Core\Preferences
;
41 use Galette\Core\PrintLogo
;
50 * @abstract Class for expanding TCPDF.
51 * @author Johan Cwiklinski <johan@x-tnd.be>
52 * @copyright 2014 The Galette Team
53 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
54 * @link http://galette.tuxfamily.org
55 * @since Available since 0.8.2dev - 2014-11-30
58 class PdfMembersCards
extends Pdf
77 private $max_text_size;
78 private $year_font_size;
86 * Main constructor, set creator and author
88 * @param Preferences $prefs Preferences
90 public function __construct(Preferences
$prefs)
92 parent
::__construct($prefs);
94 $this->filename
= __('cards') . '.pdf';
102 private function init()
104 // Set document information
105 $this->SetTitle(_T("Member's Cards"));
106 $this->SetSubject(_T("Generated by Galette"));
107 $this->SetKeywords(_T("Cards"));
109 // No hearders and footers
110 $this->SetPrintHeader(false);
111 $this->SetPrintFooter(false);
112 $this->setFooterMargin(0);
113 $this->setHeaderMargin(0);
116 $this->SetDisplayMode('fullpage');
118 // Disable Auto Page breaks
119 $this->SetAutoPageBreak(false, 0);
122 $this->SetDrawColor(160, 160, 160);
123 $this->SetTextColor(0);
124 $this->tcol
= $this->colorHex2Dec($this->preferences
->pref_card_tcol
);
125 $this->scol
= $this->colorHex2Dec($this->preferences
->pref_card_scol
);
126 $this->bcol
= $this->colorHex2Dec($this->preferences
->pref_card_bcol
);
127 $this->hcol
= $this->colorHex2Dec($this->preferences
->pref_card_hcol
);
131 $this->preferences
->pref_card_marges_h
,
132 $this->preferences
->pref_card_marges_v
136 $this->SetFont(self
::FONT
);
140 $this->xorigin
= $this->preferences
->pref_card_marges_h
;
141 $this->yorigin
= $this->preferences
->pref_card_marges_v
;
144 $this->wi
= self
::getWidth();
146 $this->he
= self
::getHeight();
148 $this->nbcol
= self
::getCols();
150 $this->nbrow
= self
::getRows();
151 // Spacing betweeen cards
152 $this->hspacing
= $this->preferences
->pref_card_hspace
;
153 $this->vspacing
= $this->preferences
->pref_card_vspace
;
155 //maximum size for visible text. May vary with fonts.
156 $this->max_text_size
= 80;
157 $this->year_font_size
= 8;
159 // Get fixed data from preferences
160 $this->an_cot
= $this->preferences
->pref_card_year
;
161 $this->abrev
= $this->preferences
->pref_card_abrev
;
163 $print_logo = new PrintLogo();
164 $this->logofile
= $print_logo->getPath();
166 // Set logo size to max width 30 mm or max height 25 mm
167 $ratio = $print_logo->getWidth() / $print_logo->getHeight();
169 if ($print_logo->getHeight() > 16) {
172 $this->hlogo
= $print_logo->getHeight();
174 $this->wlogo
= round($this->hlogo
* $ratio);
176 if ($print_logo->getWidth() > 16) {
179 $this->wlogo
= $print_logo->getWidth();
181 $this->hlogo
= round($this->wlogo
/ $ratio);
188 * @param array $members Members
192 public function drawCards($members)
195 foreach ($members as $member) {
196 // Detect page breaks
197 if ($nb_card %
($this->nbcol
* $this->nbrow
) == 0) {
201 // Compute card position on page
202 $col = $nb_card %
$this->nbcol
;
203 $row = ($nb_card / $this->nbcol
) %
$this->nbrow
;
205 $x0 = $this->xorigin +
$col * (round($this->wi
) +
round($this->hspacing
));
206 $y0 = $this->yorigin +
$row * (round($this->he
) +
round($this->vspacing
));
208 $xl = round($x0 +
$this->wi
- $this->wlogo
);
211 switch ($this->preferences
->pref_card_address
) {
213 $email .= $member->email
;
216 $email .= $member->msn
;
219 $email .= $member->jabber
;
222 $email .= $member->website
;
225 $email .= $member->icq
;
228 $email .= $member->zipcode
. ' - ' . $member->town
;
231 $email .= $member->nickname
;
234 $email .= $member->job
;
238 // Select strip color according to status
239 switch ($member->status
) {
255 if ($this->preferences
->pref_bool_display_title
) {
256 $nom_adh_ext .= $member->stitle
;
258 $nom_adh_ext .= $member->sname
;
259 $photo = $member->picture
;
260 $photofile = $photo->getPath();
262 // Photo 100x130 and logo
263 $this->Image($photofile, $x0, $y0, 25);
264 $this->Image($this->logofile
, $xl, $y0, round($this->wlogo
));
266 // Color=#8C8C8C: Shadow of the year
267 $this->SetTextColor(140);
268 $this->SetFontSize($this->year_font_size
);
270 $an_cot = $this->an_cot
;
271 if ($an_cot === 'DEADLINE') {
272 //get current member deadline
273 $an_cot = $member->due_date
;
276 $xan_cot = $x0 +
$this->wi
- $this->GetStringWidth(
280 $this->year_font_size
282 $this->SetXY($xan_cot, $y0 +
$this->hlogo
- 0.3);
283 $this->writeHTML('<strong>' . $an_cot . '</strong>', false, 0);
285 // Colored Text (Big label, id, year)
286 $this->SetTextColor($fcol['R'], $fcol['G'], $fcol['B']);
288 $this->SetFontSize(8);
290 $xid = $x0 +
$this->wi
- $this->GetStringWidth($member->id
, self
::FONT
, 'B', 8) - 0.2;
291 $this->SetXY($xid, $y0 +
28);
292 $this->writeHTML('<strong>' . $member->id
. '</strong>', false, 0);
293 $this->SetFontSize($this->year_font_size
);
294 $xan_cot = $xan_cot - 0.3;
295 $this->SetXY($xan_cot, $y0 +
$this->hlogo
- 0.3);
296 $this->writeHTML('<strong>' . $an_cot . '</strong>', false, 0);
298 // Abbrev: Adapt font size to text length
301 $this->max_text_size
,
305 $this->SetXY($x0 +
27, $y0 +
12);
306 $this->writeHTML('<strong>' . $this->abrev
. '</strong>', true, 0);
308 // Name: Adapt font size to text length
309 $this->SetTextColor(0);
312 $this->max_text_size
,
316 $this->SetXY($x0 +
27, $this->getY() +
4);
317 //$this->setX($x0 + 27);
318 $this->writeHTML('<strong>' . $nom_adh_ext . '</strong>', true, 0);
323 $this->max_text_size
,
327 $this->setX($x0 +
27);
328 $this->writeHTML('<strong>' . $email . '</strong>', false, 0);
330 // Lower colored strip with long text
331 $this->SetFillColor($fcol['R'], $fcol['G'], $fcol['B']);
337 $this->SetFont(self
::FONT
, 'B', 6);
338 $this->SetXY($x0, $y0 +
33);
342 $this->preferences
->pref_card_strip
,
349 // Draw a gray frame around the card
350 $this->Rect($x0, $y0, $this->wi
, $this->he
);
360 public static function getWidth()
362 return defined('GALETTE_CARD_WIDTH') ? GALETTE_CARD_WIDTH
: self
::WIDTH
;
370 public static function getHeight()
372 return defined('GALETTE_CARD_HEIGHT') ? GALETTE_CARD_HEIGHT
: self
::HEIGHT
;
376 * Get number of columns
380 public static function getCols()
382 return defined('GALETTE_CARD_COLS') ? GALETTE_CARD_COLS
: self
::COLS
;
390 public static function getRows()
392 return defined('GALETTE_CARD_ROWS') ? GALETTE_CARD_ROWS
: self
::ROWS
;