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