3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Copyright (C) 2010 Tech To The People
14 * Licensed to CiviCRM under the Academic Free License version 3.0.
21 * @copyright CiviCRM LLC https://civicrm.org/licensing
25 * This class print the name badges for the participants
26 * It isn't supposed to be called directly, but is the parent class of the classes in CRM/Event/Badges/XXX.php
29 class CRM_Event_Badge
{
33 public function __construct() {
39 'color' => [0, 0, 200],
41 $this->format
= '5160';
42 $this->imgExtension
= 'png';
45 $this->setDebug(FALSE);
51 public function setDebug($debug = TRUE) {
58 $this->border
= "LTRB";
63 * Create the labels (pdf).
65 * It assumes the participants are from the same event
67 * @param array $participants
69 public function run(&$participants) {
70 // fetch the 1st participant, and take her event to retrieve its attributes
71 $participant = reset($participants);
72 $eventID = $participant['event_id'];
73 $this->event
= self
::retrieveEvent($eventID);
74 //call function to create labels
75 self
::createLabels($participants);
76 CRM_Utils_System
::civiExit();
82 * @return CRM_Event_BAO_Event|null
84 protected function retrieveEvent($eventID) {
85 $bao = new CRM_Event_BAO_Event();
86 if ($bao->get('id', $eventID)) {
98 public function getImageFileName($eventID, $img = FALSE) {
100 $path = "CRM/Event/Badge";
105 $img = get_class($this) . "." . $this->imgExtension
;
108 // CRM-13235 - leverage the Smarty path to get all templates directories
109 $template = CRM_Core_Smarty
::singleton();
110 if (isset($template->template_dir
) && $template->template_dir
) {
111 $dirs = is_array($template->template_dir
) ?
$template->template_dir
: [$template->template_dir
];
112 foreach ($dirs as $dir) {
113 foreach (["$dir/$path/$eventID/$img", "$dir/$path/$img"] as $imgFile) {
114 if (file_exists($imgFile)) {
121 $imgFile = 'No template directories defined anywhere??';
124 // not sure it exists, but at least will display a meaniful fatal error in debug mode
131 public function printBackground($img = FALSE) {
132 $x = $this->pdf
->GetAbsX();
133 $y = $this->pdf
->GetY();
135 $this->pdf
->Rect($x, $y, $this->pdf
->width
, $this->pdf
->height
, 'D', [
141 'color' => [255, 0, 0],
145 $img = $this->getImageFileName($this->event
->id
, $img);
147 $imgsize = getimagesize($img);
149 $f = $this->imgRes
/ 25.4;
150 $w = $imgsize[0] / $f;
151 $h = $imgsize[1] / $f;
152 $this->pdf
->Image($img, $this->pdf
->GetAbsX(), $this->pdf
->GetY(), $w, $h, strtoupper($this->imgExtension
), '', '', FALSE, 72, '', FALSE, FALSE, $this->debug
, FALSE, FALSE, FALSE);
154 $this->pdf
->SetXY($x, $y);
158 * This is supposed to be overridden.
160 * @param array $participant
162 public function generateLabel($participant) {
163 $txt = "{$this->event['title']}
164 {$participant['display_name']}
165 {$participant['current_employer']}";
167 $this->pdf
->MultiCell($this->pdf
->width
, $this->pdf
->lineHeight
, $txt);
170 public function pdfExtraFormat() {
174 * Create labels (pdf).
176 * @param array $participants
178 public function createLabels(&$participants) {
180 $this->pdf
= new CRM_Utils_PDF_Label($this->format
, 'mm');
181 $this->pdfExtraFormat();
183 $this->pdf
->setPrintHeader(FALSE);
184 $this->pdf
->setPrintFooter(FALSE);
185 $this->pdf
->AddPage();
186 $this->pdf
->AddFont('DejaVu Sans', '', 'DejaVuSans.php');
187 $this->pdf
->SetFont('DejaVu Sans');
188 $this->pdf
->SetGenerator($this, "generateLabel");
190 foreach ($participants as $participant) {
191 $this->pdf
->AddPdfLabel($participant);
193 $this->pdf
->Output($this->event
->title
. '.pdf', 'D');