Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-08-16-18-06-10
[civicrm-core.git] / CRM / Event / Form / Registration.php
index 1576d668f7849a118fdb0e7a4c803dfdcb85801f..eba6370c6a8257ab60ab02ae55105203fd1a8c30 100644 (file)
@@ -288,51 +288,14 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
       // check for is_monetary status
       $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values['event']);
       $isPayLater = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eventId, 'is_pay_later');
-      //check for variour combination for paylater, payment
+      //check for various combinations for paylater, payment
       //process with paid event.
       if ($isMonetary && (!$isPayLater || !empty($this->_values['event']['payment_processor']))) {
-        $ppID = CRM_Utils_Array::value('payment_processor',
+        $this->_paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('payment_processor',
           $this->_values['event']
-        );
-        if (!$ppID) {
-          CRM_Core_Error::statusBounce(ts('A payment processor must be selected for this event registration page, or the event must be configured to give users the option to pay later (contact the site administrator for assistance).'), $infoUrl);
-        }
-        $ppIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ppID);
-        $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($ppIds,
-          $this->_mode
-        );
-        $this->set('paymentProcessors', $this->_paymentProcessors);
-
-        //set default payment processor
-        if (!empty($this->_paymentProcessors) && empty($this->_paymentProcessor)) {
-          foreach ($this->_paymentProcessors as $ppId => $values) {
-            if ($values['is_default'] == 1 || (count($this->_paymentProcessors) == 1)) {
-              $defaultProcessorId = $ppId;
-              break;
-            }
-          }
-        }
+        ));
+        $this->assignPaymentProcessor();
 
-        if (isset($defaultProcessorId)) {
-          $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($defaultProcessorId, $this->_mode);
-        }
-        // make sure we have a valid payment class, else abort
-        if ($this->_values['event']['is_monetary']) {
-          if (!CRM_Utils_System::isNull($this->_paymentProcessors)) {
-            foreach ($this->_paymentProcessors as $eachPaymentProcessor) {
-              // check selected payment processor is active
-              if (!$eachPaymentProcessor) {
-                CRM_Core_Error::fatal(ts('The site administrator must set a Payment Processor for this event in order to use online registration.'));
-              }
-              // ensure that processor has a valid config
-              $payment = CRM_Core_Payment::singleton($this->_mode, $eachPaymentProcessor, $this);
-              $error = $payment->checkConfig();
-              if (!empty($error)) {
-                CRM_Core_Error::fatal($error);
-              }
-            }
-          }
-        }
       }
       //init event fee.
       self::initEventFee($this, $this->_eventId);
@@ -374,15 +337,8 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
           unset($this->_values['additional_custom_post_id']);
         }
       }
-      // get the billing location type
-      $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
-      // CRM-8108 remove ts from Billing as the location type can not be translated in CiviCRM!
-      //$this->_bltID = array_search( ts('Billing'),  $locationTypes );
-      $this->_bltID = array_search('Billing', $locationTypes);
-      if (!$this->_bltID) {
-        CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
-      }
-      $this->set('bltID', $this->_bltID);
+
+      $this->assignBillingType();
 
       if ($this->_values['event']['is_monetary']) {
         CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor);
@@ -763,7 +719,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form {
     }
 
     CRM_Core_BAO_CustomValueTable::postProcess($this->_params,
-      CRM_Core_DAO::$_nullArray,
       'civicrm_participant',
       $participant->id,
       'Participant'
@@ -1204,6 +1159,8 @@ WHERE  v.option_group_id = g.id
   /**
    * Reset values for all options those are full.
    *
+   * @param array $optionFullIds
+   * @param $form
    */
   public static function resetElementValue($optionFullIds = array(), &$form) {
     if (!is_array($optionFullIds) ||
@@ -1274,6 +1231,7 @@ WHERE  v.option_group_id = g.id
   /**
    * @param string $elementName
    * @param array $optionIds
+   * @param CRM_Core_form $form
    */
   public static function resetSubmittedValue($elementName, $optionIds = array(), &$form) {
     if (empty($elementName) ||