Fix another entity to be standardised & support custom data
[civicrm-core.git] / CRM / Event / BAO / ParticipantPayment.php
index 2dbcd7033d0745e4ba7bf21c5d150ea754813bf0..dc9dcfd12cc3aa93566e07ae0f5e28e8f15ea494 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -29,7 +29,7 @@
  *
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2018
  * $Id$
  *
  */
@@ -41,14 +41,15 @@ class CRM_Event_BAO_ParticipantPayment extends CRM_Event_DAO_ParticipantPayment
    * @param array $params
    *   of values to initialize the record with.
    * @param array $ids
-   *   with one values of id for this participantPayment record (for update).
+   *   deprecated array.
    *
    * @return object
    *   the partcipant payment record
    */
-  public static function create(&$params, &$ids) {
-    if (isset($ids['id'])) {
-      CRM_Utils_Hook::pre('edit', 'ParticipantPayment', $ids['id'], $params);
+  public static function create(&$params, $ids = []) {
+    $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids));
+    if ($id) {
+      CRM_Utils_Hook::pre('edit', 'ParticipantPayment', $id, $params);
     }
     else {
       CRM_Utils_Hook::pre('create', 'ParticipantPayment', NULL, $params);
@@ -56,16 +57,21 @@ class CRM_Event_BAO_ParticipantPayment extends CRM_Event_DAO_ParticipantPayment
 
     $participantPayment = new CRM_Event_BAO_ParticipantPayment();
     $participantPayment->copyValues($params);
-    if (isset($ids['id'])) {
-      $participantPayment->id = CRM_Utils_Array::value('id', $ids);
+    if ($id) {
+      $participantPayment->id = $id;
     }
     else {
       $participantPayment->find(TRUE);
     }
     $participantPayment->save();
 
-    if (isset($ids['id'])) {
-      CRM_Utils_Hook::post('edit', 'ParticipantPayment', $ids['id'], $participantPayment);
+    if (empty($participantPayment->contribution_id)) {
+      // For an id update contribution_id may be unknown. We want it
+      // further down so perhaps get it before the hooks.
+      $participantPayment->find(TRUE);
+    }
+    if ($id) {
+      CRM_Utils_Hook::post('edit', 'ParticipantPayment', $id, $participantPayment);
     }
     else {
       CRM_Utils_Hook::post('create', 'ParticipantPayment', NULL, $participantPayment);