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