Merge pull request #1141 from kurund/CRM-12965
authorKurund Jalmi <kurund@civicrm.org>
Tue, 9 Jul 2013 19:04:21 +0000 (12:04 -0700)
committerKurund Jalmi <kurund@civicrm.org>
Tue, 9 Jul 2013 19:04:21 +0000 (12:04 -0700)
CRM-12965

CRM/Badge/BAO/Layout.php
CRM/Badge/Form/Layout.php
CRM/Core/SelectValues.php
CRM/Event/Form/Task/Badge.php
templates/CRM/Badge/Form/Layout.tpl

index a4370cb8b54e10ce049c8e7195380f3fd4b2505a..da95c880cf75c349c067b787a05dc90e4c2001bc 100644 (file)
@@ -162,7 +162,7 @@ class CRM_Badge_BAO_Layout extends CRM_Core_DAO_PrintLabel {
    * @access public
    */
   static function buildLayout(&$params) {
-    $layoutParams = array('id', $params['badge_id']);
+    $layoutParams = array('id' => $params['badge_id']);
     CRM_Badge_BAO_Layout::retrieve($layoutParams, $layoutInfo);
 
     $formatProperties = CRM_Core_OptionGroup::getValue('name_badge', $layoutInfo['label_format_name'], 'name');
index 3d663ec2307cc8367a1097db83e0e4d5bfbd962f..9bf2ed23615b85b27d169bcd9d1be48e392fdb90 100644 (file)
@@ -69,12 +69,14 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
     $this->add('select', 'label_format_name', ts('Label Style'), array('' => ts('- select -')) + $labelStyle, TRUE);
 
     $this->add('text', 'description', ts('Description'),
-      CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'description'));
+      CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'));
 
     // get the tokens
     $contactTokens = CRM_Core_SelectValues::contactTokens();
     $eventTokens   = CRM_Core_SelectValues::eventTokens();
-    $tokens = array_merge($contactTokens, $eventTokens);
+    $participantTokens = CRM_Core_SelectValues::participantTokens();
+
+    $tokens = array_merge($contactTokens, $eventTokens, $participantTokens);
     asort($tokens);
 
     $fontSizes = CRM_Core_BAO_LabelFormat::getFontSizes();
@@ -95,12 +97,11 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
     unset($textAlignment['J']);
     $this->add('select', "barcode_alignment", ts('Alignment'), $textAlignment);
 
-    $attributes = array(
-      'readonly'=> true,
-      'value' => ts('click here and select a file double clicking on it'),
-    );
-    $this->add('text', 'image_1', ts('Image 1'), $attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'));
-    $this->add('text', 'image_2', ts('Image 2'), $attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'));
+    $attributes = array('readonly'=> true);
+    $this->add('text', 'image_1', ts('Image 1'),
+      $attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'));
+    $this->add('text', 'image_2', ts('Image 2'),
+      $attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'));
 
     $this->add('checkbox', 'is_default', ts('Default?'));
     $this->add('checkbox', 'is_active', ts('Enabled?'));
@@ -116,14 +117,15 @@ class CRM_Badge_Form_Layout extends CRM_Admin_Form {
    * @return None
    */
   function setDefaultValues() {
-    if (isset($this->_id) && empty($this->_values)) {
-      $this->_values = array();
-      $params = array('id' => $this->_id);
-      CRM_Badge_BAO_Layout::retrieve($params, $this->_values );
+    if (isset($this->_id)) {
+      $defaults = array_merge($this->_values,
+        CRM_Badge_BAO_Layout::getDecodedData($this->_values['data']));
+    }
+    else {
+      for ($i = 1; $i <= 4; $i++) {
+        $defaults['text_alignment'][$i] = "C";
+      }
     }
-
-    $defaults = array_merge($this->_values,
-      CRM_Badge_BAO_Layout::getDecodedData($this->_values['data']));
 
     if ($this->_action == CRM_Core_Action::DELETE && isset($defaults['title'])) {
       $this->assign('delName', $defaults['title']);
index f3672d8234aa3a0366fea65905930d97a138b31b..88739eccfbd4644a3c0afab3700d55f40bbbfc5d 100644 (file)
@@ -657,7 +657,7 @@ class CRM_Core_SelectValues {
         'is_bulkmail', 'group', 'tag', 'contact_sub_type', 'note',
         'is_deceased', 'deceased_date', 'legal_identifier', 'contact_sub_type', 'user_unique_id',
       );
-      $customFields        = array();
+
       $customFields        = CRM_Core_BAO_CustomField::getFields('Individual');
       $customFieldsAddress = CRM_Core_BAO_CustomField::getFields('Address');
       $customFields        = $customFields + $customFieldsAddress;
@@ -697,6 +697,44 @@ class CRM_Core_SelectValues {
     return $tokens;
   }
 
+  /**
+   * different type of Participant Tokens
+   *
+   * @static
+   * return array
+   */
+  static function &participantTokens() {
+    static $tokens = NULL;
+    if (!$tokens) {
+      $exportFields = CRM_Event_BAO_Participant::exportableFields();
+
+      $values = array_merge(array_keys($exportFields));
+      unset($values[0]);
+
+      // skipping some tokens for time being.
+      $skipTokens = array(
+        'event_id', 'participant_is_pay_later', 'participant_is_test', 'participant_contact_id',
+        'participant_fee_currency', 'participant_campaign_id', 'participant_status', 'participant_discount_name',
+      );
+
+      $customFields = CRM_Core_BAO_CustomField::getFields('Participant');
+
+      foreach ($values as $key => $val) {
+        if (in_array($val, $skipTokens)) {
+          continue;
+        }
+        //keys for $tokens should be constant. $token Values are changed for Custom Fields. CRM-3734
+        if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($val)) {
+          $tokens["{participant.$val}"] = CRM_Utils_Array::value($customFieldId, $customFields) ? $customFields[$customFieldId]['label'] . " :: " . $customFields[$customFieldId]['groupTitle'] : '';
+        }
+        else {
+          $tokens["{participant.$val}"] = $exportFields[$val]['title'];
+        }
+      }
+    }
+    return $tokens;
+  }
+
   /**
    * get qf mappig for all date parts.
    *
index c4a5d1839a93015fce5701bb30ad57dfe55453db..c7e9a559aeaba0a6262acfb37aeafa9c7e4d8843 100644 (file)
@@ -124,13 +124,16 @@ class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task {
           if (key($token) == 'contact') {
             $element = $token['contact'][0];
           }
-          else {
+          elseif (key($token) == 'event') {
             $element = $token['event'][0];
             //FIX ME - we need to standardize event token names
             if (!strpos($element, 'event_')) {
               $element = 'event_' . $element;
             }
           }
+          elseif (key($token) == 'participant') {
+            $element = $token['participant'][0];
+          }
 
           // build returnproperties for query
           $returnProperties[$element] = 1;
index ac38646e080380becf8eced91e8c0b52872daba2..bf698efb3848eee5b772cb217b1efbb2d8735c50 100644 (file)
@@ -82,7 +82,7 @@
           <span class="crm-clear-link">
             (<a href="#" class="clear-image" imgname='image_1'>{ts}clear{/ts}</a>)
           </span>
-          <br/><span class="description">{ts}This image will displayed on top left{/ts}</span>
+          <br/><span class="description">{ts}Click above and select a file double clicking on it. This image will displayed on top left{/ts}</span>
         </td>
       </tr>
       <tr class="crm-badge-layout-form-block-image_2">
@@ -92,7 +92,7 @@
           <span class="crm-clear-link">
             (<a href="#" class="clear-image" imgname='image_2'>{ts}clear{/ts}</a>)
           </span>
-          <br/><span class="description">{ts}This image will displayed on top right{/ts}</span>
+          <br/><span class="description">{ts}Click above and select a file double clicking on it. This image will displayed on top right{/ts}</span>
         </td>
       </tr>
       <tr class="crm-badge-layout-form-block-add_barcode">