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