Commit | Line | Data |
---|---|---|
28abbcb0 | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
28abbcb0 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
28abbcb0 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
28abbcb0 | 11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
28abbcb0 | 16 | */ |
17 | class CRM_Member_BAO_MembershipPayment extends CRM_Member_DAO_MembershipPayment { | |
18 | ||
28abbcb0 | 19 | /** |
fe482240 | 20 | * Class constructor. |
28abbcb0 | 21 | */ |
00be9182 | 22 | public function __construct() { |
28abbcb0 | 23 | parent::__construct(); |
24 | } | |
353ffa53 | 25 | |
28abbcb0 | 26 | /** |
fe482240 | 27 | * Add the membership Payments. |
28abbcb0 | 28 | * |
b2363ea8 TO |
29 | * @param array $params |
30 | * Reference array contains the values submitted by the form. | |
28abbcb0 | 31 | * |
28abbcb0 | 32 | * |
33 | * @return object | |
34 | */ | |
00be9182 | 35 | public static function create($params) { |
28abbcb0 | 36 | $hook = empty($params['id']) ? 'create' : 'edit'; |
37 | CRM_Utils_Hook::pre($hook, 'MembershipPayment', CRM_Utils_Array::value('id', $params), $params); | |
38 | $dao = new CRM_Member_DAO_MembershipPayment(); | |
39 | $dao->copyValues($params); | |
43c8d1dd | 40 | // We check for membership_id in case we are being called too early in the process. This is |
41 | // cludgey but is part of the deprecation process (ie. we are trying to do everything | |
42 | // from LineItem::create with a view to eventually removing this fn & the table. | |
be2fb01f | 43 | if (!civicrm_api3('Membership', 'getcount', ['id' => $params['membership_id']])) { |
43c8d1dd | 44 | return $dao; |
45 | } | |
46 | ||
99f71e5a EM |
47 | //Fixed for avoiding duplicate entry error when user goes |
48 | //back and forward during payment mode is notify | |
49 | if (!$dao->find(TRUE)) { | |
50 | $dao->save(); | |
51 | } | |
28abbcb0 | 52 | CRM_Utils_Hook::post($hook, 'MembershipPayment', $dao->id, $dao); |
99f71e5a EM |
53 | // CRM-14197 we are in the process on phasing out membershipPayment in favour of storing both contribution_id & entity_id (membership_id) on the line items |
54 | // table. However, at this stage we have both - there is still quite a bit of refactoring to do to set the line_iten entity_id right the first time | |
55 | // however, we can assume at this stage that any contribution id will have only one line item with that membership type in the line item table | |
56 | // OR the caller will have taken responsibility for updating the line items themselves so we will update using SQL here | |
a9f44ffb | 57 | if (!empty($params['isSkipLineItem'])) { |
58 | // Caller has taken responsibility for updating the line items. | |
59 | return $dao; | |
60 | } | |
67dbb78c | 61 | if (!isset($params['membership_type_id'])) { |
be2fb01f | 62 | $membership_type_id = civicrm_api3('membership', 'getvalue', [ |
353ffa53 | 63 | 'id' => $dao->membership_id, |
317fceb4 | 64 | 'return' => 'membership_type_id', |
be2fb01f | 65 | ]); |
67dbb78c MM |
66 | } |
67 | else { | |
68 | $membership_type_id = $params['membership_type_id']; | |
69 | } | |
99f71e5a EM |
70 | $sql = "UPDATE civicrm_line_item li |
71 | LEFT JOIN civicrm_price_field_value pv ON pv.id = li.price_field_value_id | |
72 | SET entity_table = 'civicrm_membership', entity_id = %1 | |
73 | WHERE pv.membership_type_id = %2 | |
99f71e5a | 74 | AND contribution_id = %3"; |
be2fb01f CW |
75 | CRM_Core_DAO::executeQuery($sql, [ |
76 | 1 => [$dao->membership_id, 'Integer'], | |
77 | 2 => [$membership_type_id, 'Integer'], | |
78 | 3 => [$dao->contribution_id, 'Integer'], | |
79 | ]); | |
28abbcb0 | 80 | return $dao; |
81 | } | |
82 | ||
83 | /** | |
fe482240 | 84 | * Delete membership Payments. |
28abbcb0 | 85 | * |
86 | * @param int $id | |
77b97be7 EM |
87 | * |
88 | * @return bool | |
28abbcb0 | 89 | */ |
00be9182 | 90 | public static function del($id) { |
28abbcb0 | 91 | $dao = new CRM_Member_DAO_MembershipPayment(); |
92 | $dao->id = $id; | |
93 | $result = FALSE; | |
94 | if ($dao->find(TRUE)) { | |
95 | $dao->delete(); | |
96 | $result = TRUE; | |
97 | } | |
98 | return $result; | |
99 | } | |
100 | ||
28abbcb0 | 101 | } |