CRM-17434 fix - Free event registration with 'skip confirmation' throws warning
authormonishdeb <monish.deb@webaccessglobal.com>
Wed, 28 Oct 2015 08:34:25 +0000 (14:04 +0530)
committermonishdeb <monish.deb@webaccessglobal.com>
Wed, 28 Oct 2015 08:34:25 +0000 (14:04 +0530)
https://issues.civicrm.org/jira/browse/CRM-17434

CRM/Event/Form/Registration.php
CRM/Event/Form/Registration/AdditionalParticipant.php
CRM/Event/Form/Registration/Register.php

index c7a204978070459d88513f58dfcf9f94de969dae..44a4a6dccd54bd0aba9c3d9f571d85d3d04d1327 100644 (file)
@@ -1518,4 +1518,182 @@ WHERE  v.option_group_id = g.id
     return CRM_Price_BAO_PriceSet::getAmountLevelText($params);
   }
 
+  /**
+   * Process Registration of free event.
+   *
+   * @param array $params
+   *   Form values.
+   * @param int $contactID
+   */
+  public function processRegistration($params, $contactID = NULL) {
+    $session = CRM_Core_Session::singleton();
+    $this->_participantInfo = array();
+
+    // CRM-4320, lets build array of cancelled additional participant ids
+    // those are drop or skip by primary at the time of confirmation.
+    // get all in and then unset those are confirmed.
+    $cancelledIds = $this->_additionalParticipantIds;
+
+    $participantCount = array();
+    foreach ($params as $participantNum => $record) {
+      if ($record == 'skip') {
+        $participantCount[$participantNum] = 'skip';
+      }
+      elseif ($participantNum) {
+        $participantCount[$participantNum] = 'participant';
+      }
+    }
+
+    $registerByID = NULL;
+    foreach ($params as $key => $value) {
+      if ($value != 'skip') {
+        $fields = NULL;
+
+        // setting register by Id and unset contactId.
+        if (empty($value['is_primary'])) {
+          $contactID = NULL;
+          $registerByID = $this->get('registerByID');
+          if ($registerByID) {
+            $value['registered_by_id'] = $registerByID;
+          }
+          // get an email if one exists for the participant
+          $participantEmail = '';
+          foreach (array_keys($value) as $valueName) {
+            if (substr($valueName, 0, 6) == 'email-') {
+              $participantEmail = $value[$valueName];
+            }
+          }
+          if ($participantEmail) {
+            $this->_participantInfo[] = $participantEmail;
+          }
+          else {
+            $this->_participantInfo[] = $value['first_name'] . ' ' . $value['last_name'];
+          }
+        }
+        elseif (!empty($value['contact_id'])) {
+          $contactID = $value['contact_id'];
+        }
+        else {
+          $contactID = $this->getContactID();
+        }
+
+        CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields, $this);
+        //for free event or additional participant, dont create billing email address.
+        if (empty($value['is_primary']) || !$this->_values['event']['is_monetary']) {
+          unset($value["email-{$this->_bltID}"]);
+        }
+
+        $contactID = CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields, $this);
+
+        // lets store the contactID in the session
+        // we dont store in userID in case the user is doing multiple
+        // transactions etc
+        // for things like tell a friend
+        if (!$this->getContactID() && !empty($value['is_primary'])) {
+          $session->set('transaction.userID', $contactID);
+        }
+
+        //lets get the status if require approval or waiting.
+
+        $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
+        if ($this->_allowWaitlist && !$this->_allowConfirmation) {
+          $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
+        }
+        elseif ($this->_requireApproval && !$this->_allowConfirmation) {
+          $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
+        }
+
+        $this->set('value', $value);
+        $this->confirmPostProcess($contactID, NULL, NULL);
+
+        //lets get additional participant id to cancel.
+        if ($this->_allowConfirmation && is_array($cancelledIds)) {
+          $additonalId = CRM_Utils_Array::value('participant_id', $value);
+          if ($additonalId && $key = array_search($additonalId, $cancelledIds)) {
+            unset($cancelledIds[$key]);
+          }
+        }
+      }
+    }
+
+    // update status and send mail to cancelled additional participants, CRM-4320
+    if ($this->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) {
+      $cancelledId = array_search('Cancelled',
+        CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'")
+      );
+      CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId);
+    }
+
+    //set information about additional participants if exists
+    if (count($this->_participantInfo)) {
+      $this->set('participantInfo', $this->_participantInfo);
+    }
+
+    //send mail Confirmation/Receipt
+    if ($this->_contributeMode != 'checkout' ||
+      $this->_contributeMode != 'notify'
+    ) {
+      $isTest = FALSE;
+      if ($this->_action & CRM_Core_Action::PREVIEW) {
+        $isTest = TRUE;
+      }
+
+      //handle if no additional participant.
+      if (!$registerByID) {
+        $registerByID = $this->get('registerByID');
+      }
+      $primaryContactId = $this->get('primaryContactId');
+
+      //build an array of custom profile and assigning it to template.
+      $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL,
+        $primaryContactId, $isTest, TRUE
+      );
+
+      //lets carry all participant params w/ values.
+      foreach ($additionalIDs as $participantID => $contactId) {
+        $participantNum = NULL;
+        if ($participantID == $registerByID) {
+          $participantNum = 0;
+        }
+        else {
+          if ($participantNum = array_search('participant', $participantCount)) {
+            unset($participantCount[$participantNum]);
+          }
+        }
+
+        if ($participantNum === NULL) {
+          break;
+        }
+
+        //carry the participant submitted values.
+        $this->_values['params'][$participantID] = $params[$participantNum];
+      }
+
+      //lets send  mails to all with meanigful text, CRM-4320.
+      $this->assign('isOnWaitlist', $this->_allowWaitlist);
+      $this->assign('isRequireApproval', $this->_requireApproval);
+
+      foreach ($additionalIDs as $participantID => $contactId) {
+        if ($participantID == $registerByID) {
+          //set as Primary Participant
+          $this->assign('isPrimary', 1);
+
+          $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $this->_values, NULL, $isTest);
+
+          if (count($customProfile)) {
+            $this->assign('customProfile', $customProfile);
+            $this->set('customProfile', $customProfile);
+          }
+        }
+        else {
+          $this->assign('isPrimary', 0);
+          $this->assign('customProfile', NULL);
+        }
+
+        //send Confirmation mail to Primary & additional Participants if exists
+        CRM_Event_BAO_Event::sendMail($contactId, $this->_values, $participantID, $isTest);
+      }
+    }
+  }
+
 }
