]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/IO/PdfMembersLabels.php
31a179ef9a7467ddcb9a6101833757a85e24a005
[galette.git] / galette / lib / Galette / IO / PdfMembersLabels.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Member labels PDF
7 *
8 * PHP version 5
9 *
10 * Copyright © 2014 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
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.
18 *
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.
23 *
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/>.
26 *
27 * @category IO
28 * @package Galette
29 *
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
33 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.8.2dev - 2014-12-01
36 */
37
38 namespace Galette\IO;
39
40 use Galette\Core\Preferences;
41 use Analog\Analog;
42
43 /**
44 * Member labels PDF
45 *
46 * @category IO
47 * @name PDF
48 * @package Galette
49 * @abstract Class for expanding TCPDF.
50 * @author Johan Cwiklinski <johan@x-tnd.be>
51 * @copyright 2014 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-12-01
55 */
56
57 class PdfMembersLabels extends Pdf
58 {
59 private $xorigin;
60 private $yorigin;
61 private $lw;
62 private $lh;
63 private $line_h;
64
65 /**
66 * Main constructor, set creator and author
67 *
68 * @param Preferences $prefs Preferences
69 */
70 public function __construct(Preferences $prefs)
71 {
72 parent::__construct($prefs);
73 $this->setRTL(false);
74 $this->filename = __('labels_print_filename') . '.pdf';
75 $this->init();
76 }
77
78 /**
79 * Initialize PDF
80 *
81 * @return void
82 */
83 private function init()
84 {
85 // Set document information
86 $this->SetTitle(_T("Member's Labels"));
87 $this->SetSubject(_T("Generated by Galette"));
88 $this->SetKeywords(_T("Labels"));
89
90 // No hearders and footers
91 $this->SetPrintHeader(false);
92 $this->SetPrintFooter(false);
93 $this->setFooterMargin(0);
94 $this->setHeaderMargin(0);
95
96 // Show full page
97 $this->SetDisplayMode('fullpage');
98
99 // Disable Auto Page breaks
100 $this->SetAutoPageBreak(false, 0);
101
102 // Set colors
103 $this->SetDrawColor(160, 160, 160);
104 $this->SetTextColor(0);
105
106 // Set margins
107 $this->SetMargins(
108 $this->preferences->pref_etiq_marges_h,
109 $this->preferences->pref_etiq_marges_v
110 );
111
112 // Set font
113 //$this->SetFont(self::FONT);
114
115 // Set origin
116 // Top left corner
117 $this->xorigin = $this->preferences->pref_etiq_marges_h;
118 $this->yorigin = $this->preferences->pref_etiq_marges_v;
119
120 // Label width
121 $this->lw = round($this->preferences->pref_etiq_hsize);
122 // Label heigth
123 $this->lh = round($this->preferences->pref_etiq_vsize);
124 // Line heigth
125 $this->line_h=round($this->lh/5);
126 }
127
128 /**
129 * Draw members cards
130 *
131 * @param array $members Members
132 *
133 * @return void
134 */
135 public function drawLabels($members)
136 {
137 $nb_etiq=0;
138 foreach ($members as $member) {
139 // Detect page breaks
140 $colsrows = $this->preferences->pref_etiq_cols
141 * $this->preferences->pref_etiq_rows;
142 if ($nb_etiq % $colsrows == 0) {
143 $this->AddPage();
144 }
145 // Set font
146 $this->SetFont(self::FONT, 'B', $this->preferences->pref_etiq_corps);
147
148 // Compute label position
149 $col = $nb_etiq % $this->preferences->pref_etiq_cols;
150 $row = ($nb_etiq / $this->preferences->pref_etiq_cols)
151 % $this->preferences->pref_etiq_rows;
152 // Set label origin
153 $x = $this->xorigin + $col*(
154 round($this->preferences->pref_etiq_hsize) +
155 round($this->preferences->pref_etiq_hspace)
156 );
157 $y = $this->yorigin + $row*(
158 round($this->preferences->pref_etiq_vsize) +
159 round($this->preferences->pref_etiq_vspace)
160 );
161 // Draw a frame around the label
162 $this->Rect($x, $y, $this->lw, $this->lh);
163 // Print full name
164 $this->SetXY($x, $y);
165 $this->Cell($this->lw, $this->line_h, $member->sfullname, 0, 0, 'L', 0);
166 // Print first line of address
167 $this->SetFont(self::FONT, '', $this->preferences->pref_etiq_corps);
168 $this->SetXY($x, $y + $this->line_h);
169
170 //calculte font size to display address and address continuation
171 $max_text_size = $this->preferences->pref_etiq_hsize;
172 $text = mb_strlen($member->address) > mb_strlen($member->address_continuation) ?
173 $member->address :
174 $member->address_continuation;
175 $this->fixSize(
176 $text,
177 $max_text_size,
178 $this->preferences->pref_etiq_corps
179 );
180
181 $this->Cell($this->lw, $this->line_h, $member->address, 0, 0, 'L', 0);
182 // Print second line of address
183 $this->SetXY($x, $y + $this->line_h*2);
184 $this->Cell(
185 $this->lw,
186 $this->line_h,
187 $member->address_continuation,
188 0,
189 0,
190 'L',
191 0
192 );
193 // Print zip code and town
194 $this->SetFont(self::FONT, 'B', $this->preferences->pref_etiq_corps);
195 $text = $member->zipcode . ' - ' . $member->town;
196 $this->fixSize(
197 $text,
198 $max_text_size,
199 $this->preferences->pref_etiq_corps,
200 'B'
201 );
202
203 $this->SetXY($x, $y + $this->line_h*3);
204 $this->Cell(
205 $this->lw,
206 $this->line_h,
207 $text,
208 0,
209 0,
210 'L',
211 0
212 );
213 // Print country
214 $this->SetFont(self::FONT, 'I', $this->preferences->pref_etiq_corps);
215 $this->SetXY($x, $y + $this->line_h*4);
216 $this->Cell($this->lw, $this->line_h, $member->country, 0, 0, 'R', 0);
217 $nb_etiq++;
218 }
219 }
220 }