added QR code support for name badges, CRM-12967
authorKurund Jalmi <kurund@civicrm.org>
Fri, 12 Jul 2013 19:29:12 +0000 (00:59 +0530)
committerKurund Jalmi <kurund@civicrm.org>
Fri, 12 Jul 2013 19:29:12 +0000 (00:59 +0530)
CRM/Badge/BAO/Badge.php
CRM/Badge/BAO/Layout.php
CRM/Badge/Form/Layout.php
CRM/Core/SelectValues.php
templates/CRM/Badge/Form/Layout.tpl

index bb89d4abf0dbef65705afa0e9e404641b6959949..e17f82706ec2f190f1d4680625dc49ddd2697001 100644 (file)
@@ -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');
+      }
     }
   }
 
index da95c880cf75c349c067b787a05dc90e4c2001bc..587d57a15082ae674b6214fa89812e1d2c6036d5 100644 (file)
@@ -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);
index 471b899c4f88d1f8a7e40d76a8cb0893ce078c49..092aa08809cd3f704b36c76c4831dc26c143d0e3 100644 (file)
@@ -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'));
index 88739eccfbd4644a3c0afab3700d55f40bbbfc5d..1d2c2431c14de1b2a9af07b2b72075a768e97074 100644 (file)
@@ -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;
+  }
 }
 
index 26cd069ca5657a5a528e7f9db107f5ffdf8e5196..d71163bd8e9165c6941f39fd1eec0ea879f495b1 100644 (file)
@@ -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>