index 6c2a0555f3988b20da620f723a4a1725b2414f27..7d161b4aa81876f2280a3a4065316741c2498aea 100644 (file)
@@ -724,7 +724,7 @@ class CRM_Event_Form_Registration_AdditionalParticipant extends CRM_Event_Form_R
       && CRM_Utils_Array::value('additional_participants', $this->_params[0])
       && $this->isLastParticipant()
     ) {
-      CRM_Event_Form_Registration_Register::processRegistration($this, NULL);
+      $this->processRegistration($this->_params);
     }
   }
 
index be179aadc41b42d531b6b91b73fb455586263929..78ed0807c90a6631c9de5ffaeb66db5fa55fda4d 100644 (file)
@@ -1151,7 +1151,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
         empty($params['additional_participants'])
         && !$this->_values['event']['is_confirm_enabled'] // CRM-11182 - Optional confirmation screen
       ) {
-        self::processRegistration($this);
+        $this->processRegistration($this->_params);
       }
     }
 
@@ -1162,184 +1162,6 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
     }
   }
 
-  /**
-   * Process Registration of free event.
-   *
-   * @param object $form
-   * @param int $contactID
-   */
-  public static function processRegistration(&$form, $contactID = NULL) {
-    $session = CRM_Core_Session::singleton();
-    $form->_participantInfo = array();
-    $params = $form->_params;
-
-    // CRM-4320, lets build array of cancelled additional participant ids
-    // those are drop or skip by primary at the time of confirmation.
-    // get all in and then unset those are confirmed.
-    $cancelledIds = $form->_additionalParticipantIds;
-
-    $participantCount = array();
-    foreach ($params as $participantNum => $record) {
-      if ($record == 'skip') {
-        $participantCount[$participantNum] = 'skip';
-      }
-      elseif ($participantNum) {
-        $participantCount[$participantNum] = 'participant';
-      }
-    }
-
-    $registerByID = NULL;
-    foreach ($params as $key => $value) {
-      if ($value != 'skip') {
-        $fields = NULL;
-
-        // setting register by Id and unset contactId.
-        if (empty($value['is_primary'])) {
-          $contactID = NULL;
-          $registerByID = $this->get('registerByID');
-          if ($registerByID) {
-            $value['registered_by_id'] = $registerByID;
-          }
-          // get an email if one exists for the participant
-          $participantEmail = '';
-          foreach (array_keys($value) as $valueName) {
-            if (substr($valueName, 0, 6) == 'email-') {
-              $participantEmail = $value[$valueName];
-            }
-          }
-          if ($participantEmail) {
-            $form->_participantInfo[] = $participantEmail;
-          }
-          else {
-            $form->_participantInfo[] = $value['first_name'] . ' ' . $value['last_name'];
-          }
-        }
-        elseif (!empty($value['contact_id'])) {
-          $contactID = $value['contact_id'];
-        }
-        else {
-          $contactID = $form->getContactID();
-        }
-
-        CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields, $form);
-        //for free event or additional participant, dont create billing email address.
-        if (empty($value['is_primary']) || !$form->_values['event']['is_monetary']) {
-          unset($value["email-{$form->_bltID}"]);
-        }
-
-        $contactID = CRM_Event_Form_Registration_Confirm::updateContactFields($contactID, $value, $fields, $form);
-
-        // lets store the contactID in the session
-        // we dont store in userID in case the user is doing multiple
-        // transactions etc
-        // for things like tell a friend
-        if (!$form->getContactID() && !empty($value['is_primary'])) {
-          $session->set('transaction.userID', $contactID);
-        }
-
-        //lets get the status if require approval or waiting.
-
-        $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
-        if ($form->_allowWaitlist && !$form->_allowConfirmation) {
-          $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
-        }
-        elseif ($form->_requireApproval && !$form->_allowConfirmation) {
-          $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
-        }
-
-        $form->set('value', $value);
-        $form->confirmPostProcess($contactID, NULL, NULL);
-
-        //lets get additional participant id to cancel.
-        if ($form->_allowConfirmation && is_array($cancelledIds)) {
-          $additonalId = CRM_Utils_Array::value('participant_id', $value);
-          if ($additonalId && $key = array_search($additonalId, $cancelledIds)) {
-            unset($cancelledIds[$key]);
-          }
-        }
-      }
-    }
-
-    // update status and send mail to cancelled additional participants, CRM-4320
-    if ($form->_allowConfirmation && is_array($cancelledIds) && !empty($cancelledIds)) {
-      $cancelledId = array_search('Cancelled',
-        CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'")
-      );
-      CRM_Event_BAO_Participant::transitionParticipants($cancelledIds, $cancelledId);
-    }
-
-    //set information about additional participants if exists
-    if (count($form->_participantInfo)) {
-      $form->set('participantInfo', $form->_participantInfo);
-    }
-
-    //send mail Confirmation/Receipt
-    if ($form->_contributeMode != 'checkout' ||
-      $form->_contributeMode != 'notify'
-    ) {
-      $isTest = FALSE;
-      if ($form->_action & CRM_Core_Action::PREVIEW) {
-        $isTest = TRUE;
-      }
-
-      //handle if no additional participant.
-      if (!$registerByID) {
-        $registerByID = $form->get('registerByID');
-      }
-      $primaryContactId = $form->get('primaryContactId');
-
-      //build an array of custom profile and assigning it to template.
-      $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($registerByID, NULL,
-        $primaryContactId, $isTest, TRUE
-      );
-
-      //lets carry all participant params w/ values.
-      foreach ($additionalIDs as $participantID => $contactId) {
-        $participantNum = NULL;
-        if ($participantID == $registerByID) {
-          $participantNum = 0;
-        }
-        else {
-          if ($participantNum = array_search('participant', $participantCount)) {
-            unset($participantCount[$participantNum]);
-          }
-        }
-
-        if ($participantNum === NULL) {
-          break;
-        }
-
-        //carry the participant submitted values.
-        $form->_values['params'][$participantID] = $params[$participantNum];
-      }
-
-      //lets send  mails to all with meanigful text, CRM-4320.
-      $form->assign('isOnWaitlist', $form->_allowWaitlist);
-      $form->assign('isRequireApproval', $form->_requireApproval);
-
-      foreach ($additionalIDs as $participantID => $contactId) {
-        if ($participantID == $registerByID) {
-          //set as Primary Participant
-          $form->assign('isPrimary', 1);
-
-          $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participantID, $form->_values, NULL, $isTest);
-
-          if (count($customProfile)) {
-            $form->assign('customProfile', $customProfile);
-            $form->set('customProfile', $customProfile);
-          }
-        }
-        else {
-          $form->assign('isPrimary', 0);
-          $form->assign('customProfile', NULL);
-        }
-
-        //send Confirmation mail to Primary & additional Participants if exists
-        CRM_Event_BAO_Event::sendMail($contactId, $form->_values, $participantID, $isTest);
-      }
-    }
-  }
-
   /**
    * Method to check if the user is already registered for the event.
    * and if result found redirect to the event info page