Skip to content
Snippets Groups Projects
Commit f38395f7 authored by Kurund Jalmi's avatar Kurund Jalmi
Browse files

added QR code support for name badges, CRM-12967

parent e1f4e358
No related branches found
No related tags found
No related merge requests found
...@@ -113,7 +113,10 @@ class CRM_Badge_BAO_Badge { ...@@ -113,7 +113,10 @@ class CRM_Badge_BAO_Badge {
} }
if (CRM_Utils_Array::value('add_barcode', $layout['data'])) { 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 // finally assign all the row values, so that we can use it for barcode etc
...@@ -179,43 +182,90 @@ class CRM_Badge_BAO_Badge { ...@@ -179,43 +182,90 @@ class CRM_Badge_BAO_Badge {
$this->border, $formattedRow['token'][4]['text_alignment'], 0, 1, $x, $y + $this->pdf->height - 5); $this->border, $formattedRow['token'][4]['text_alignment'], 0, 1, $x, $y + $this->pdf->height - 5);
if (CRM_Utils_Array::value('barcode', $formattedRow)) { if (CRM_Utils_Array::value('barcode', $formattedRow)) {
$style = array( $data = $formattedRow['values'];
'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,
);
// barcode position if ($formattedRow['barcode']['type'] == 'barcode') {
$xAlign = $x; $data['current_value'] =
if ($formattedRow['barcode'] == 'L') { $formattedRow['values']['contact_id'] . '-' . $formattedRow['values']['participant_id'];
$xAlign += -12;
}
elseif ($formattedRow['barcode'] == 'R') {
$xAlign += 30;
} }
elseif ($formattedRow['barcode'] == 'C') { else {
$xAlign += 15; // 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 // 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, '', $style = array(
12, 0.4, $style, 'B'); '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');
}
} }
} }
......
...@@ -189,6 +189,7 @@ class CRM_Badge_BAO_Layout extends CRM_Core_DAO_PrintLabel { ...@@ -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['add_barcode'] = CRM_Utils_Array::value('add_barcode', $data);
$dataValues['barcode_alignment'] = CRM_Utils_Array::value('barcode_alignment', $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_1'] = CRM_Utils_Array::value('image_1', $data);
$dataValues['image_2'] = CRM_Utils_Array::value('image_2', $data); $dataValues['image_2'] = CRM_Utils_Array::value('image_2', $data);
......
...@@ -93,10 +93,12 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form { ...@@ -93,10 +93,12 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
$rowCount++; $rowCount++;
$this->assign('rowCount', $rowCount); $this->assign('rowCount', $rowCount);
$barcodeTypes = CRM_Core_SelectValues::getBarcodeTypes();
$this->add('checkbox', 'add_barcode', ts('Barcode?')); $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); $this->add('select', "barcode_alignment", ts('Alignment'), $textAlignment);
$attributes = array('readonly'=> true); $attributes = array('readonly'=> true);
$this->add('text', 'image_1', ts('Image (top right)'), $this->add('text', 'image_1', ts('Image (top right)'),
$attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title')); $attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'));
......
...@@ -849,5 +849,20 @@ class CRM_Core_SelectValues { ...@@ -849,5 +849,20 @@ class CRM_Core_SelectValues {
} }
return $numericOptions; 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;
}
} }
...@@ -92,7 +92,9 @@ ...@@ -92,7 +92,9 @@
</tr> </tr>
<tr class="crm-badge-layout-form-block-add_barcode"> <tr class="crm-badge-layout-form-block-add_barcode">
<td class="label">{$form.add_barcode.label}</td> <td class="label">{$form.add_barcode.label}</td>
<td>{$form.add_barcode.html}&nbsp;&nbsp;&nbsp;{ts}on{/ts}&nbsp;&nbsp;&nbsp;{$form.barcode_alignment.html}</td> <td>{$form.add_barcode.html}&nbsp;&nbsp;&nbsp;{ts}of type{/ts}&nbsp;&nbsp;&nbsp;
{$form.barcode_type.html}&nbsp;&nbsp;&nbsp;{ts}on{/ts}&nbsp;&nbsp;&nbsp;{$form.barcode_alignment.html}
</td>
</tr> </tr>
<tr class="crm-badge-layout-form-block-is_active"> <tr class="crm-badge-layout-form-block-is_active">
<td class="label">{$form.is_active.label}</td> <td class="label">{$form.is_active.label}</td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment