CRM-14342 : introduced generalized assignProfiles function to be used in confirm...
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 3 Apr 2014 11:04:20 +0000 (16:34 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 3 Apr 2014 11:04:20 +0000 (16:34 +0530)
CRM/Event/Form/Registration/Confirm.php
CRM/Event/Form/Registration/ThankYou.php

index fbec562fb4668c670ca9482c1ed9d3cb5b771bdf..6edd554ce0da4a814d5139ac70f44b4300b22a2c 100644 (file)
@@ -288,73 +288,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
     }
 
     //display additional participants profile.
-    $participantParams = $this->_params;
-    $formattedValues = $profileFields = array();
-    $count             = 1;
-    foreach ($participantParams as $participantNum => $participantValue) {
-      if ($participantNum) {
-          $prefix1 = 'additional';
-          $prefix2 = 'additional_';
-      } else {
-          $prefix1 = '';
-          $prefix2 = '';
-      }
-      if ($participantValue != 'skip') {
-        //get the customPre profile info
-        if (!empty($this->_values[$prefix2 . 'custom_pre_id'])) {
-          $values = $groupName = array();
-          CRM_Event_BAO_Event::displayProfile($participantValue,
-            $this->_values[ $prefix2 . 'custom_pre_id'],
-            $groupName,
-            $values,
-            $profileFields
-          );
-
-          if (count($values)) {
-            $formattedValues[$count][$prefix1 . 'CustomPre'] = $values;
-          }
-          $formattedValues[$count][$prefix1 . 'CustomPreGroupTitle'] = CRM_Utils_Array::value('groupTitle', $groupName);
-        }
-        //get the customPost profile info
-        if (!empty($this->_values[$prefix2 . 'custom_post_id'])) {
-          $values = $groupName = array();
-          foreach ($this->_values[$prefix2 . 'custom_post_id'] as $gids) {
-            $val = array();
-            CRM_Event_BAO_Event::displayProfile($participantValue,
-              $gids,
-              $group,
-              $val,
-              $profileFields
-            );
-            $values[$gids] = $val;
-            $groupName[$gids] = $group;
-          }
-
-          if (count($values)) {
-            $formattedValues[$count][$prefix1 . 'CustomPost'] = $values;
-          }
-
-          if (isset($formattedValues[$count][$prefix1 . 'CustomPre'])) {
-            $formattedValues[$count][$prefix1 . 'CustomPost'] = array_diff_assoc($formattedValues[$count][$prefix1 . 'CustomPost'],
-              $formattedValues[$count][$prefix1 . 'CustomPre']
-            );
-          }
-
-          $formattedValues[$count][$prefix1 . 'CustomPostGroupTitle'] = $groupName;
-        }
-        $count++;
-      }
-      $this->_fields = $profileFields;
-    }
-    if (!empty($formattedValues) ) {
-      $this->assign('primaryParticipantProfile', $formattedValues[1]);
-      $this->set('primaryParticipantProfile',    $formattedValues[1]);
-      if ($count > 2) {
-        unset($formattedValues[1]);
-        $this->assign('addParticipantProfile', $formattedValues);
-        $this->set('addParticipantProfile',    $formattedValues);
-      }
-    }
+    self::assignProfiles($this);
 
     //consider total amount.
     $this->assign('isAmountzero', ($this->_totalAmount <= 0) ? TRUE : FALSE);
@@ -1127,4 +1061,82 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
 
     return $contactID;
   }
+
+  public static function assignProfiles(&$form) {
+    $addParticipantProfile = $form->get('addParticipantProfile');
+    $primaryParticipantProfile = $form->get('primaryParticipantProfile');
+    if (!empty($addParticipantProfile) || !empty($primaryParticipantProfile)) {
+      $form->assign('addParticipantProfile', $addParticipantProfile);
+      $form->assign('primaryParticipantProfile', $primaryParticipantProfile);
+      return;
+    }
+
+    $participantParams = $form->_params;
+    $formattedValues = $profileFields = array();
+    $count             = 1;
+    foreach ($participantParams as $participantNum => $participantValue) {
+      if ($participantNum) {
+          $prefix1 = 'additional';
+          $prefix2 = 'additional_';
+      } else {
+          $prefix1 = '';
+          $prefix2 = '';
+      }
+      if ($participantValue != 'skip') {
+        //get the customPre profile info
+        if (!empty($form->_values[$prefix2 . 'custom_pre_id'])) {
+          $values = $groupName = array();
+          CRM_Event_BAO_Event::displayProfile($participantValue,
+            $form->_values[ $prefix2 . 'custom_pre_id'],
+            $groupName,
+            $values,
+            $profileFields
+          );
+
+          if (count($values)) {
+            $formattedValues[$count][$prefix1 . 'CustomPre'] = $values;
+          }
+          $formattedValues[$count][$prefix1 . 'CustomPreGroupTitle'] = CRM_Utils_Array::value('groupTitle', $groupName);
+        }
+        //get the customPost profile info
+        if (!empty($form->_values[$prefix2 . 'custom_post_id'])) {
+          $values = $groupName = array();
+          foreach ($form->_values[$prefix2 . 'custom_post_id'] as $gids) {
+            $val = array();
+            CRM_Event_BAO_Event::displayProfile($participantValue,
+              $gids,
+              $group,
+              $val,
+              $profileFields
+            );
+            $values[$gids] = $val;
+            $groupName[$gids] = $group;
+          }
+
+          if (count($values)) {
+            $formattedValues[$count][$prefix1 . 'CustomPost'] = $values;
+          }
+
+          if (isset($formattedValues[$count][$prefix1 . 'CustomPre'])) {
+            $formattedValues[$count][$prefix1 . 'CustomPost'] = array_diff_assoc($formattedValues[$count][$prefix1 . 'CustomPost'],
+              $formattedValues[$count][$prefix1 . 'CustomPre']
+            );
+          }
+
+          $formattedValues[$count][$prefix1 . 'CustomPostGroupTitle'] = $groupName;
+        }
+        $count++;
+      }
+      $form->_fields = $profileFields;
+    }
+    if (!empty($formattedValues) ) {
+      $form->assign('primaryParticipantProfile', $formattedValues[1]);
+      $form->set('primaryParticipantProfile',    $formattedValues[1]);
+      if ($count > 2) {
+        unset($formattedValues[1]);
+        $form->assign('addParticipantProfile', $formattedValues);
+        $form->set('addParticipantProfile',    $formattedValues);
+      }
+    }
+  }
 }
index e5f753a40f78d8fcee73e831b4fe5e8cef651648..7c9fc60705c39f7e0524b2cdf7bf15c6f2102734 100644 (file)
@@ -62,8 +62,7 @@ class CRM_Event_Form_Registration_ThankYou extends CRM_Event_Form_Registration {
     $customGroup = $this->get('customProfile');
     $this->assign('customProfile', $customGroup);
 
-    $this->assign('primaryParticipantProfile', $this->get('primaryParticipantProfile'));
-    $this->assign('addParticipantProfile', $this->get('addParticipantProfile'));
+    CRM_Event_Form_Registration_Confirm::assignProfiles($this);
 
     CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values['event']));
   }