Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
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 | +--------------------------------------------------------------------+ | |
24 | */ | |
25 | ||
26 | /* | |
27 | * Copyright (C) 2010 Tech To The People | |
28 | * Licensed to CiviCRM under the Academic Free License version 3.0. | |
29 | * | |
30 | */ | |
31 | ||
32 | /** | |
33 | * | |
34 | * @package CRM | |
35 | * @copyright CiviCRM LLC (c) 2004-2013 | |
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 { | |
46 | function __construct() { | |
47 | $this->style = array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,2', 'color' => array(0, 0, 200)); | |
48 | $this->format = '5160'; | |
49 | $this->imgExtension = 'png'; | |
50 | $this->imgRes = 300; | |
51 | $this->event = NULL; | |
52 | $this->setDebug(FALSE); | |
53 | } | |
54 | ||
55 | function setDebug($debug = TRUE) { | |
56 | if (!$debug) { | |
57 | $this->debug = FALSE; | |
58 | $this->border = 0; | |
59 | } | |
60 | else { | |
61 | $this->debug = TRUE; | |
62 | $this->border = "LTRB"; | |
63 | } | |
64 | } | |
65 | ||
66 | /** | |
67 | * function to create the labels (pdf) | |
68 | * It assumes the participants are from the same event | |
69 | * | |
70 | * @param array $participants | |
71 | * | |
72 | * @return null | |
73 | * @access public | |
74 | */ | |
75 | public function run(&$participants) { | |
76 | // fetch the 1st participant, and take her event to retrieve its attributes | |
77 | $participant = reset($participants); | |
78 | $eventID = $participant['event_id']; | |
79 | $this->event = self::retrieveEvent($eventID); | |
80 | //call function to create labels | |
81 | self::createLabels($participants); | |
82 | CRM_Utils_System::civiExit(1); | |
83 | } | |
84 | ||
85 | protected function retrieveEvent($eventID) { | |
86 | $bao = new CRM_Event_BAO_Event(); | |
87 | if ($bao->get('id', $eventID)) { | |
88 | return $bao; | |
89 | } | |
90 | return NULL; | |
91 | } | |
92 | ||
93 | function getImageFileName($eventID, $img = FALSE) { | |
94 | global $civicrm_root; | |
95 | $path = "CRM/Event/Badge"; | |
96 | if ($img == FALSE) { | |
97 | return FALSE; | |
98 | } | |
99 | if ($img == TRUE) { | |
100 | $img = get_class($this) . "." . $this->imgExtension; | |
101 | } | |
102 | ||
103 | $config = CRM_Core_Config::singleton(); | |
104 | $imgFile = $config->customTemplateDir . "/$path/$eventID/$img"; | |
105 | if (file_exists($imgFile)) { | |
106 | return $imgFile; | |
107 | } | |
108 | $imgFile = $config->customTemplateDir . "/$path/$img"; | |
109 | if (file_exists($imgFile)) { | |
110 | return $imgFile; | |
111 | } | |
112 | ||
113 | $imgFile = "$civicrm_root/templates/$path/$eventID/$img"; | |
114 | if (file_exists($imgFile)) { | |
115 | return $imgFile; | |
116 | } | |
117 | $imgFile = "$civicrm_root/templates/$path/$img"; | |
118 | if (!file_exists($imgFile) && !$this->debug) { | |
119 | return FALSE; | |
120 | } | |
121 | ||
122 | // not sure it exists, but at least will display a meaniful fatal error in debug mode | |
123 | return $imgFile; | |
124 | } | |
125 | ||
126 | function printBackground($img = FALSE) { | |
127 | $x = $this->pdf->GetAbsX(); | |
128 | $y = $this->pdf->GetY(); | |
129 | if ($this->debug) { | |
130 | $this->pdf->Rect($x, $y, $this->pdf->width, $this->pdf->height, 'D', array('all' => array('width' => 1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,10', 'color' => array(255, 0, 0)))); | |
131 | } | |
132 | $img = $this->getImageFileName($this->event->id, $img); | |
133 | if ($img) { | |
134 | $imgsize = getimagesize($img); | |
135 | // mm | |
136 | $f = $this->imgRes / 25.4; | |
137 | $w = $imgsize[0] / $f; | |
138 | $h = $imgsize[1] / $f; | |
139 | $this->pdf->Image($img, $this->pdf->GetAbsX(), $this->pdf->GetY(), $w, $h, strtoupper($this->imgExtension), '', '', FALSE, 72, '', FALSE, FALSE, $this->debug, FALSE, FALSE, FALSE); | |
140 | } | |
141 | $this->pdf->SetXY($x, $y); | |
142 | } | |
143 | ||
144 | /** | |
145 | * this is supposed to be overrided | |
146 | **/ | |
147 | public function generateLabel($participant) { | |
148 | $txt = "{$this->event['title']} | |
149 | {$participant['display_name']} | |
150 | {$participant['current_employer']}"; | |
151 | ||
152 | $this->pdf->MultiCell($this->pdf->width, $this->pdf->lineHeight, $txt); | |
153 | } | |
154 | ||
155 | function pdfExtraFormat() {} | |
156 | ||
157 | /** | |
158 | * function to create labels (pdf) | |
159 | * | |
160 | * @param array $contactRows assciated array of contact data | |
161 | * @param string $format format in which labels needs to be printed | |
162 | * | |
163 | * @return null | |
164 | * @access public | |
165 | */ | |
166 | function createLabels(&$participants) { | |
167 | ||
168 | $this->pdf = new CRM_Utils_PDF_Label($this->format, 'mm'); | |
169 | $this->pdfExtraFormat(); | |
170 | $this->pdf->Open(); | |
171 | $this->pdf->setPrintHeader(FALSE); | |
172 | $this->pdf->setPrintFooter(FALSE); | |
173 | $this->pdf->AddPage(); | |
174 | $this->pdf->AddFont('DejaVu Sans', '', 'DejaVuSans.php'); | |
175 | $this->pdf->SetFont('DejaVu Sans'); | |
176 | $this->pdf->SetGenerator($this, "generateLabel"); | |
177 | ||
178 | foreach ($participants as $participant) { | |
179 | $this->pdf->AddPdfLabel($participant); | |
180 | } | |
181 | $this->pdf->Output($this->event->title . '.pdf', 'D'); | |
182 | } | |
183 | } | |
184 |