3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * @copyright CiviCRM LLC (c) 2004-2013
35 * Class CRM_Badge_Format_Badge
37 * parent class for building name badges
39 class CRM_Badge_BAO_Badge
{
41 public $debug = FALSE;
46 * This function is called to create name label pdf
48 * @param array $participants associated array with participant info
49 * @param array $layoutInfo associated array which contains meta data about format/layout
54 public function createLabels(&$participants, &$layoutInfo) {
55 $this->pdf
= new CRM_Utils_PDF_Label($layoutInfo['format'], 'mm');
57 $this->pdf
->setPrintHeader(FALSE);
58 $this->pdf
->setPrintFooter(FALSE);
59 $this->pdf
->AddPage();
60 $this->pdf
->SetGenerator($this, "generateLabel");
62 // this is very useful for debugging, by default set to FALSE
64 $this->border
= "LTRB";
67 foreach ($participants as $participant) {
68 $formattedRow = self
::formatLabel($participant, $layoutInfo);
69 $this->pdf
->AddPdfLabel($formattedRow);
72 $this->pdf
->Output(CRM_Utils_String
::munge($layoutInfo['title'], '_', 64) . '.pdf', 'D');
73 CRM_Utils_System
::civiExit(1);
77 * Funtion to create structure and add meta data according to layout
79 * @param array $row row element that needs to be formatted
80 * @param array $layout layout meta data
82 * @return array $formattedRow row with meta data
84 static function formatLabel(&$row, &$layout) {
85 $formattedRow = array('labelFormat' => $layout['label_format_name']);
87 if (CRM_Utils_Array
::value('rowElements', $layout['data'])) {
88 foreach ($layout['data']['rowElements'] as $key => $element) {
91 $value = $row[$element];
92 // hack to fix date field display format
93 if (strpos($element, '_date')) {
94 $value = CRM_Utils_Date
::customFormat($value, "%e %b");
98 $formattedRow['token'][$key] = array(
100 'font_name' => $layout['data']['font_name'][$key],
101 'font_size' => $layout['data']['font_size'][$key],
102 'text_alignment' => $layout['data']['text_alignment'][$key],
107 if (CRM_Utils_Array
::value('image_1', $layout['data'])) {
108 $formattedRow['image_1'] = $layout['data']['image_1'];
111 if (CRM_Utils_Array
::value('image_2', $layout['data'])) {
112 $formattedRow['image_2'] = $layout['data']['image_2'];
115 if (CRM_Utils_Array
::value('add_barcode', $layout['data'])) {
116 $formattedRow['barcode'] = $layout['data']['barcode_alignment'];
119 // finally assign all the row values, so that we can use it for barcode etc
120 $formattedRow['values'] = $row;
122 return $formattedRow;
125 public function generateLabel($formattedRow) {
126 switch ($formattedRow['labelFormat']) {
128 self
::labelAvery5395($formattedRow);
133 public function labelAvery5395(&$formattedRow) {
134 $this->lMarginLogo
= 18;
135 $this->tMarginName
= 20;
137 $x = $this->pdf
->GetAbsX();
138 $y = $this->pdf
->GetY();
140 $titleWidth = $titleLeftMargin = 0;
141 if (CRM_Utils_Array
::value('image_1', $formattedRow)) {
142 $this->printImage($formattedRow['image_1']);
143 $titleWidth = $titleLeftMargin = $this->lMarginLogo
;
146 $titleRightMargin = 0;
147 if (CRM_Utils_Array
::value('image_2', $formattedRow)) {
148 $this->printImage($formattedRow['image_2'], $x +
68);
149 $titleRightMargin = 36;
150 $titleWidth = $this->lMarginLogo
;
153 $this->pdf
->SetLineStyle(array(
158 'color' => array(0, 0, 200)
161 if ($titleLeftMargin && $titleRightMargin) {
162 $titleWidth = $titleRightMargin;
165 $this->pdf
->SetFont($formattedRow['token'][1]['font_name'], '', $formattedRow['token'][1]['font_size']);
166 $this->pdf
->MultiCell($this->pdf
->width
- $titleWidth, 0, $formattedRow['token'][1]['value'],
167 $this->border
, $formattedRow['token'][1]['text_alignment'], 0, 1, $x +
$titleLeftMargin, $y);
169 $this->pdf
->SetFont($formattedRow['token'][2]['font_name'], '', $formattedRow['token'][2]['font_size']);
170 $this->pdf
->MultiCell($this->pdf
->width
, 10, $formattedRow['token'][2]['value'],
171 $this->border
, $formattedRow['token'][2]['text_alignment'], 0, 1, $x, $y +
$this->tMarginName
);
173 $this->pdf
->SetFont($formattedRow['token'][3]['font_name'], '', $formattedRow['token'][3]['font_size']);
174 $this->pdf
->MultiCell($this->pdf
->width
, 0, $formattedRow['token'][3]['value'],
175 $this->border
, $formattedRow['token'][3]['text_alignment'], 0, 1, $x, $this->pdf
->getY());
177 $this->pdf
->SetFont($formattedRow['token'][4]['font_name'], '', $formattedRow['token'][4]['font_size']);
178 $this->pdf
->MultiCell($this->pdf
->width
, 0, $formattedRow['token'][4]['value'],
179 $this->border
, $formattedRow['token'][4]['text_alignment'], 0, 1, $x, $y +
$this->pdf
->height
- 5);
181 if (CRM_Utils_Array
::value('barcode', $formattedRow)) {
187 'cellfitalign' => '',
190 'vpadding' => 'auto',
191 'fgcolor' => array(0, 0, 0),
194 'font' => 'helvetica',
201 if ($formattedRow['barcode'] == 'L') {
204 elseif ($formattedRow['barcode'] == 'R') {
207 elseif ($formattedRow['barcode'] == 'C') {
211 $data = $formattedRow['values'];
212 $data['current_value'] = $formattedRow['values']['contact_id'] . '-' . $formattedRow['values']['participant_id'];
214 // call hook alterBarcode
215 CRM_Utils_Hook
::alterBarcode($data);
217 $this->pdf
->write1DBarcode($data['current_value'], 'C128', $xAlign, $y +
$this->pdf
->height
- 10, '',
218 12, 0.4, $style, 'B');
223 * Helper function to print images
224 * @param string $img image url
229 function printImage($img, $x = '', $y = '') {
231 $x = $this->pdf
->GetAbsX();
235 $y = $this->pdf
->GetY();
241 $imgsize = getimagesize($img);
243 $f = $this->imgRes
/ 25.4;
244 $w = $imgsize[0] / $f;
245 $h = $imgsize[1] / $f;
246 $this->pdf
->Image($img, $x, $y, $w, $h, '', '', '', FALSE, 72, '', FALSE,
247 FALSE, $this->debug
, FALSE, FALSE, FALSE);
249 $this->pdf
->SetXY($x, $y);