Merge pull request #5883 from mallezie/addfield-website
[civicrm-core.git] / CRM / Event / Form / Participant.php
index 881ad5731da7f61773f82acf748c5f9d82d4755e..1bd751a84818dfd247aa6915cdf6f0c07e64aa10 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -29,7 +29,7 @@
  *
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -43,14 +43,14 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $useLivePageJS = TRUE;
 
   /**
-   * The values for the contribution db object
+   * The values for the contribution db object.
    *
    * @var array
    */
   public $_values;
 
   /**
-   * The values for the quickconfig for priceset
+   * The values for the quickconfig for priceset.
    *
    * @var boolean
    */
@@ -64,35 +64,35 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $_priceSetId;
 
   /**
-   * Array of fields for the price set
+   * Array of fields for the price set.
    *
    * @var array
    */
   public $_priceSet;
 
   /**
-   * The id of the participation that we are proceessing
+   * The id of the participation that we are proceessing.
    *
    * @var int
    */
   public $_id;
 
   /**
-   * The id of the note
+   * The id of the note.
    *
    * @var int
    */
   protected $_noteId = NULL;
 
   /**
-   * The id of the contact associated with this participation
+   * The id of the contact associated with this participation.
    *
    * @var int
    */
   public $_contactId;
 
   /**
-   * Array of event values
+   * Array of event values.
    *
    * @var array
    */
@@ -107,52 +107,52 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $_single = FALSE;
 
   /**
-   * If event is paid or unpaid
+   * If event is paid or unpaid.
    */
   public $_isPaidEvent;
 
   /**
-   * Page action
+   * Page action.
    */
   public $_action;
 
   /**
-   * Role Id
+   * Role Id.
    */
   protected $_roleId = NULL;
 
   /**
-   * Event Type Id
+   * Event Type Id.
    */
   protected $_eventTypeId = NULL;
 
   /**
-   * Participant status Id
+   * Participant status Id.
    */
   protected $_statusId = NULL;
 
   /**
-   * Cache all the participant statuses
+   * Cache all the participant statuses.
    */
   protected $_participantStatuses;
 
   /**
-   * Participant mode
+   * Participant mode.
    */
   public $_mode = NULL;
 
   /**
-   * Event ID preselect
+   * Event ID preselect.
    */
   public $_eID = NULL;
 
   /**
-   * Line Item for Price Set
+   * Line Item for Price Set.
    */
   public $_lineItem = NULL;
 
   /**
-   * Contribution mode for event registration for offline mode
+   * Contribution mode for event registration for offline mode.
    */
   public $_contributeMode = 'direct';
 
@@ -169,12 +169,12 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   protected $_eventNameCustomDataTypeID;
 
   /**
-   * Selected discount id
+   * Selected discount id.
    */
   public $_originalDiscountId = NULL;
 
   /**
-   * Event id
+   * Event id.
    */
   public $_eventId = NULL;
 
@@ -190,7 +190,14 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $_onlinePendingContributionId = NULL;
 
   /**
-   * Set variables up before form is built
+   * Explicitly declare the entity api name.
+   */
+  public function getDefaultEntity() {
+    return 'Participant';
+  }
+
+  /**
+   * Set variables up before form is built.
    *
    * @return void
    */
@@ -322,7 +329,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
           $this->_action = CRM_Core_Action::COPY;
           break;
       }
-      parent::preProcess();
+      CRM_Contact_Form_Task::preProcessCommon($this);
 
       $this->_single = FALSE;
       $this->_contactId = NULL;
@@ -581,7 +588,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   }
 
   /**
-   * Build the form object
+   * Build the form object.
    *
    * @return void
    */
@@ -780,7 +787,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   }
 
   /**
-   * Add local and global form rules
+   * Add local and global form rules.
    *
    *
    * @return void
@@ -790,7 +797,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   }
 
   /**
-   * Global validation rules for the form
+   * Global validation rules for the form.
    *
    * @param array $values
    *   Posted values of the form.
@@ -866,7 +873,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   }
 
   /**
-   * Process the form submission
+   * Process the form submission.
    */
   public function postProcess() {
     // get the submitted form values.
@@ -1043,7 +1050,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       unset($params['amount']);
     }
     $params['register_date'] = CRM_Utils_Date::processDate($params['register_date'], $params['register_date_time']);
-    $params['receive_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $params));
+    $params['receive_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $params), CRM_Utils_Array::value('receive_date_time', $params));
     $params['contact_id'] = $this->_contactId;
 
     // overwrite actual payment amount if entered
@@ -1157,7 +1164,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
       $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEventType, $customFields);
       $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
-        $customFields,
         $this->_id,
         'Participant'
       );
@@ -1189,13 +1195,20 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       if (!empty($this->_params['send_receipt'])) {
         $paymentParams['email'] = $this->_contributorEmail;
       }
-      CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
+
+      // The only reason for merging in the 'contact_id' rather than ensuring it is set
+      // is that this patch is being done around the time of the stable release
+      // so more conservative approach is called for.
+      // In fact the use of $params and $this->_params & $this->_contactId vs $contactID
+      // needs rationalising.
+      $mapParams = array_merge(array('contact_id' => $contactID), $this->_params);
+      CRM_Core_Payment_Form::mapParams($this->_bltID, $mapParams, $paymentParams, TRUE);
 
       $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
 
       // CRM-15622: fix for incorrect contribution.fee_amount
       $paymentParams['fee_amount'] = NULL;
-      $result = $payment->doDirectPayment($paymentParams);
+      $result = $payment->doPayment($paymentParams);
 
       if (is_a($result, 'CRM_Core_Error')) {
         CRM_Core_Error::displaySessionError($result);
@@ -1228,7 +1241,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
         = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
       $this->_params['mode'] = $this->_mode;
 
-      //add contribution reocord
+      //add contribution record
       $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm::processContribution($this, $this->_params, $result, $contactID, FALSE);
 
       // add participant record
@@ -1246,7 +1259,6 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
 
       //add custom data for participant
       CRM_Core_BAO_CustomValueTable::postProcess($this->_params,
-        CRM_Core_DAO::$_nullArray,
         'civicrm_participant',
         $participants[0]->id,
         'Participant'