Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | class CRM_Member_Page_Tab extends CRM_Core_Page { | |
18 | ||
19 | /** | |
fe482240 | 20 | * The action links that we need to display for the browse screen. |
6a488035 TO |
21 | * |
22 | * @var array | |
6a488035 | 23 | */ |
971e129b SL |
24 | public static $_links = NULL; |
25 | public static $_membershipTypesLinks = NULL; | |
6a488035 TO |
26 | |
27 | public $_permission = NULL; | |
28 | public $_contactId = NULL; | |
29 | ||
30 | /** | |
fe482240 | 31 | * called when action is browse. |
6a488035 | 32 | */ |
00be9182 | 33 | public function browse() { |
51b9c47e | 34 | $links = self::links('all', $this->_isPaymentProcessor, $this->_accessContribution); |
2dc76e8d MW |
35 | $membershipTypes = \Civi\Api4\MembershipType::get(TRUE) |
36 | ->execute() | |
37 | ->indexBy('id') | |
38 | ->column('name'); | |
51b9c47e SL |
39 | $addWhere = "membership_type_id IN (0)"; |
40 | if (!empty($membershipTypes)) { | |
41 | $addWhere = "membership_type_id IN (" . implode(',', array_keys($membershipTypes)) . ")"; | |
42 | } | |
43 | ||
be2fb01f | 44 | $membership = []; |
8d8bd076 | 45 | $dao = new CRM_Member_DAO_Membership(); |
6a488035 | 46 | $dao->contact_id = $this->_contactId; |
51b9c47e | 47 | $dao->whereAdd($addWhere); |
6a488035 TO |
48 | $dao->find(); |
49 | ||
50 | //CRM--4418, check for view, edit, delete | |
be2fb01f | 51 | $permissions = [CRM_Core_Permission::VIEW]; |
6a488035 TO |
52 | if (CRM_Core_Permission::check('edit memberships')) { |
53 | $permissions[] = CRM_Core_Permission::EDIT; | |
a3ca6fe3 MW |
54 | $linkButtons['add_membership'] = [ |
55 | 'title' => ts('Add Membership'), | |
56 | 'url' => 'civicrm/contact/view/membership', | |
57 | 'qs' => "reset=1&action=add&cid={$this->_contactId}&context=membership", | |
58 | 'icon' => 'fa-plus-circle', | |
59 | 'accessKey' => 'N', | |
60 | ]; | |
61 | if ($this->_accessContribution && CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()) { | |
62 | $linkButtons['creditcard_membership'] = [ | |
63 | 'title' => ts('Submit Credit Card Membership'), | |
64 | 'url' => 'civicrm/contact/view/membership', | |
65 | 'qs' => "reset=1&action=add&cid={$this->_contactId}&context=membership&mode=live", | |
66 | 'icon' => 'fa-credit-card', | |
67 | 'accessKey' => 'C', | |
68 | ]; | |
69 | } | |
70 | $this->assign('linkButtons', $linkButtons ?? []); | |
6a488035 TO |
71 | } |
72 | if (CRM_Core_Permission::check('delete in CiviMember')) { | |
73 | $permissions[] = CRM_Core_Permission::DELETE; | |
74 | } | |
75 | $mask = CRM_Core_Action::mask($permissions); | |
76 | ||
77 | // get deceased status id | |
78 | $allStatus = CRM_Member_PseudoConstant::membershipStatus(); | |
79 | $deceasedStatusId = array_search('Deceased', $allStatus); | |
80 | ||
81 | //get all campaigns. | |
82 | $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); | |
83 | ||
84 | //checks membership of contact itself | |
85 | while ($dao->fetch()) { | |
be2fb01f | 86 | $membership[$dao->id] = []; |
6a488035 TO |
87 | CRM_Core_DAO::storeValues($dao, $membership[$dao->id]); |
88 | ||
89 | //carry campaign. | |
9c1bc317 | 90 | $membership[$dao->id]['campaign'] = $allCampaigns[$dao->campaign_id] ?? NULL; |
6a488035 TO |
91 | |
92 | //get the membership status and type values. | |
93 | $statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->id); | |
be2fb01f | 94 | foreach (['status', 'membership_type'] as $fld) { |
9c1bc317 | 95 | $membership[$dao->id][$fld] = $statusANDType[$dao->id][$fld] ?? NULL; |
6a488035 | 96 | } |
a7488080 | 97 | if (!empty($statusANDType[$dao->id]['is_current_member'])) { |
6a488035 TO |
98 | $membership[$dao->id]['active'] = TRUE; |
99 | } | |
100 | if (empty($dao->owner_membership_id)) { | |
101 | // unset renew and followup link for deceased membership | |
102 | $currentMask = $mask; | |
103 | if ($dao->status_id == $deceasedStatusId) { | |
104 | $currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP; | |
105 | } | |
106 | ||
8d8bd076 | 107 | $isUpdateBilling = FALSE; |
0bd096e8 | 108 | // It would be better to determine if there is a recurring contribution & |
109 | // is so get the entity for the recurring contribution (& skip if not). | |
8d8bd076 | 110 | $paymentObject = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity( |
111 | $membership[$dao->id]['membership_id'], 'membership', 'obj'); | |
6a488035 | 112 | if (!empty($paymentObject)) { |
b690491e | 113 | $isUpdateBilling = $paymentObject->supports('updateSubscriptionBillingInfo'); |
6a488035 TO |
114 | } |
115 | ||
0bd096e8 | 116 | // @todo - get this working with syntax style $paymentObject->supports(array |
117 | //('CancelSubscriptionSupported')); | |
8d8bd076 | 118 | $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported( |
119 | $membership[$dao->id]['membership_id']); | |
8a0604d2 | 120 | $links = self::links('all', |
6a488035 TO |
121 | NULL, |
122 | NULL, | |
123 | $isCancelSupported, | |
124 | $isUpdateBilling | |
8a0604d2 E |
125 | ); |
126 | self::getPermissionedLinks($dao->membership_type_id, $links); | |
127 | $membership[$dao->id]['action'] = CRM_Core_Action::formLink($links, | |
6a488035 | 128 | $currentMask, |
be2fb01f | 129 | [ |
6a488035 TO |
130 | 'id' => $dao->id, |
131 | 'cid' => $this->_contactId, | |
be2fb01f | 132 | ], |
6957f0a9 | 133 | ts('Renew') . '...', |
87dab4a4 AH |
134 | FALSE, |
135 | 'membership.tab.row', | |
136 | 'Membership', | |
137 | $dao->id | |
6a488035 TO |
138 | ); |
139 | } | |
140 | else { | |
8a0604d2 E |
141 | $links = self::links('view'); |
142 | self::getPermissionedLinks($dao->membership_type_id, $links); | |
143 | $membership[$dao->id]['action'] = CRM_Core_Action::formLink($links, | |
6a488035 | 144 | $mask, |
be2fb01f | 145 | [ |
6a488035 TO |
146 | 'id' => $dao->id, |
147 | 'cid' => $this->_contactId, | |
be2fb01f | 148 | ], |
87dab4a4 AH |
149 | ts('more'), |
150 | FALSE, | |
151 | 'membership.tab.row', | |
152 | 'Membership', | |
153 | $dao->id | |
6a488035 TO |
154 | ); |
155 | } | |
156 | ||
6bb529e7 MW |
157 | // Display Auto-renew status on page (0=disabled, 1=enabled, 2=enabled, but error |
158 | if (!empty($membership[$dao->id]['contribution_recur_id'])) { | |
159 | if (CRM_Member_BAO_Membership::isSubscriptionCancelled($membership[$dao->id]['membership_id'])) { | |
160 | $membership[$dao->id]['auto_renew'] = 2; | |
161 | } | |
162 | else { | |
163 | $membership[$dao->id]['auto_renew'] = 1; | |
164 | } | |
6a488035 TO |
165 | } |
166 | else { | |
167 | $membership[$dao->id]['auto_renew'] = 0; | |
168 | } | |
169 | ||
c5c263ca | 170 | // if relevant--membership is active and type allows inheritance--count related memberships |
b99f3e96 CW |
171 | if (!empty($statusANDType[$dao->id]['is_current_member']) |
172 | && !empty($statusANDType[$dao->id]['relationship_type_id']) | |
8d8bd076 | 173 | && empty($dao->owner_membership_id) |
ae5ffbb7 TO |
174 | ) { |
175 | // not an related membership | |
6a488035 TO |
176 | $query = " |
177 | SELECT COUNT(m.id) | |
178 | FROM civicrm_membership m | |
179 | LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id | |
86c838ac CW |
180 | LEFT JOIN civicrm_contact ct ON ct.id = m.contact_id |
181 | WHERE m.owner_membership_id = {$dao->id} AND m.is_test = 0 AND ms.is_current_member = 1 AND ct.is_deleted = 0"; | |
6a488035 | 182 | $num_related = CRM_Core_DAO::singleValueQuery($query); |
9c1bc317 | 183 | $max_related = $membership[$dao->id]['max_related'] ?? NULL; |
be2fb01f | 184 | $membership[$dao->id]['related_count'] = ($max_related == '' ? ts('%1 created', [1 => $num_related]) : ts('%1 out of %2', [ |
c5c263ca AH |
185 | 1 => $num_related, |
186 | 2 => $max_related, | |
be2fb01f | 187 | ])); |
8d8bd076 | 188 | } |
189 | else { | |
6a488035 TO |
190 | $membership[$dao->id]['related_count'] = ts('N/A'); |
191 | } | |
192 | } | |
193 | ||
194 | //Below code gives list of all Membership Types associated | |
195 | //with an Organization(CRM-2016) | |
be2fb01f | 196 | $membershipTypesResult = civicrm_api3('MembershipType', 'get', [ |
4c50ac3a | 197 | 'member_of_contact_id' => $this->_contactId, |
be2fb01f | 198 | 'options' => [ |
c8eada29 | 199 | 'limit' => 0, |
be2fb01f CW |
200 | ], |
201 | ]); | |
9c1bc317 | 202 | $membershipTypes = $membershipTypesResult['values'] ?? NULL; |
4c50ac3a | 203 | |
6a488035 TO |
204 | foreach ($membershipTypes as $key => $value) { |
205 | $membershipTypes[$key]['action'] = CRM_Core_Action::formLink(self::membershipTypeslinks(), | |
206 | $mask, | |
be2fb01f | 207 | [ |
6a488035 TO |
208 | 'id' => $value['id'], |
209 | 'cid' => $this->_contactId, | |
be2fb01f | 210 | ], |
87dab4a4 AH |
211 | ts('more'), |
212 | FALSE, | |
213 | 'membershipType.organization.action', | |
214 | 'MembershipType', | |
215 | $value['id'] | |
6a488035 TO |
216 | ); |
217 | } | |
218 | ||
219 | $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership); | |
220 | $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive'); | |
221 | $this->assign('activeMembers', $activeMembers); | |
222 | $this->assign('inActiveMembers', $inActiveMembers); | |
223 | $this->assign('membershipTypes', $membershipTypes); | |
224 | ||
225 | if ($this->_contactId) { | |
226 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
227 | $this->assign('displayName', $displayName); | |
4e8065a9 | 228 | $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId); |
fa9fbb61 | 229 | // Refresh other tabs with related data |
be2fb01f | 230 | $this->ajaxResponse['updateTabs'] = [ |
fa9fbb61 CW |
231 | '#tab_activity' => CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId), |
232 | '#tab_rel' => CRM_Contact_BAO_Contact::getCountComponent('rel', $this->_contactId), | |
be2fb01f | 233 | ]; |
c312052e CW |
234 | if (CRM_Core_Permission::access('CiviContribute')) { |
235 | $this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId); | |
236 | } | |
6a488035 TO |
237 | } |
238 | } | |
239 | ||
240 | /** | |
fe482240 | 241 | * called when action is view. |
6a488035 | 242 | * |
76e7a76c | 243 | * @return null |
6a488035 | 244 | */ |
00be9182 | 245 | public function view() { |
6a488035 TO |
246 | $controller = new CRM_Core_Controller_Simple( |
247 | 'CRM_Member_Form_MembershipView', | |
248 | ts('View Membership'), | |
249 | $this->_action | |
250 | ); | |
251 | $controller->setEmbedded(TRUE); | |
252 | $controller->set('id', $this->_id); | |
253 | $controller->set('cid', $this->_contactId); | |
254 | ||
255 | return $controller->run(); | |
256 | } | |
257 | ||
258 | /** | |
fe482240 | 259 | * called when action is update or new. |
6a488035 | 260 | * |
76e7a76c | 261 | * @return null |
6a488035 | 262 | */ |
00be9182 | 263 | public function edit() { |
6a488035 | 264 | // set https for offline cc transaction |
19046166 | 265 | $mode = CRM_Utils_Request::retrieve('mode', 'Alphanumeric', $this); |
6a488035 TO |
266 | if ($mode == 'test' || $mode == 'live') { |
267 | CRM_Utils_System::redirectToSSL(); | |
268 | } | |
269 | ||
8d8bd076 | 270 | // build associated contributions ( note: this is called to show associated contributions in edit mode ) |
271 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
272 | $this->assign('accessContribution', FALSE); | |
273 | if (CRM_Core_Permission::access('CiviContribute')) { | |
274 | $this->assign('accessContribution', TRUE); | |
275 | CRM_Member_Page_Tab::associatedContribution($this->_contactId, $this->_id); | |
eb3cfcd6 | 276 | |
277 | //show associated soft credit when contribution payment is paid by different person in edit mode | |
278 | if ($this->_id && $this->_contactId) { | |
279 | $filter = " AND cc.id IN (SELECT contribution_id FROM civicrm_membership_payment WHERE membership_id = {$this->_id})"; | |
280 | $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $filter); | |
281 | if (!empty($softCreditList)) { | |
282 | $this->assign('softCredit', TRUE); | |
283 | $this->assign('softCreditRows', $softCreditList); | |
284 | } | |
285 | } | |
8d8bd076 | 286 | } |
6a488035 TO |
287 | } |
288 | ||
289 | if ($this->_action & CRM_Core_Action::RENEW) { | |
290 | $path = 'CRM_Member_Form_MembershipRenewal'; | |
291 | $title = ts('Renew Membership'); | |
292 | } | |
293 | else { | |
294 | $path = 'CRM_Member_Form_Membership'; | |
295 | $title = ts('Create Membership'); | |
296 | } | |
8d8bd076 | 297 | |
298 | $controller = new CRM_Core_Controller_Simple($path, $title, $this->_action); | |
6a488035 TO |
299 | $controller->setEmbedded(TRUE); |
300 | $controller->set('BAOName', $this->getBAOName()); | |
301 | $controller->set('id', $this->_id); | |
302 | $controller->set('cid', $this->_contactId); | |
303 | return $controller->run(); | |
304 | } | |
305 | ||
00be9182 | 306 | public function preProcess() { |
edc80cda | 307 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
6a488035 | 308 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); |
8d8bd076 | 309 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
6a488035 TO |
310 | |
311 | if ($context == 'standalone') { | |
312 | $this->_action = CRM_Core_Action::ADD; | |
313 | } | |
314 | else { | |
315 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); | |
316 | $this->assign('contactId', $this->_contactId); | |
317 | ||
318 | // check logged in url permission | |
319 | CRM_Contact_Page_View::checkUserPermission($this); | |
6a488035 TO |
320 | } |
321 | ||
322 | $this->assign('action', $this->_action); | |
323 | ||
324 | if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit memberships')) { | |
325 | // demote to view since user does not have edit membership rights | |
326 | $this->_permission = CRM_Core_Permission::VIEW; | |
327 | $this->assign('permission', 'view'); | |
328 | } | |
329 | } | |
330 | ||
331 | /** | |
dc195289 | 332 | * the main function that is called when the page loads, it decides the which action has to be taken for the page. |
6a488035 | 333 | * |
76e7a76c | 334 | * @return null |
6a488035 | 335 | */ |
00be9182 | 336 | public function run() { |
6a488035 TO |
337 | $this->preProcess(); |
338 | ||
339 | // check if we can process credit card membership | |
a3ca6fe3 | 340 | if (CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()) { |
6a488035 TO |
341 | $this->_isPaymentProcessor = TRUE; |
342 | } | |
343 | else { | |
344 | $this->_isPaymentProcessor = FALSE; | |
345 | } | |
346 | ||
347 | // Only show credit card membership signup if user has CiviContribute permission | |
348 | if (CRM_Core_Permission::access('CiviContribute')) { | |
349 | $this->_accessContribution = TRUE; | |
350 | $this->assign('accessContribution', TRUE); | |
91ef9be0 | 351 | |
352 | //show associated soft credit when contribution payment is paid by different person | |
353 | if ($this->_id && $this->_contactId) { | |
354 | $filter = " AND cc.id IN (SELECT contribution_id FROM civicrm_membership_payment WHERE membership_id = {$this->_id})"; | |
355 | $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $filter); | |
356 | if (!empty($softCreditList)) { | |
357 | $this->assign('softCredit', TRUE); | |
358 | $this->assign('softCreditRows', $softCreditList); | |
359 | } | |
360 | } | |
6a488035 TO |
361 | } |
362 | else { | |
363 | $this->_accessContribution = FALSE; | |
364 | $this->assign('accessContribution', FALSE); | |
91ef9be0 | 365 | $this->assign('softCredit', FALSE); |
6a488035 TO |
366 | } |
367 | ||
368 | if ($this->_action & CRM_Core_Action::VIEW) { | |
369 | $this->view(); | |
370 | } | |
d3e86119 | 371 | elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) { |
8d8bd076 | 372 | self::setContext($this); |
6a488035 TO |
373 | $this->edit(); |
374 | } | |
375 | else { | |
8d8bd076 | 376 | self::setContext($this); |
6a488035 TO |
377 | $this->browse(); |
378 | } | |
379 | ||
380 | return parent::run(); | |
381 | } | |
382 | ||
bb3a214a | 383 | /** |
c490a46a | 384 | * @param CRM_Core_Form $form |
100fef9d | 385 | * @param int $contactId |
bb3a214a | 386 | */ |
8d8bd076 | 387 | public static function setContext(&$form, $contactId = NULL) { |
edc80cda | 388 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $form, FALSE, 'search'); |
6a488035 | 389 | |
8d8bd076 | 390 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $form); |
29571f63 | 391 | |
e803fd5a | 392 | $searchContext = CRM_Utils_Request::retrieve('searchContext', 'String', $form); |
29571f63 | 393 | |
6a488035 TO |
394 | //validate the qfKey |
395 | if (!CRM_Utils_Rule::qfKey($qfKey)) { | |
396 | $qfKey = NULL; | |
397 | } | |
398 | ||
399 | if (!$contactId) { | |
8d8bd076 | 400 | $contactId = $form->_contactId; |
6a488035 TO |
401 | } |
402 | ||
403 | switch ($context) { | |
404 | case 'dashboard': | |
8d8bd076 | 405 | $url = CRM_Utils_System::url('civicrm/member', 'reset=1'); |
6a488035 TO |
406 | break; |
407 | ||
408 | case 'membership': | |
8d8bd076 | 409 | $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$contactId}&selectedChild=member"); |
6a488035 TO |
410 | break; |
411 | ||
412 | case 'search': | |
413 | $urlParams = 'force=1'; | |
414 | if ($qfKey) { | |
415 | $urlParams .= "&qfKey=$qfKey"; | |
416 | } | |
8d8bd076 | 417 | $form->assign('searchKey', $qfKey); |
2a6da8d7 | 418 | |
29571f63 AS |
419 | if ($searchContext) { |
420 | $url = CRM_Utils_System::url("civicrm/$searchContext/search", $urlParams); | |
421 | } | |
422 | else { | |
423 | $url = CRM_Utils_System::url('civicrm/member/search', $urlParams); | |
424 | } | |
6a488035 TO |
425 | break; |
426 | ||
427 | case 'home': | |
428 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
429 | break; | |
430 | ||
431 | case 'activity': | |
432 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
433 | "reset=1&force=1&cid={$contactId}&selectedChild=activity" | |
434 | ); | |
435 | break; | |
436 | ||
437 | case 'standalone': | |
438 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
439 | break; | |
440 | ||
441 | case 'fulltext': | |
8d8bd076 | 442 | $action = CRM_Utils_Request::retrieve('action', 'String', $form); |
443 | $keyName = '&qfKey'; | |
6a488035 TO |
444 | $urlParams = 'force=1'; |
445 | $urlString = 'civicrm/contact/search/custom'; | |
446 | if ($action == CRM_Core_Action::UPDATE) { | |
8d8bd076 | 447 | if ($form->_contactId) { |
ec6d9c07 | 448 | $urlParams .= '&cid=' . $form->_contactId; |
6a488035 TO |
449 | } |
450 | $keyName = '&key'; | |
451 | $urlParams .= '&context=fulltext&action=view'; | |
452 | $urlString = 'civicrm/contact/view/membership'; | |
453 | } | |
454 | if ($qfKey) { | |
455 | $urlParams .= "$keyName=$qfKey"; | |
456 | } | |
8d8bd076 | 457 | $form->assign('searchKey', $qfKey); |
6a488035 TO |
458 | $url = CRM_Utils_System::url($urlString, $urlParams); |
459 | break; | |
460 | ||
461 | default: | |
462 | $cid = NULL; | |
463 | if ($contactId) { | |
464 | $cid = '&cid=' . $contactId; | |
465 | } | |
8d8bd076 | 466 | $url = CRM_Utils_System::url('civicrm/member/search', 'force=1' . $cid); |
6a488035 TO |
467 | break; |
468 | } | |
469 | ||
470 | $session = CRM_Core_Session::singleton(); | |
471 | $session->pushUserContext($url); | |
472 | } | |
473 | ||
474 | /** | |
fe482240 | 475 | * Get action links. |
6a488035 | 476 | * |
2a6da8d7 EM |
477 | * @param string $status |
478 | * @param null $isPaymentProcessor | |
479 | * @param null $accessContribution | |
480 | * @param bool $isCancelSupported | |
481 | * @param bool $isUpdateBilling | |
482 | * | |
a6c01b45 CW |
483 | * @return array |
484 | * (reference) of action links | |
6a488035 | 485 | */ |
ae5ffbb7 | 486 | public static function &links( |
500cfe81 | 487 | $status = 'all', |
353ffa53 TO |
488 | $isPaymentProcessor = NULL, |
489 | $accessContribution = NULL, | |
490 | $isCancelSupported = FALSE, | |
491 | $isUpdateBilling = FALSE | |
6a488035 | 492 | ) { |
f3acfdd9 | 493 | if (empty(self::$_links['view'])) { |
be2fb01f CW |
494 | self::$_links['view'] = [ |
495 | CRM_Core_Action::VIEW => [ | |
6a488035 TO |
496 | 'name' => ts('View'), |
497 | 'url' => 'civicrm/contact/view/membership', | |
498 | 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member', | |
499 | 'title' => ts('View Membership'), | |
be2fb01f CW |
500 | ], |
501 | ]; | |
6a488035 TO |
502 | } |
503 | ||
f3acfdd9 | 504 | if (empty(self::$_links['all'])) { |
be2fb01f CW |
505 | $extraLinks = [ |
506 | CRM_Core_Action::UPDATE => [ | |
6a488035 TO |
507 | 'name' => ts('Edit'), |
508 | 'url' => 'civicrm/contact/view/membership', | |
509 | 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member', | |
510 | 'title' => ts('Edit Membership'), | |
be2fb01f CW |
511 | ], |
512 | CRM_Core_Action::RENEW => [ | |
6a488035 TO |
513 | 'name' => ts('Renew'), |
514 | 'url' => 'civicrm/contact/view/membership', | |
515 | 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member', | |
516 | 'title' => ts('Renew Membership'), | |
be2fb01f CW |
517 | ], |
518 | CRM_Core_Action::FOLLOWUP => [ | |
6a488035 TO |
519 | 'name' => ts('Renew-Credit Card'), |
520 | 'url' => 'civicrm/contact/view/membership', | |
521 | 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member&mode=live', | |
522 | 'title' => ts('Renew Membership Using Credit Card'), | |
be2fb01f CW |
523 | ], |
524 | CRM_Core_Action::DELETE => [ | |
6a488035 TO |
525 | 'name' => ts('Delete'), |
526 | 'url' => 'civicrm/contact/view/membership', | |
527 | 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member', | |
528 | 'title' => ts('Delete Membership'), | |
be2fb01f CW |
529 | ], |
530 | ]; | |
6a488035 TO |
531 | if (!$isPaymentProcessor || !$accessContribution) { |
532 | //unset the renew with credit card when payment | |
533 | //processor is not available or user is not permitted to create contributions | |
534 | unset($extraLinks[CRM_Core_Action::FOLLOWUP]); | |
535 | } | |
536 | self::$_links['all'] = self::$_links['view'] + $extraLinks; | |
537 | } | |
538 | ||
6a488035 TO |
539 | if ($isCancelSupported) { |
540 | $cancelMessage = ts('WARNING: If you cancel the recurring contribution associated with this membership, the membership will no longer be renewed automatically. However, the current membership status will not be affected.'); | |
be2fb01f | 541 | self::$_links['all'][CRM_Core_Action::DISABLE] = [ |
6a488035 TO |
542 | 'name' => ts('Cancel Auto-renewal'), |
543 | 'url' => 'civicrm/contribute/unsubscribe', | |
544 | 'qs' => 'reset=1&cid=%%cid%%&mid=%%id%%&context=membership&selectedChild=member', | |
545 | 'title' => ts('Cancel Auto Renew Subscription'), | |
546 | 'extra' => 'onclick = "if (confirm(\'' . $cancelMessage . '\') ) { return true; else return false;}"', | |
be2fb01f | 547 | ]; |
6a488035 TO |
548 | } |
549 | elseif (isset(self::$_links['all'][CRM_Core_Action::DISABLE])) { | |
550 | unset(self::$_links['all'][CRM_Core_Action::DISABLE]); | |
551 | } | |
552 | ||
553 | if ($isUpdateBilling) { | |
be2fb01f | 554 | self::$_links['all'][CRM_Core_Action::MAP] = [ |
6a488035 TO |
555 | 'name' => ts('Change Billing Details'), |
556 | 'url' => 'civicrm/contribute/updatebilling', | |
557 | 'qs' => 'reset=1&cid=%%cid%%&mid=%%id%%&context=membership&selectedChild=member', | |
558 | 'title' => ts('Change Billing Details'), | |
be2fb01f | 559 | ]; |
6a488035 TO |
560 | } |
561 | elseif (isset(self::$_links['all'][CRM_Core_Action::MAP])) { | |
562 | unset(self::$_links['all'][CRM_Core_Action::MAP]); | |
563 | } | |
564 | return self::$_links[$status]; | |
565 | } | |
566 | ||
567 | /** | |
fe482240 | 568 | * Define action links for membership types of related organization. |
6a488035 | 569 | * |
a6c01b45 CW |
570 | * @return array |
571 | * self::$_membershipTypesLinks array of action links | |
6a488035 | 572 | */ |
00be9182 | 573 | public static function &membershipTypesLinks() { |
6a488035 | 574 | if (!self::$_membershipTypesLinks) { |
be2fb01f CW |
575 | self::$_membershipTypesLinks = [ |
576 | CRM_Core_Action::VIEW => [ | |
6a488035 TO |
577 | 'name' => ts('Members'), |
578 | 'url' => 'civicrm/member/search/', | |
579 | 'qs' => 'reset=1&force=1&type=%%id%%', | |
580 | 'title' => ts('Search'), | |
be2fb01f CW |
581 | ], |
582 | CRM_Core_Action::UPDATE => [ | |
6a488035 TO |
583 | 'name' => ts('Edit'), |
584 | 'url' => 'civicrm/admin/member/membershipType', | |
585 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
586 | 'title' => ts('Edit Membership Type'), | |
be2fb01f CW |
587 | ], |
588 | ]; | |
6a488035 TO |
589 | } |
590 | return self::$_membershipTypesLinks; | |
591 | } | |
592 | ||
593 | /** | |
fe482240 | 594 | * used for the to show the associated. |
6a488035 | 595 | * contribution for the membership |
76e7a76c CW |
596 | * |
597 | * @param int $contactId | |
598 | * @param int $membershipId | |
6a488035 | 599 | */ |
141d3170 | 600 | public static function associatedContribution($contactId = NULL, $membershipId = NULL) { |
8d8bd076 | 601 | $controller = new CRM_Core_Controller_Simple( |
602 | 'CRM_Contribute_Form_Search', | |
603 | ts('Contributions'), | |
604 | NULL, | |
605 | FALSE, FALSE, TRUE | |
606 | ); | |
607 | $controller->setEmbedded(TRUE); | |
608 | $controller->reset(); | |
609 | $controller->set('force', 1); | |
e7afe635 | 610 | $controller->set('skip_cid', TRUE); |
8d8bd076 | 611 | $controller->set('memberId', $membershipId); |
612 | $controller->set('context', 'contribution'); | |
613 | $controller->process(); | |
614 | $controller->run(); | |
6a488035 TO |
615 | } |
616 | ||
617 | /** | |
fe482240 | 618 | * Get BAO Name. |
6a488035 | 619 | * |
a6c01b45 CW |
620 | * @return string |
621 | * Classname of BAO. | |
6a488035 | 622 | */ |
00be9182 | 623 | public function getBAOName() { |
6a488035 TO |
624 | return 'CRM_Member_BAO_Membership'; |
625 | } | |
96025800 | 626 | |
22806e9a E |
627 | /** |
628 | * Get a list of links based on permissioned FTs. | |
629 | * | |
630 | * @param int $memTypeID | |
631 | * membership type ID | |
632 | * @param int $links | |
633 | * (reference ) action links | |
634 | */ | |
40c655aa | 635 | public static function getPermissionedLinks($memTypeID, &$links) { |
000f0cc9 | 636 | if (!CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { |
66af7c48 PN |
637 | return FALSE; |
638 | } | |
8a0604d2 E |
639 | $finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memTypeID, 'financial_type_id'); |
640 | $finType = CRM_Contribute_PseudoConstant::financialType($finTypeId); | |
641 | if (!CRM_Core_Permission::check('edit contributions of type ' . $finType)) { | |
642 | unset($links[CRM_Core_Action::UPDATE]); | |
e9864b40 E |
643 | unset($links[CRM_Core_Action::RENEW]); |
644 | unset($links[CRM_Core_Action::FOLLOWUP]); | |
8a0604d2 E |
645 | } |
646 | if (!CRM_Core_Permission::check('delete contributions of type ' . $finType)) { | |
647 | unset($links[CRM_Core_Action::DELETE]); | |
648 | } | |
649 | } | |
650 | ||
6a488035 | 651 | } |