From f38395f722d94a04a9e0750cf3bc4c21f2b332a9 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Sat, 13 Jul 2013 00:59:12 +0530 Subject: [PATCH] added QR code support for name badges, CRM-12967 --- CRM/Badge/BAO/Badge.php | 114 ++++++++++++++++++++-------- CRM/Badge/BAO/Layout.php | 1 + CRM/Badge/Form/Layout.php | 4 +- CRM/Core/SelectValues.php | 15 ++++ templates/CRM/Badge/Form/Layout.tpl | 4 +- 5 files changed, 104 insertions(+), 34 deletions(-) diff --git a/CRM/Badge/BAO/Badge.php b/CRM/Badge/BAO/Badge.php index bb89d4abf0..e17f82706e 100644 --- a/CRM/Badge/BAO/Badge.php +++ b/CRM/Badge/BAO/Badge.php @@ -113,7 +113,10 @@ class CRM_Badge_BAO_Badge { } if (CRM_Utils_Array::value('add_barcode', $layout['data'])) { - $formattedRow['barcode'] = $layout['data']['barcode_alignment']; + $formattedRow['barcode'] = array( + 'alignment' => $layout['data']['barcode_alignment'], + 'type' => $layout['data']['barcode_type'], + ); } // finally assign all the row values, so that we can use it for barcode etc @@ -179,43 +182,90 @@ class CRM_Badge_BAO_Badge { $this->border, $formattedRow['token'][4]['text_alignment'], 0, 1, $x, $y + $this->pdf->height - 5); if (CRM_Utils_Array::value('barcode', $formattedRow)) { - $style = array( - 'position' => '', - 'align' => '', - 'stretch' => FALSE, - 'fitwidth' => TRUE, - 'cellfitalign' => '', - 'border' => FALSE, - 'hpadding' => 13.5, - 'vpadding' => 'auto', - 'fgcolor' => array(0, 0, 0), - 'bgcolor' => FALSE, - 'text' => FALSE, - 'font' => 'helvetica', - 'fontsize' => 8, - 'stretchtext' => 0, - ); + $data = $formattedRow['values']; - // barcode position - $xAlign = $x; - if ($formattedRow['barcode'] == 'L') { - $xAlign += -12; - } - elseif ($formattedRow['barcode'] == 'R') { - $xAlign += 30; + if ($formattedRow['barcode']['type'] == 'barcode') { + $data['current_value'] = + $formattedRow['values']['contact_id'] . '-' . $formattedRow['values']['participant_id']; } - elseif ($formattedRow['barcode'] == 'C') { - $xAlign += 15; + else { + // view participant url + $data['current_value'] = CRM_Utils_System::url('civicrm/contact/view/participant', + 'action=view&reset=1&cid=' . $formattedRow['values']['contact_id'] . '&id=' + . $formattedRow['values']['participant_id'], + TRUE, + NULL, + FALSE + ); } - $data = $formattedRow['values']; - $data['current_value'] = $formattedRow['values']['contact_id'] . '-' . $formattedRow['values']['participant_id']; - // call hook alterBarcode - CRM_Utils_Hook::alterBarcode($data); + CRM_Utils_Hook::alterBarcode($data, $formattedRow['barcode']['type']); + + if ($formattedRow['barcode']['type'] == 'barcode') { + // barcode position + $xAlign = $x; + + switch ($formattedRow['barcode']['alignment']) { + case 'L': + $xAlign += -12; + break; + case 'R': + $xAlign += 30; + break; + case 'C': + $xAlign += 15; + break; + } - $this->pdf->write1DBarcode($data['current_value'], 'C128', $xAlign, $y + $this->pdf->height - 10, '', - 12, 0.4, $style, 'B'); + $style = array( + 'position' => '', + 'align' => '', + 'stretch' => FALSE, + 'fitwidth' => TRUE, + 'cellfitalign' => '', + 'border' => FALSE, + 'hpadding' => 13.5, + 'vpadding' => 'auto', + 'fgcolor' => array(0, 0, 0), + 'bgcolor' => FALSE, + 'text' => FALSE, + 'font' => 'helvetica', + 'fontsize' => 8, + 'stretchtext' => 0, + ); + + $this->pdf->write1DBarcode($data['current_value'], 'C128', $xAlign, $y + $this->pdf->height - 10, '', + 12, 0.4, $style, 'B'); + } + else { + // qr code position + $xAlign = $x; + + switch ($formattedRow['barcode']['alignment']) { + case 'L': + $xAlign += -8; + break; + case 'R': + $xAlign += 63; + break; + case 'C': + $xAlign += 29; + break; + } + + $style = array( + 'border' => false, + 'hpadding' => 13.5, + 'vpadding' => 'auto', + 'fgcolor' => array(0,0,0), + 'bgcolor' => false, + 'position' => '', + ); + + $this->pdf->write2DBarcode($data['current_value'], 'QRCODE,Q', $xAlign, $y + $this->pdf->height - 23, 30, + 30, $style, 'B'); + } } } diff --git a/CRM/Badge/BAO/Layout.php b/CRM/Badge/BAO/Layout.php index da95c880cf..587d57a150 100644 --- a/CRM/Badge/BAO/Layout.php +++ b/CRM/Badge/BAO/Layout.php @@ -189,6 +189,7 @@ class CRM_Badge_BAO_Layout extends CRM_Core_DAO_PrintLabel { $dataValues['add_barcode'] = CRM_Utils_Array::value('add_barcode', $data); $dataValues['barcode_alignment'] = CRM_Utils_Array::value('barcode_alignment', $data); + $dataValues['barcode_type'] = CRM_Utils_Array::value('barcode_type', $data); $dataValues['image_1'] = CRM_Utils_Array::value('image_1', $data); $dataValues['image_2'] = CRM_Utils_Array::value('image_2', $data); diff --git a/CRM/Badge/Form/Layout.php b/CRM/Badge/Form/Layout.php index 471b899c4f..092aa08809 100644 --- a/CRM/Badge/Form/Layout.php +++ b/CRM/Badge/Form/Layout.php @@ -93,10 +93,12 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form { $rowCount++; $this->assign('rowCount', $rowCount); + $barcodeTypes = CRM_Core_SelectValues::getBarcodeTypes(); $this->add('checkbox', 'add_barcode', ts('Barcode?')); - unset($textAlignment['J']); + $this->add('select', "barcode_type", ts('Type'), $barcodeTypes); $this->add('select', "barcode_alignment", ts('Alignment'), $textAlignment); + $attributes = array('readonly'=> true); $this->add('text', 'image_1', ts('Image (top right)'), $attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title')); diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 88739eccfb..1d2c2431c1 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -849,5 +849,20 @@ class CRM_Core_SelectValues { } return $numericOptions; } + + /** + * barcode types + * @static + */ + static function getBarcodeTypes() { + static $barcodeTypes = NULL; + if (!$barcodeTypes) { + $barcodeTypes = array( + 'barcode' => ts('Linear (1D)'), + 'qrcode' => ts('QR code'), + ); + } + return $barcodeTypes; + } } diff --git a/templates/CRM/Badge/Form/Layout.tpl b/templates/CRM/Badge/Form/Layout.tpl index 26cd069ca5..d71163bd8e 100644 --- a/templates/CRM/Badge/Form/Layout.tpl +++ b/templates/CRM/Badge/Form/Layout.tpl @@ -92,7 +92,9 @@ {$form.add_barcode.label} - {$form.add_barcode.html}   {ts}on{/ts}   {$form.barcode_alignment.html} + {$form.add_barcode.html}   {ts}of type{/ts}    + {$form.barcode_type.html}   {ts}on{/ts}   {$form.barcode_alignment.html} + {$form.is_active.label} -- 2.25.1