CRM-12966, added missing files
[civicrm-core.git] / CRM / Badge / Format / Badge.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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 *
28 * @package CRM
29 * @copyright CiviCRM LLC (c) 2004-2013
30 * $Id$
31 *
32 */
33
34 /**
35 * Class CRM_Badge_Format_Badge
36 *
37 * parent class for building name badges
38 */
39 class CRM_Badge_Format_Badge {
40 function printImage($img) {
41 $x = $this->pdf->GetAbsX();
42 $y = $this->pdf->GetY();
43
44 $this->imgRes = 300;
45
46 if ($img) {
47 $imgsize = getimagesize($img);
48 // mm
49 $f = $this->imgRes / 25.4;
50 $w = $imgsize[0] / $f;
51 $h = $imgsize[1] / $f;
52 $this->pdf->Image($img, $this->pdf->GetAbsX(), $this->pdf->GetY(), $w, $h, '', '', '', FALSE, 72, '', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE);
53 }
54 $this->pdf->SetXY($x, $y);
55 }
56
57 /**
58 * This function is called to create name label pdf
59 *
60 * @param array $participants associated array with participant info
61 * @param array $layoutInfo associated array which contains meta data about format/layout
62 *
63 * @return void
64 * @access public
65 */
66 function createLabels(&$participants, &$layoutInfo) {
67 $this->pdf = new CRM_Utils_PDF_Label($layoutInfo['format'], 'mm');
68 $this->pdf->Open();
69 $this->pdf->setPrintHeader(FALSE);
70 $this->pdf->setPrintFooter(FALSE);
71 $this->pdf->AddPage();
72 $this->pdf->AddFont('DejaVu Sans', '', 'DejaVuSans.php');
73 $this->pdf->SetFont('DejaVu Sans');
74 $this->pdf->SetGenerator($this, "generateLabel");
75
76 foreach ($participants as $participant) {
77 $formattedRow = self::formatLabel($participant, $layoutInfo);
78 $this->pdf->AddPdfLabel($formattedRow);
79 }
80
81 $this->pdf->Output(CRM_Utils_String::munge($layoutInfo['title'], '_', 64) . '.pdf', 'D');
82 CRM_Utils_System::civiExit(1);
83 }
84
85 /**
86 * Funtion to create structure and add meta data according to layout
87 *
88 * @param array $row row element that needs to be formatted
89 * @param array $layout layout meta data
90 *
91 * @return array $formattedRow row with meta data
92 */
93 static function formatLabel(&$row, &$layout) {
94 $formattedRow = array();
95 if (CRM_Utils_Array::value('rowElements', $layout['data'])) {
96 foreach($layout['data']['rowElements'] as $key => $element) {
97 $formattedRow['token'][$key] = array(
98 'value' => $row[$element],
99 'font_name' => $layout['data']['font_name'][$key],
100 'font_size' => $layout['data']['font_size'][$key],
101 'text_alignment' => $layout['data']['text_alignment'][$key],
102 );
103 }
104 }
105
106 if (CRM_Utils_Array::value('image_1', $layout['data'])) {
107 $formattedRow['image_1'] = $layout['data']['image_1'];
108 }
109
110 if (CRM_Utils_Array::value('image_2', $layout['data'])) {
111 $formattedRow['image_2'] = $layout['data']['image_2'];
112 }
113
114 if (CRM_Utils_Array::value('add_barcode', $layout['data'])) {
115 $formattedRow['barcode'] = $layout['data']['barcode_alignment'];
116 }
117
118 return $formattedRow;
119 }
120 }
121