From f4e94ab8985c89b245183773c67f4b3181b5e1fa Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Fri, 5 Jul 2013 02:23:06 +0530 Subject: [PATCH] CRM-12966, more fixes and cleanup for badges --- CRM/Badge/{Format => BAO}/Badge.php | 81 ++++++++++++++++++++++------- CRM/Badge/Format/Avery5395.php | 61 ---------------------- CRM/Event/Form/Task/Badge.php | 13 +---- 3 files changed, 63 insertions(+), 92 deletions(-) rename CRM/Badge/{Format => BAO}/Badge.php (72%) delete mode 100644 CRM/Badge/Format/Avery5395.php diff --git a/CRM/Badge/Format/Badge.php b/CRM/Badge/BAO/Badge.php similarity index 72% rename from CRM/Badge/Format/Badge.php rename to CRM/Badge/BAO/Badge.php index 47d482426a..1932bf26f2 100644 --- a/CRM/Badge/Format/Badge.php +++ b/CRM/Badge/BAO/Badge.php @@ -36,24 +36,7 @@ * * parent class for building name badges */ -class CRM_Badge_Format_Badge { - function printImage($img) { - $x = $this->pdf->GetAbsX(); - $y = $this->pdf->GetY(); - - $this->imgRes = 300; - - if ($img) { - $imgsize = getimagesize($img); - // mm - $f = $this->imgRes / 25.4; - $w = $imgsize[0] / $f; - $h = $imgsize[1] / $f; - $this->pdf->Image($img, $this->pdf->GetAbsX(), $this->pdf->GetY(), $w, $h, '', '', '', FALSE, 72, '', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); - } - $this->pdf->SetXY($x, $y); - } - +class CRM_Badge_BAO_Badge { /** * This function is called to create name label pdf * @@ -63,7 +46,7 @@ class CRM_Badge_Format_Badge { * @return void * @access public */ - function createLabels(&$participants, &$layoutInfo) { + public function createLabels(&$participants, &$layoutInfo) { $this->pdf = new CRM_Utils_PDF_Label($layoutInfo['format'], 'mm'); $this->pdf->Open(); $this->pdf->setPrintHeader(FALSE); @@ -91,7 +74,8 @@ class CRM_Badge_Format_Badge { * @return array $formattedRow row with meta data */ static function formatLabel(&$row, &$layout) { - $formattedRow = array(); + $formattedRow = array('labelFormat' => $layout['label_format_name']); + if (CRM_Utils_Array::value('rowElements', $layout['data'])) { foreach($layout['data']['rowElements'] as $key => $element) { $formattedRow['token'][$key] = array( @@ -117,5 +101,62 @@ class CRM_Badge_Format_Badge { return $formattedRow; } + + public function generateLabel($formattedRow) { + switch ($formattedRow['labelFormat']) { + case 'Avery5395': + self::labelAvery5395($formattedRow); + break; + } + } + + public function labelAvery5395(&$formattedRow) { + $this->lMarginLogo = 20; + $this->tMarginName = 20; + + $x = $this->pdf->GetAbsX(); + $y = $this->pdf->GetY(); + + $this->printImage($formattedRow['image_1']); + + $this->pdf->SetLineStyle(array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,2', 'color' => array(0, 0, 200))); + + $this->pdf->SetFontSize(9); + $this->pdf->MultiCell($this->pdf->width - $this->lMarginLogo, 0, $formattedRow['token'][1]['value'], $this->border, "L", 0, 1, $x + $this->lMarginLogo, $y); + + $this->pdf->SetFontSize(20); + $this->pdf->MultiCell($this->pdf->width, 10, $formattedRow['token'][2]['value'], $this->border, "C", 0, 1, $x, $y + $this->tMarginName); + $this->pdf->SetFontSize(15); + $this->pdf->MultiCell($this->pdf->width, 0, $formattedRow['token'][3]['value'], $this->border, "C", 0, 1, $x, $this->pdf->getY()); + + $this->pdf->SetFontSize(9); + $this->pdf->SetXY($x, $y + $this->pdf->height - 5); + $date = CRM_Utils_Date::customFormat($formattedRow['token'][4]['value'], "%e %b"); + $this->pdf->Cell($this->pdf->width, 0, $date, $this->border, 2, "R"); + } + + /** + * Helper function to print images + * @param string $img image url + * + * @return void + * @access public + */ + function printImage($img) { + $x = $this->pdf->GetAbsX(); + $y = $this->pdf->GetY(); + + $this->imgRes = 300; + + if ($img) { + $imgsize = getimagesize($img); + // mm + $f = $this->imgRes / 25.4; + $w = $imgsize[0] / $f; + $h = $imgsize[1] / $f; + $this->pdf->Image($img, $this->pdf->GetAbsX(), $this->pdf->GetY(), $w, $h, '', '', '', FALSE, 72, '', FALSE, FALSE, FALSE, FALSE, FALSE, FALSE); + } + $this->pdf->SetXY($x, $y); + } } diff --git a/CRM/Badge/Format/Avery5395.php b/CRM/Badge/Format/Avery5395.php deleted file mode 100644 index 1c6453ff7e..0000000000 --- a/CRM/Badge/Format/Avery5395.php +++ /dev/null @@ -1,61 +0,0 @@ -lMarginLogo = 20; - $this->tMarginName = 20; - - $x = $this->pdf->GetAbsX(); - $y = $this->pdf->GetY(); - - $this->printImage($participant['image_1']); - - $this->pdf->SetLineStyle(array('width' => 0.1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,2', 'color' => array(0, 0, 200))); - - $this->pdf->SetFontSize(9); - $this->pdf->MultiCell($this->pdf->width - $this->lMarginLogo, 0, $participant['token'][1]['value'], $this->border, "L", 0, 1, $x + $this->lMarginLogo, $y); - - $this->pdf->SetFontSize(20); - $this->pdf->MultiCell($this->pdf->width, 10, $participant['token'][2]['value'], $this->border, "C", 0, 1, $x, $y + $this->tMarginName); - $this->pdf->SetFontSize(15); - $this->pdf->MultiCell($this->pdf->width, 0, $participant['token'][3]['value'], $this->border, "C", 0, 1, $x, $this->pdf->getY()); - - $this->pdf->SetFontSize(9); - $this->pdf->SetXY($x, $y + $this->pdf->height - 5); - $date = CRM_Utils_Date::customFormat($participant['token'][4]['value'], "%e %b"); - $this->pdf->Cell($this->pdf->width, 0, $date, $this->border, 2, "R"); - } -} diff --git a/CRM/Event/Form/Task/Badge.php b/CRM/Event/Form/Task/Badge.php index 2e5febd7b2..403c80f331 100644 --- a/CRM/Event/Form/Task/Badge.php +++ b/CRM/Event/Form/Task/Badge.php @@ -130,7 +130,7 @@ class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task { } } - // build returnproperties + // build returnproperties for query $returnProperties[$element] = 1; // add actual field name to row element @@ -138,13 +138,6 @@ class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task { } } - // check if name label format class exists - $classFile = 'CRM/Badge/Format/' . $layoutInfo['label_format_name'] . '.php'; - $error = include_once($classFile); - if ($error == FALSE) { - CRM_Core_Error::fatal('Event Badge code file: ' . $classFile . ' does not exist. Please verify your custom event badge settings in CiviCRM administrative panel.'); - } - // add additional required fields for query execution $additionalFields = array('participant_register_date', 'participant_id'); foreach ($additionalFields as $field) { @@ -188,9 +181,7 @@ class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task { } } - // create badge class - $className = 'CRM_Badge_Format_' . $layoutInfo['label_format_name']; - $eventBadgeClass = new $className(); + $eventBadgeClass = new CRM_Badge_BAO_Badge(); $eventBadgeClass->createLabels($rows, $layoutInfo); } } -- 2.25.1