Merge pull request #16558 from eileenmcnaughton/523dupe
[civicrm-core.git] / CRM / Event / Form / Participant.php
index d12d0a9d6e79ac046fee53d56e672018723310a0..d1d5a95861b2ac879c94b844915c761285911ae0 100644 (file)
@@ -107,60 +107,70 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
 
   /**
    * If event is paid or unpaid.
+   *
    * @var bool
    */
   public $_isPaidEvent;
 
   /**
    * Page action.
+   *
    * @var int
    */
   public $_action;
 
   /**
    * Role Id.
+   *
    * @var int
    */
   protected $_roleId = NULL;
 
   /**
    * Event Type Id.
+   *
    * @var int
    */
   protected $_eventTypeId = NULL;
 
   /**
    * Participant status Id.
+   *
    * @var int
    */
   protected $_statusId = NULL;
 
   /**
    * Cache all the participant statuses.
+   *
    * @var array
    */
   protected $_participantStatuses;
 
   /**
    * Participant mode.
+   *
    * @var string
    */
   public $_mode = NULL;
 
   /**
    * Event ID preselect.
+   *
    * @var int
    */
   public $_eID = NULL;
 
   /**
    * Line Item for Price Set.
+   *
    * @var array
    */
   public $_lineItem = NULL;
 
   /**
    * Contribution mode for event registration for offline mode.
+   *
    * @var string
    * @deprecated
    */
@@ -170,30 +180,35 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
 
   /**
    * Store id of role custom data type ( option value )
+   *
    * @var int
    */
   protected $_roleCustomDataTypeID;
 
   /**
    * Store id of event Name custom data type ( option value)
+   *
    * @var int
    */
   protected $_eventNameCustomDataTypeID;
 
   /**
    * Selected discount id.
+   *
    * @var int
    */
   public $_originalDiscountId = NULL;
 
   /**
    * Event id.
+   *
    * @var int
    */
   public $_eventId = NULL;
 
   /**
    * Id of payment, if any
+   *
    * @var int
    */
   public $_paymentId = NULL;
@@ -1211,7 +1226,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       //CRM-15372 patch to fix fee amount replacing amount
       $this->_params['fee_amount'] = $this->_params['amount'];
 
-      $participants[] = $this->addParticipant($this, $contactID);
+      $participants[] = $this->addParticipant($this, $this->_params, $contactID);
 
       //add custom data for participant
       CRM_Core_BAO_CustomValueTable::postProcess($this->_params,
@@ -1410,10 +1425,14 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
               $lineItem[$this->_priceSetId][$lineKey] = $line;
             }
             CRM_Price_BAO_LineItem::processPriceSet($participants[$num]->id, $lineItem, CRM_Utils_Array::value($num, $contributions, NULL), 'civicrm_participant');
-            CRM_Contribute_BAO_Contribution::addPayments($contributions);
           }
         }
       }
+      foreach ($contributions as $contribution) {
+        if ('Partially paid' === CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contribution->contribution_status_id)) {
+          CRM_Contribute_BAO_Contribution::addPayments($contribution);
+        }
+      }
     }
 
     $updateStatusMsg = NULL;
@@ -2078,27 +2097,25 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
    * Process the participant.
    *
    * @param CRM_Core_Form $form
+   * @param array $params
    * @param int $contactID
    *
    * @return \CRM_Event_BAO_Participant
+   * @throws \CRM_Core_Exception
    * @throws \CiviCRM_API3_Exception
    */
-  protected function addParticipant(&$form, $contactID) {
-    if (empty($form->_params)) {
-      return NULL;
-    }
-    $params = $form->_params;
+  protected function addParticipant(&$form, $params, $contactID) {
     $transaction = new CRM_Core_Transaction();
 
     $participantFields = CRM_Event_DAO_Participant::fields();
-    $participantParams = array(
+    $participantParams = [
       'id' => CRM_Utils_Array::value('participant_id', $params),
       'contact_id' => $contactID,
       'event_id' => $form->_eventId ? $form->_eventId : $params['event_id'],
       'status_id' => CRM_Utils_Array::value('participant_status',
         $params, 1
       ),
-      'role_id' => CRM_Utils_Array::value('participant_role_id', $params) ?: self::getDefaultRoleID(),
+      'role_id' => CRM_Utils_Array::value('participant_role_id', $params) ?: CRM_Event_BAO_Participant::getDefaultRoleID(),
       'register_date' => $params['register_date'],
       'source' => CRM_Utils_String::ellipsify(
         isset($params['participant_source']) ? CRM_Utils_Array::value('participant_source', $params) : CRM_Utils_Array::value('description', $params),
@@ -2111,7 +2128,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
       'discount_id' => CRM_Utils_Array::value('discount_id', $params),
       'fee_currency' => CRM_Utils_Array::value('currencyID', $params),
       'campaign_id' => CRM_Utils_Array::value('campaign_id', $params),
-    );
+    ];
 
     if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
       $participantParams['is_test'] = 1;