Allows users to display a contact's profile picture on their name badge
authorMaggie <maggie.epps@gmail.com>
Thu, 10 Apr 2014 20:46:10 +0000 (16:46 -0400)
committerMaggie <maggie.epps@gmail.com>
Wed, 30 Apr 2014 21:19:53 +0000 (17:19 -0400)
CRM/Badge/BAO/Badge.php
CRM/Badge/Form/Layout.php
templates/CRM/Badge/Form/Layout.tpl

index ad2fcacd991beb8b7a095b58c972ce61f8e16ced..640be3f14624d7a9665a6767f2d9e60ae5fc3f5a 100644 (file)
@@ -125,6 +125,18 @@ class CRM_Badge_BAO_Badge {
     if (!empty($layout['data']['height_image_2'])) {
       $formattedRow['height_image_2'] = $layout['data']['height_image_2'];
     }
+    if (!empty($row['participant_image_URL'])) {
+      $formattedRow['participant_image'] = $row['participant_image_URL'];
+    }
+    if (!empty($layout['data']['width_participant_image'])) {
+      $formattedRow['width_participant_image'] = $layout['data']['width_participant_image'];
+    }
+    if (!empty($layout['data']['height_participant_image'])) {
+      $formattedRow['height_participant_image'] = $layout['data']['height_participant_image'];
+    }
+    if (!empty($layout['data']['alignment_participant_image'])) {
+      $formattedRow['alignment_participant_image'] = $layout['data']['alignment_participant_image'];
+    }    
 
     if (!empty($layout['data']['add_barcode'])) {
       $formattedRow['barcode'] = array(
@@ -178,6 +190,27 @@ class CRM_Badge_BAO_Badge {
       $startOffset = CRM_Utils_Array::value('height_image_2', $formattedRow);
     }
 
+    if (CRM_Utils_Array::value('participant_image', $formattedRow)){
+      $xAlign = 10;
+      switch (CRM_Utils_Array::value('alignment_participant_image', $formattedRow)){
+        case 'R':
+          $xAlign = 65;
+          break;
+        case 'L':
+          $xAlign = 10;
+          break;
+        case 'C':
+          $xAlign = 35;
+          break;
+        default:
+          break;
+      }
+      $this->pdf->Image($formattedRow['participant_image'], $x+$xAlign, $y + 18, CRM_Utils_Array::value('width_participant_image', $formattedRow), CRM_Utils_Array::value('height_participant_image', $formattedRow));
+      if ($startOffset == NULL && CRM_Utils_Array::value('height_participant_image', $formattedRow)){
+        $startOffset = CRM_Utils_Array::value('height_participant_image', $formattedRow);        
+      }
+    }
+
     $this->pdf->SetLineStyle(array(
       'width' => 0.1,
       'cap' => 'round',
@@ -342,7 +375,16 @@ class CRM_Badge_BAO_Badge {
     // get name badge layout info
     $layoutInfo = CRM_Badge_BAO_Layout::buildLayout($params);
 
-    // spit / get actual field names from token
+    // spit / get actual field names from tokeni and individual contact image URLs
+    $participant_image_URLs = array();
+    if (CRM_Utils_Array::value('participant_image', $layoutInfo['data'])){
+      $layoutInfo['data']['participant_image_URL'] = '';
+      $queryString = "SELECT civicrm_participant.id as participant_id, civicrm_contact.image_URL FROM civicrm_contact LEFT JOIN civicrm_participant ON civicrm_contact.id = civicrm_participant.contact_id WHERE {$form->_componentClause};";
+      $dao = CRM_Core_DAO::executeQuery($queryString);
+      while ($dao->fetch()){ 
+        $participant_image_URLs[$dao->participant_id] = $dao->image_URL;
+      }
+    }
     $returnProperties = array();
     if (!empty($layoutInfo['data']['token'])) {
       foreach ($layoutInfo['data']['token'] as $index => $value) {
@@ -414,7 +456,9 @@ class CRM_Badge_BAO_Badge {
         $rows[$dao->participant_id][$key] = isset($dao->$key) ? $dao->$key : NULL;
       }
     }
-
+    foreach ($participant_image_URLs as $participantId => $participant_image_URL) {
+      $rows[$participantId]['participant_image_URL'] = $participant_image_URL;
+    }
     $eventBadgeClass = new CRM_Badge_BAO_Badge();
     $eventBadgeClass->createLabels($rows, $layoutInfo);
   }
index dada647a1ea3ce35c77bb57e6639150afc416826..c3e6f064a000a33e2535c0ca2f38a151b1b33f6d 100644 (file)
@@ -118,6 +118,12 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
     $this->add('text', 'width_image_2', ts('Width (mm)'), array('size' => 6));
     $this->add('text', 'height_image_2', ts('Height (mm)'), array('size' => 6));
 
+
+    $this->add('checkbox', 'participant_image', ts('Use Participant Image?'));
+    $this->add('text', 'width_participant_image', ts('Width (mm)'), array('size' => 6));
+    $this->add('text', 'height_participant_image', ts('Height (mm)'), array('size' => 6));
+    $this->add('select', "alignment_participant_image", ts('Image Alignment'), $textAlignment);
+
     $this->add('checkbox', 'is_default', ts('Default?'));
     $this->add('checkbox', 'is_active', ts('Enabled?'));
     $this->add('checkbox', 'is_reserved', ts('Reserved?'));
@@ -126,6 +132,8 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
     $this->addRule('width_image_2', ts('Enter valid width'), 'positiveInteger');
     $this->addRule('height_image_1', ts('Enter valid height'), 'positiveInteger');
     $this->addRule('height_image_2', ts('Enter valid height'), 'positiveInteger');
+    $this->addRule('height_participant_image', ts('Enter valid height'), 'positiveInteger');
+    $this->addRule('width_participant_image', ts('Enter valid height'), 'positiveInteger');
 
     $this->addButtons(array(
         array(
index 285c489681b4ade5cbe7ca5738e5dd382f5dd66e..dcdb7e206544bc5aa88316814a96b6152f731e54 100644 (file)
          </table> 
         </td>
       </tr>
+      <tr class="crm-badge-layout-form-block-participant_image">
+        <td class="label">{$form.participant_image.label}</td>
+        <td>
+         <table>
+           <tr>
+            <td>{$form.participant_image.html}
+             <br/>
+             <span class="description">{ts}Select this option if you want to use a contact's image on their name badge.{/ts}</span>
+            </td>
+            <td>
+             {$form.width_participant_image.html}<br/>{$form.width_participant_image.label}
+            </td>
+           <td>
+              {$form.height_participant_image.html}</br>{$form.height_participant_image.label}
+            </td>
+           <td>
+              {$form.alignment_participant_image.html}</br>{$form.alignment_participant_image.label}
+            </td>
+           </tr>
+         </table> 
+        </td>
+      </tr>
       <tr class="crm-badge-layout-form-block-elements">
         <td class="label">{ts}Elements{/ts}</td>
         <td>