Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | This file is a part of CiviCRM. | | |
7 | | | | |
8 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
9 | | under the terms of the GNU Affero General Public License | | |
10 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
11 | | | | |
12 | | CiviCRM is distributed in the hope that it will be useful, but | | |
13 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
14 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
15 | | See the GNU Affero General Public License for more details. | | |
16 | | | | |
17 | | You should have received a copy of the GNU Affero General Public | | |
18 | | License and the CiviCRM Licensing Exception along | | |
19 | | with this program; if not, contact CiviCRM LLC | | |
20 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
21 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
22 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
23 | +--------------------------------------------------------------------+ | |
d25dd0ee | 24 | */ |
6a488035 TO |
25 | |
26 | /* | |
e70a7fc0 TO |
27 | * Copyright (C) 2010 Tech To The People |
28 | * Licensed to CiviCRM under the Academic Free License version 3.0. | |
29 | * | |
30 | */ | |
6a488035 TO |
31 | |
32 | /** | |
33 | * | |
34 | * @package CRM | |
8c9251b3 | 35 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
36 | * $Id$ |
37 | * | |
38 | */ | |
39 | ||
40 | /** | |
41 | * This class print the name badges for the participants | |
42 | * It isn't supposed to be called directly, but is the parent class of the classes in CRM/Event/Badges/XXX.php | |
43 | * | |
44 | */ | |
45 | class CRM_Event_Badge { | |
0cf587a7 | 46 | /** |
0cf587a7 | 47 | */ |
00be9182 | 48 | public function __construct() { |
353ffa53 TO |
49 | $this->style = array( |
50 | 'width' => 0.1, | |
51 | 'cap' => 'round', | |
52 | 'join' => 'round', | |
53 | 'dash' => '2,2', | |
d5cc0fc2 | 54 | 'color' => array(0, 0, 200), |
353ffa53 TO |
55 | ); |
56 | $this->format = '5160'; | |
6a488035 | 57 | $this->imgExtension = 'png'; |
353ffa53 TO |
58 | $this->imgRes = 300; |
59 | $this->event = NULL; | |
6a488035 TO |
60 | $this->setDebug(FALSE); |
61 | } | |
62 | ||
0cf587a7 EM |
63 | /** |
64 | * @param bool $debug | |
65 | */ | |
00be9182 | 66 | public function setDebug($debug = TRUE) { |
6a488035 TO |
67 | if (!$debug) { |
68 | $this->debug = FALSE; | |
69 | $this->border = 0; | |
70 | } | |
71 | else { | |
72 | $this->debug = TRUE; | |
73 | $this->border = "LTRB"; | |
74 | } | |
75 | } | |
76 | ||
77 | /** | |
54957108 | 78 | * Create the labels (pdf). |
79 | * | |
6a488035 TO |
80 | * It assumes the participants are from the same event |
81 | * | |
d4dd1e85 | 82 | * @param array $participants |
6a488035 TO |
83 | */ |
84 | public function run(&$participants) { | |
85 | // fetch the 1st participant, and take her event to retrieve its attributes | |
86 | $participant = reset($participants); | |
353ffa53 | 87 | $eventID = $participant['event_id']; |
6a488035 TO |
88 | $this->event = self::retrieveEvent($eventID); |
89 | //call function to create labels | |
90 | self::createLabels($participants); | |
292c8687 | 91 | CRM_Utils_System::civiExit(); |
6a488035 TO |
92 | } |
93 | ||
0cf587a7 | 94 | /** |
100fef9d | 95 | * @param int $eventID |
0cf587a7 EM |
96 | * |
97 | * @return CRM_Event_BAO_Event|null | |
98 | */ | |
6a488035 TO |
99 | protected function retrieveEvent($eventID) { |
100 | $bao = new CRM_Event_BAO_Event(); | |
101 | if ($bao->get('id', $eventID)) { | |
102 | return $bao; | |
103 | } | |
104 | return NULL; | |
105 | } | |
106 | ||
0cf587a7 | 107 | /** |
100fef9d | 108 | * @param int $eventID |
0cf587a7 EM |
109 | * @param bool $img |
110 | * | |
111 | * @return string | |
112 | */ | |
00be9182 | 113 | public function getImageFileName($eventID, $img = FALSE) { |
6a488035 TO |
114 | global $civicrm_root; |
115 | $path = "CRM/Event/Badge"; | |
116 | if ($img == FALSE) { | |
117 | return FALSE; | |
118 | } | |
119 | if ($img == TRUE) { | |
120 | $img = get_class($this) . "." . $this->imgExtension; | |
121 | } | |
122 | ||
81733948 DG |
123 | // CRM-13235 - leverage the Smarty path to get all templates directories |
124 | $template = CRM_Core_Smarty::singleton(); | |
125 | if (isset($template->template_dir) && $template->template_dir) { | |
481a74f4 | 126 | $dirs = is_array($template->template_dir) ? $template->template_dir : array($template->template_dir); |
81733948 | 127 | foreach ($dirs as $dir) { |
481a74f4 | 128 | foreach (array("$dir/$path/$eventID/$img", "$dir/$path/$img") as $imgFile) { |
81733948 DG |
129 | if (file_exists($imgFile)) { |
130 | return $imgFile; | |
131 | } | |
132 | } | |
133 | } | |
0db6c3e1 TO |
134 | } |
135 | else { | |
81733948 | 136 | $imgFile = 'No template directories defined anywhere??'; |
6a488035 TO |
137 | } |
138 | ||
139 | // not sure it exists, but at least will display a meaniful fatal error in debug mode | |
140 | return $imgFile; | |
141 | } | |
142 | ||
0cf587a7 EM |
143 | /** |
144 | * @param bool $img | |
145 | */ | |
00be9182 | 146 | public function printBackground($img = FALSE) { |
6a488035 TO |
147 | $x = $this->pdf->GetAbsX(); |
148 | $y = $this->pdf->GetY(); | |
149 | if ($this->debug) { | |
353ffa53 TO |
150 | $this->pdf->Rect($x, $y, $this->pdf->width, $this->pdf->height, 'D', array( |
151 | 'all' => array( | |
152 | 'width' => 1, | |
153 | 'cap' => 'round', | |
154 | 'join' => 'round', | |
155 | 'dash' => '2,10', | |
d5cc0fc2 | 156 | 'color' => array(255, 0, 0), |
157 | ), | |
353ffa53 | 158 | )); |
6a488035 TO |
159 | } |
160 | $img = $this->getImageFileName($this->event->id, $img); | |
161 | if ($img) { | |
162 | $imgsize = getimagesize($img); | |
163 | // mm | |
164 | $f = $this->imgRes / 25.4; | |
165 | $w = $imgsize[0] / $f; | |
166 | $h = $imgsize[1] / $f; | |
167 | $this->pdf->Image($img, $this->pdf->GetAbsX(), $this->pdf->GetY(), $w, $h, strtoupper($this->imgExtension), '', '', FALSE, 72, '', FALSE, FALSE, $this->debug, FALSE, FALSE, FALSE); | |
168 | } | |
169 | $this->pdf->SetXY($x, $y); | |
170 | } | |
171 | ||
172 | /** | |
ea3ddccf | 173 | * This is supposed to be overridden. |
174 | * | |
175 | * @param array $participant | |
d5cc0fc2 | 176 | */ |
6a488035 TO |
177 | public function generateLabel($participant) { |
178 | $txt = "{$this->event['title']} | |
179 | {$participant['display_name']} | |
180 | {$participant['current_employer']}"; | |
181 | ||
182 | $this->pdf->MultiCell($this->pdf->width, $this->pdf->lineHeight, $txt); | |
183 | } | |
184 | ||
0479b4c8 TO |
185 | public function pdfExtraFormat() { |
186 | } | |
6a488035 TO |
187 | |
188 | /** | |
ad37ac8e | 189 | * Create labels (pdf). |
6a488035 | 190 | * |
c490a46a | 191 | * @param array $participants |
6a488035 | 192 | */ |
00be9182 | 193 | public function createLabels(&$participants) { |
6a488035 TO |
194 | |
195 | $this->pdf = new CRM_Utils_PDF_Label($this->format, 'mm'); | |
196 | $this->pdfExtraFormat(); | |
197 | $this->pdf->Open(); | |
198 | $this->pdf->setPrintHeader(FALSE); | |
199 | $this->pdf->setPrintFooter(FALSE); | |
200 | $this->pdf->AddPage(); | |
201 | $this->pdf->AddFont('DejaVu Sans', '', 'DejaVuSans.php'); | |
202 | $this->pdf->SetFont('DejaVu Sans'); | |
203 | $this->pdf->SetGenerator($this, "generateLabel"); | |
204 | ||
205 | foreach ($participants as $participant) { | |
206 | $this->pdf->AddPdfLabel($participant); | |
207 | } | |
208 | $this->pdf->Output($this->event->title . '.pdf', 'D'); | |
209 | } | |
96025800 | 210 | |
6a488035 | 211 | } |