From cf723d2e7973c0b1b5665044da6c9f08cd97b171 Mon Sep 17 00:00:00 2001 From: Maggie Date: Thu, 10 Apr 2014 16:46:10 -0400 Subject: [PATCH] Allows users to display a contact's profile picture on their name badge --- CRM/Badge/BAO/Badge.php | 48 +++++++++++++++++++++++++++-- CRM/Badge/Form/Layout.php | 8 +++++ templates/CRM/Badge/Form/Layout.tpl | 22 +++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/CRM/Badge/BAO/Badge.php b/CRM/Badge/BAO/Badge.php index ad2fcacd99..640be3f146 100644 --- a/CRM/Badge/BAO/Badge.php +++ b/CRM/Badge/BAO/Badge.php @@ -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); } diff --git a/CRM/Badge/Form/Layout.php b/CRM/Badge/Form/Layout.php index dada647a1e..c3e6f064a0 100644 --- a/CRM/Badge/Form/Layout.php +++ b/CRM/Badge/Form/Layout.php @@ -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( diff --git a/templates/CRM/Badge/Form/Layout.tpl b/templates/CRM/Badge/Form/Layout.tpl index 285c489681..dcdb7e2065 100644 --- a/templates/CRM/Badge/Form/Layout.tpl +++ b/templates/CRM/Badge/Form/Layout.tpl @@ -86,6 +86,28 @@ + + {$form.participant_image.label} + + + + + + + + +
{$form.participant_image.html} +
+ {ts}Select this option if you want to use a contact's image on their name badge.{/ts} +
+ {$form.width_participant_image.html}
{$form.width_participant_image.label} +
+ {$form.height_participant_image.html}
{$form.height_participant_image.label} +
+ {$form.alignment_participant_image.html}
{$form.alignment_participant_image.label} +
+ + {ts}Elements{/ts} -- 2.25.1