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

Merge pull request #1157 from kurund/CRM-12967

added QR code support for name badges, CRM-12967
parents 3e0d4656 f38395f7
Branches
Tags
No related merge requests found
......@@ -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');
}
}
}
......
......@@ -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);
......
......@@ -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'));
......
......@@ -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;
}
}
......@@ -92,7 +92,9 @@
</tr>
<tr class="crm-badge-layout-form-block-add_barcode">
<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 class="crm-badge-layout-form-block-is_active">
<td class="label">{$form.is_active.label}</td>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment