CRM-14197 make membership_payment create action take responsibility for setting entit...
[civicrm-core.git] / CRM / Event / BAO / ParticipantPayment.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 *
31 * @package CRM
06b69b18 32 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
33 * $Id$
34 *
35 */
36class CRM_Event_BAO_ParticipantPayment extends CRM_Event_DAO_ParticipantPayment {
37
38 /**
39 * Creates or updates a participant payment record
40 *
41 * @param $params array of values to initialize the record with
42 * @param $ids array with one values of id for this participantPayment record (for update)
43 *
44 * @return object the partcipant payment record
45 * @static
46 */
9637d4be 47 static function create(&$params, &$ids) {
6a488035
TO
48 if (isset($ids['id'])) {
49 CRM_Utils_Hook::pre('edit', 'ParticipantPayment', $ids['id'], $params);
50 }
51 else {
52 CRM_Utils_Hook::pre('create', 'ParticipantPayment', NULL, $params);
53 }
54
55 $participantPayment = new CRM_Event_BAO_ParticipantPayment();
56 $participantPayment->copyValues($params);
57 if (isset($ids['id'])) {
58 $participantPayment->id = CRM_Utils_Array::value('id', $ids);
59 }
60 else {
61 $participantPayment->find(TRUE);
62 }
63 $participantPayment->save();
64
65 if (isset($ids['id'])) {
66 CRM_Utils_Hook::post('edit', 'ParticipantPayment', $ids['id'], $participantPayment);
67 }
68 else {
69 CRM_Utils_Hook::post('create', 'ParticipantPayment', NULL, $participantPayment);
70 }
71
72 return $participantPayment;
73 }
74
75 /**
76 * Delete the record that are associated with this ParticipantPayment
77 * Also deletes the associated contribution for this participant
78 *
79 * @param array $params associative array whose values match the record to be deleted
80 *
81 * @return boolean true if deleted false otherwise
82 * @static
83 * @access public
84 */
85 static function deleteParticipantPayment($params) {
86 $participantPayment = new CRM_Event_DAO_ParticipantPayment();
87
88 $valid = FALSE;
89 foreach ($params as $field => $value) {
90 if (!empty($value)) {
91 $participantPayment->$field = $value;
92 $valid = TRUE;
93 }
94 }
95
96 if (!$valid) {
97 CRM_Core_Error::fatal();
98 }
99
100 if ($participantPayment->find(TRUE)) {
101 CRM_Utils_Hook::pre('delete', 'ParticipantPayment', $participantPayment->id, $params);
102 CRM_Contribute_BAO_Contribution::deleteContribution($participantPayment->contribution_id);
103 $participantPayment->delete();
104 CRM_Utils_Hook::post('delete', 'ParticipantPayment', $participantPayment->id, $participantPayment);
105 return $participantPayment;
106 }
107 return FALSE;
108 }
109}
110