3 +--------------------------------------------------------------------+
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 +--------------------------------------------------------------------+
27 * Copyright (C) 2010 Tech To The People
28 * Licensed to CiviCRM under the Academic Free License version 3.0.
35 * @copyright CiviCRM LLC https://civicrm.org/licensing
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
45 class CRM_Event_Badge
{
49 public function __construct() {
55 'color' => [0, 0, 200],
57 $this->format
= '5160';
58 $this->imgExtension
= 'png';
61 $this->setDebug(FALSE);
67 public function setDebug($debug = TRUE) {
74 $this->border
= "LTRB";
79 * Create the labels (pdf).
81 * It assumes the participants are from the same event
83 * @param array $participants
85 public function run(&$participants) {
86 // fetch the 1st participant, and take her event to retrieve its attributes
87 $participant = reset($participants);
88 $eventID = $participant['event_id'];
89 $this->event
= self
::retrieveEvent($eventID);
90 //call function to create labels
91 self
::createLabels($participants);
92 CRM_Utils_System
::civiExit();
98 * @return CRM_Event_BAO_Event|null
100 protected function retrieveEvent($eventID) {
101 $bao = new CRM_Event_BAO_Event();
102 if ($bao->get('id', $eventID)) {
109 * @param int $eventID
114 public function getImageFileName($eventID, $img = FALSE) {
115 global $civicrm_root;
116 $path = "CRM/Event/Badge";
121 $img = get_class($this) . "." . $this->imgExtension
;
124 // CRM-13235 - leverage the Smarty path to get all templates directories
125 $template = CRM_Core_Smarty
::singleton();
126 if (isset($template->template_dir
) && $template->template_dir
) {
127 $dirs = is_array($template->template_dir
) ?
$template->template_dir
: [$template->template_dir
];
128 foreach ($dirs as $dir) {
129 foreach (["$dir/$path/$eventID/$img", "$dir/$path/$img"] as $imgFile) {
130 if (file_exists($imgFile)) {
137 $imgFile = 'No template directories defined anywhere??';
140 // not sure it exists, but at least will display a meaniful fatal error in debug mode
147 public function printBackground($img = FALSE) {
148 $x = $this->pdf
->GetAbsX();
149 $y = $this->pdf
->GetY();
151 $this->pdf
->Rect($x, $y, $this->pdf
->width
, $this->pdf
->height
, 'D', [
157 'color' => [255, 0, 0],
161 $img = $this->getImageFileName($this->event
->id
, $img);
163 $imgsize = getimagesize($img);
165 $f = $this->imgRes
/ 25.4;
166 $w = $imgsize[0] / $f;
167 $h = $imgsize[1] / $f;
168 $this->pdf
->Image($img, $this->pdf
->GetAbsX(), $this->pdf
->GetY(), $w, $h, strtoupper($this->imgExtension
), '', '', FALSE, 72, '', FALSE, FALSE, $this->debug
, FALSE, FALSE, FALSE);
170 $this->pdf
->SetXY($x, $y);
174 * This is supposed to be overridden.
176 * @param array $participant
178 public function generateLabel($participant) {
179 $txt = "{$this->event['title']}
180 {$participant['display_name']}
181 {$participant['current_employer']}";
183 $this->pdf
->MultiCell($this->pdf
->width
, $this->pdf
->lineHeight
, $txt);
186 public function pdfExtraFormat() {
190 * Create labels (pdf).
192 * @param array $participants
194 public function createLabels(&$participants) {
196 $this->pdf
= new CRM_Utils_PDF_Label($this->format
, 'mm');
197 $this->pdfExtraFormat();
199 $this->pdf
->setPrintHeader(FALSE);
200 $this->pdf
->setPrintFooter(FALSE);
201 $this->pdf
->AddPage();
202 $this->pdf
->AddFont('DejaVu Sans', '', 'DejaVuSans.php');
203 $this->pdf
->SetFont('DejaVu Sans');
204 $this->pdf
->SetGenerator($this, "generateLabel");
206 foreach ($participants as $participant) {
207 $this->pdf
->AddPdfLabel($participant);
209 $this->pdf
->Output($this->event
->title
. '.pdf', 'D');