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