Merge branch 'CRM-14696-v2' of https://github.com/JKingsnorth/civicrm-core into CRM...
[civicrm-core.git] / CRM / Event / Form / Participant.php
index d5a4a6593bfc2b7cc0c7602a257c3e84f4591fca..a57d376bea6703b5ec4df23428025d748c1ce471 100644 (file)
@@ -43,7 +43,7 @@ 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
    * @protected
@@ -51,7 +51,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $_values;
 
   /**
-   * the values for the quickconfig for priceset
+   * The values for the quickconfig for priceset
    *
    * @var boolean
    * @protected
@@ -75,7 +75,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $_priceSet;
 
   /**
-   * the id of the participation that we are proceessing
+   * The id of the participation that we are proceessing
    *
    * @var int
    * @protected
@@ -83,7 +83,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $_id;
 
   /**
-   * the id of the note
+   * The id of the note
    *
    * @var int
    * @protected
@@ -91,7 +91,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   protected $_noteId = NULL;
 
   /**
-   * the id of the contact associated with this participation
+   * The id of the contact associated with this participation
    *
    * @var int
    * @protected
@@ -99,7 +99,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $_contactId;
 
   /**
-   * array of event values
+   * Array of event values
    *
    * @var array
    * @protected
@@ -135,60 +135,59 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   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';
 
   public $_online;
 
   /**
-   * store id of role custom data type ( option value )
+   * Store id of role custom data type ( option value )
    */
   protected $_roleCustomDataTypeID;
 
   /**
-   * store id of event Name custom data type ( option value)
+   * Store id of event Name custom data type ( option value)
    */
   protected $_eventNameCustomDataTypeID;
 
   /**
-   * selected discount id
+   * Selected discount id
    */
   public $_originalDiscountId = NULL;
 
   /**
-   * event id
+   * Event id
    */
   public $_eventId = NULL;
 
   /**
-   * id of payment, if any
+   * Id of payment, if any
    */
   public $_paymentId = NULL;
 
@@ -199,7 +198,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   public $_onlinePendingContributionId = NULL;
 
   /**
-   * Function to set variables up before form is built
+   * Set variables up before form is built
    *
    * @return void
    * @access public
@@ -348,7 +347,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
 
     // check for edit permission
     if (!CRM_Core_Permission::checkActionPermission('CiviEvent', $this->_action)) {
-      CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
+      CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
 
     if ($this->_action & CRM_Core_Action::DELETE) {
@@ -592,7 +591,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   }
 
   /**
-   * Function to build the form
+   * Build the form object
    *
    * @return void
    * @access public
@@ -735,17 +734,17 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
     $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
     $this->assign('notificationStatusIds', $notificationStatusIds);
 
-    $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
-    $this->addSelect('status_id', $checkCancelledJs + array('option_url' => 'civicrm/admin/participant_status'), TRUE);
+    $this->_participantStatuses = $statusOptions = CRM_Event_BAO_Participant::buildOptions('status_id', 'create');
 
-    $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
-      'enable_cart'
-    );
-    $pendingInCartStatusId = array_search('Pending in cart', $participantStatusName);
-    $this->assign('pendingInCartStatusId', $pendingInCartStatusId);
-    $this->assign('enableCart', $enableCart);
-    $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
-    $this->assign('pendingRefundStatusId', $pendingRefundStatusId);
+    // Only show refund status when editing
+    if ($this->_action & CRM_Core_Action::ADD) {
+      $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
+      if ($pendingRefundStatusId) {
+        unset($statusOptions[$pendingRefundStatusId]);
+      }
+    }
+
+    $this->addSelect('status_id', $checkCancelledJs + array('options' => $statusOptions, 'option_url' => 'civicrm/admin/participant_status'), TRUE);
 
     $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
 
@@ -797,14 +796,12 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   }
 
   /**
-   * global validation rules for the form
+   * Global validation rules for the form
    *
-   * @param $values
+   * @param array $values posted values of the form
    * @param $files
    * @param $self
    *
-   * @internal param array $fields posted values of the form
-   *
    * @return array list of errors to be posted back to the form
    * @static
    * @access public
@@ -875,7 +872,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
   }
 
   /**
-   * Function to process the form
+   * Process the form submission
    *
    * @access public
    */
@@ -1201,6 +1198,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
 
       $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);
 
       if (is_a($result, 'CRM_Core_Error')) {