forked from Project60/org.project60.membership
-
Notifications
You must be signed in to change notification settings - Fork 0
/
membership.php
303 lines (275 loc) · 9.03 KB
/
membership.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?php
/*-------------------------------------------------------+
| Project 60 - Membership Extension |
| Copyright (C) 2013-2015 SYSTOPIA |
| Author: B. Endres (endres -at- systopia.de) |
| http://www.systopia.de/ |
+--------------------------------------------------------+
| This program is released as free software under the |
| Affero GPL license. You can redistribute it and/or |
| modify it under the terms of this license which you |
| can read by viewing the included agpl.txt or online |
| at www.gnu.org/licenses/agpl.html. Removal of this |
| copyright header is strictly prohibited without |
| written permission from the original author(s). |
+--------------------------------------------------------*/
require_once 'membership.civix.php';
use CRM_Membership_ExtensionUtil as E;
/**
* Implements hook_civicrm_postProcess().
*
* @param string $formName
* @param CRM_Core_Form $form
*/
function membership_civicrm_postProcess($formName, &$form) {
if ($form instanceof CRM_Contribute_Form_Contribution) {
// Reset the status message after our logic has renewed a membership after completing
// a contribution. The civicrm status message from core would
// indicate a wrong end date and that end date is shown to the user
// so that is confusing.
$paidByLogic = CRM_Membership_PaidByLogic::getSingleton();
$paidByLogic->replaceStatusMessages();
} elseif ($form instanceof CRM_Member_Form_Membership) {
// update derived fields
$membership_id = $form->getEntityId();
if ($membership_id) {
$logic = CRM_Membership_PaidByLogic::getSingleton();
$logic->updateDerivedFields($membership_id);
}
}
}
/**
* Add an action for creating donation receipts after doing a search
*
* @access public
*/
function membership_civicrm_searchTasks($objectType, &$tasks) {
if ($objectType == 'contribution') {
if (CRM_Core_Permission::check('access CiviMember')) {
$tasks[] = array(
'title' => E::ts('Assign to Membership'),
'class' => 'CRM_Membership_Form_Task_AssignTask',
'result' => false);
$tasks[] = array(
'title' => E::ts('Detach from Membership'),
'class' => 'CRM_Membership_Form_Task_DetachTask',
'result' => false);
}
}
}
/**
* Implementation of hook_civicrm_config
*/
function membership_civicrm_config(&$config) {
_membership_civix_civicrm_config($config);
}
/**
* Implementation of hook_civicrm_xmlMenu
*
* @param $files array(string)
*/
function membership_civicrm_xmlMenu(&$files) {
_membership_civix_civicrm_xmlMenu($files);
}
/**
* Implementation of hook_civicrm_install
*/
function membership_civicrm_install() {
return _membership_civix_civicrm_install();
}
/**
* Implementation of hook_civicrm_uninstall
*/
function membership_civicrm_uninstall() {
return _membership_civix_civicrm_uninstall();
}
/**
* Implementation of hook_civicrm_enable
*/
function membership_civicrm_enable() {
return _membership_civix_civicrm_enable();
}
/**
* Implementation of hook_civicrm_disable
*/
function membership_civicrm_disable() {
return _membership_civix_civicrm_disable();
}
/**
* Implementation of hook_civicrm_upgrade
*
* @param $op string, the type of operation being performed; 'check' or 'enqueue'
* @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
*
* @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
* for 'enqueue', returns void
*/
function membership_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
return _membership_civix_civicrm_upgrade($op, $queue);
}
/**
* Implementation of hook_civicrm_managed
*
* Generate a list of entities to create/deactivate/delete when this module
* is installed, disabled, uninstalled.
*/
function membership_civicrm_managed(&$entities) {
return _membership_civix_civicrm_managed($entities);
}
/**
* Implementation of hook_civicrm_caseTypes
*
* Generate a list of case-types
*
* Note: This hook only runs in CiviCRM 4.4+.
*/
function membership_civicrm_caseTypes(&$caseTypes) {
_membership_civix_civicrm_caseTypes($caseTypes);
}
/**
* CiviSEPA Hook - called whenever a new CiviSEPA installment is created
*
* @access public
*/
function membership_civicrm_installment_created($mandate_id, $contribution_recur_id, $contribution_id) {
//see if this installment should be assigned to a membership
$paid_by_logic = CRM_Membership_PaidByLogic::getSingleton();
$paid_by_logic->assignSepaInstallment($mandate_id, $contribution_recur_id,$contribution_id);
}
/**
* CiviCRM SearchColumn Hook
*
* @access public
*/
function membership_civicrm_searchColumns( $objectName, &$headers, &$rows, &$selector ) {
if ($objectName == 'membership') {
CRM_Membership_UiMods::adjustList($headers, $rows, $selector);
}
}
/**
* CiviCRM PRE Hook
*
* @access public
*/
function membership_civicrm_pre($op, $objectName, $id, &$params) {
if ($objectName == 'Membership') {
// generate new membership number when new membership is created
if ($op == 'create' && empty($id)) {
// this might be one for us
CRM_Membership_NumberLogic::generateNewNumber($params);
}
// catch if a membership is set to a certain status
if (!empty($id) && ($op == 'create' || $op == 'edit')) {
$logic = CRM_Membership_PaidByLogic::getSingleton();
$logic->membershipUpdatePre($id, $params);
}
}
if ($objectName == 'Contribution' && $op == 'edit') {
$logic = CRM_Membership_PaidByLogic::getSingleton();
$logic->contributionUpdatePRE($id, $params);
}
}
/**
* CiviCRM POST Hook
*
* @access public
*/
function membership_civicrm_post($op, $objectName, $objectId, &$objectRef) {
if ($objectName == 'Membership') {
// catch if a membership is set to a certain status
if (!empty($objectId) && ($op == 'create' || $op == 'edit')) {
$logic = CRM_Membership_PaidByLogic::getSingleton();
$logic->membershipUpdatePOST($objectId, $objectRef);
}
}
if ($objectName == 'MembershipPayment' && $op == 'create') {
$logic = CRM_Membership_PaidByLogic::getSingleton();
$logic->membershipPaymentCreatePOST($objectRef->contribution_id, $objectRef->membership_id);
}
if ($objectName == 'Contribution' && $op == 'edit') {
$logic = CRM_Membership_PaidByLogic::getSingleton();
$logic->contributionUpdatePOST($objectId, $objectRef);
}
// update derived fields:
if (!empty($objectId) && ($op == 'create' || $op == 'edit')) {
switch ($objectName) {
case 'Membership':
// update membership
$logic = CRM_Membership_PaidByLogic::getSingleton();
$logic->updateDerivedFields($objectId);
break;
case 'ContributionRecur':
// update
$logic = CRM_Membership_PaidByLogic::getSingleton();
$membership_ids = $logic->getMembershipIDs($objectId);
foreach ($membership_ids as $membership_id) {
$logic->updateDerivedFields($objectId);
}
break;
default:
// do nothing
}
}
}
/**
* Implements hook_civicrm_buildForm().
*
* Insert
*
* @param string $formName
* @param CRM_Core_Form $form
*/
function membership_civicrm_buildForm($formName, &$form) {
// first: general UI mods
CRM_Membership_UiMods::adjustForm($formName, $form);
// then inject paid-via stuff - if enabled
if ($formName == 'CRM_Member_Form_MembershipView') {
$paid_by_logic = CRM_Membership_PaidByLogic::getSingleton();
$paid_by_logic->extendForm($formName, $form);
}
}
/**
* Implements hook_civicrm_navigationMenu().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
*/
function membership_civicrm_navigationMenu(&$menu) {
_membership_civix_insert_navigation_menu($menu, 'Memberships', array(
'label' => E::ts('Synchronise Payments'),
'name' => 'p60_payment_sync',
'url' => 'civicrm/membership/payments',
'permission' => 'access CiviContribute',
'operator' => 'OR',
'separator' => 0,
));
_membership_civix_navigationMenu($menu);
}
/**
* Hook implementation: New Tokens
*/
function membership_civicrm_tokens( &$tokens ) {
CRM_Membership_TokenLogic::getSingleton()->tokens($tokens);
}
/**
* Hook implementation: New Tokens
*/
function membership_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) {
// compatibility: extract contact_ids
if (is_string($cids)) {
$contact_ids = explode(',', $cids);
} elseif (isset($cids['contact_id'])) {
$contact_ids = array($cids['contact_id']);
} elseif (is_array($cids)) {
$contact_ids = $cids;
} else {
CRM_Core_Error::debug_log_message("Cannot interpret cids: " . json_encode($cids));
return;
}
CRM_Membership_TokenLogic::getSingleton()->tokenValues($values, $contact_ids, $job, $tokens, $context);
}
/**
* Hook implementation: New Tokens
*/
function membership_civicrm_summary( $contactID, &$content, &$contentPlacement ) {
CRM_Membership_NumberLogic::adjustSummaryView($contactID);
}