Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
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)) { | |
56 | $addWhere = "membership_type_id IN (" . implode(',' , array_keys($membershipTypes)) . ")"; | |
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 AH |
134 | ), |
135 | ts('more'), | |
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 | ||
169 | // if relevant, count related memberships | |
8d8bd076 | 170 | if (CRM_Utils_Array::value('is_current_member', $statusANDType[$dao->id]) // membership is active |
171 | && CRM_Utils_Array::value('relationship_type_id', $statusANDType[$dao->id]) // membership type allows inheritance | |
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 TO |
183 | $membership[$dao->id]['related_count'] = ($max_related == '' ? ts('%1 created', array(1 => $num_related)) : ts('%1 out of %2', array( |
184 | 1 => $num_related, | |
ae5ffbb7 | 185 | 2 => $max_related, |
353ffa53 | 186 | )) |
6a488035 | 187 | ); |
8d8bd076 | 188 | } |
189 | else { | |
6a488035 TO |
190 | $membership[$dao->id]['related_count'] = ts('N/A'); |
191 | } | |
192 | } | |
193 | ||
194 | //Below code gives list of all Membership Types associated | |
195 | //with an Organization(CRM-2016) | |
196 | $membershipTypes = CRM_Member_BAO_MembershipType::getMembershipTypesByOrg($this->_contactId); | |
197 | foreach ($membershipTypes as $key => $value) { | |
198 | $membershipTypes[$key]['action'] = CRM_Core_Action::formLink(self::membershipTypeslinks(), | |
199 | $mask, | |
200 | array( | |
201 | 'id' => $value['id'], | |
202 | 'cid' => $this->_contactId, | |
87dab4a4 AH |
203 | ), |
204 | ts('more'), | |
205 | FALSE, | |
206 | 'membershipType.organization.action', | |
207 | 'MembershipType', | |
208 | $value['id'] | |
6a488035 TO |
209 | ); |
210 | } | |
211 | ||
212 | $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership); | |
213 | $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive'); | |
214 | $this->assign('activeMembers', $activeMembers); | |
215 | $this->assign('inActiveMembers', $inActiveMembers); | |
216 | $this->assign('membershipTypes', $membershipTypes); | |
217 | ||
218 | if ($this->_contactId) { | |
219 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
220 | $this->assign('displayName', $displayName); | |
4e8065a9 | 221 | $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('membership', $this->_contactId); |
fa9fbb61 | 222 | // Refresh other tabs with related data |
2840a035 | 223 | $this->ajaxResponse['updateTabs'] = array( |
fa9fbb61 CW |
224 | '#tab_activity' => CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId), |
225 | '#tab_rel' => CRM_Contact_BAO_Contact::getCountComponent('rel', $this->_contactId), | |
2840a035 | 226 | ); |
c312052e CW |
227 | if (CRM_Core_Permission::access('CiviContribute')) { |
228 | $this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId); | |
229 | } | |
6a488035 TO |
230 | } |
231 | } | |
232 | ||
233 | /** | |
fe482240 | 234 | * called when action is view. |
6a488035 | 235 | * |
76e7a76c | 236 | * @return null |
6a488035 | 237 | */ |
00be9182 | 238 | public function view() { |
6a488035 TO |
239 | $controller = new CRM_Core_Controller_Simple( |
240 | 'CRM_Member_Form_MembershipView', | |
241 | ts('View Membership'), | |
242 | $this->_action | |
243 | ); | |
244 | $controller->setEmbedded(TRUE); | |
245 | $controller->set('id', $this->_id); | |
246 | $controller->set('cid', $this->_contactId); | |
247 | ||
248 | return $controller->run(); | |
249 | } | |
250 | ||
251 | /** | |
fe482240 | 252 | * called when action is update or new. |
6a488035 | 253 | * |
76e7a76c | 254 | * @return null |
6a488035 | 255 | */ |
00be9182 | 256 | public function edit() { |
6a488035 TO |
257 | // set https for offline cc transaction |
258 | $mode = CRM_Utils_Request::retrieve('mode', 'String', $this); | |
259 | if ($mode == 'test' || $mode == 'live') { | |
260 | CRM_Utils_System::redirectToSSL(); | |
261 | } | |
262 | ||
8d8bd076 | 263 | // build associated contributions ( note: this is called to show associated contributions in edit mode ) |
264 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
265 | $this->assign('accessContribution', FALSE); | |
266 | if (CRM_Core_Permission::access('CiviContribute')) { | |
267 | $this->assign('accessContribution', TRUE); | |
268 | CRM_Member_Page_Tab::associatedContribution($this->_contactId, $this->_id); | |
eb3cfcd6 | 269 | |
270 | //show associated soft credit when contribution payment is paid by different person in edit mode | |
271 | if ($this->_id && $this->_contactId) { | |
272 | $filter = " AND cc.id IN (SELECT contribution_id FROM civicrm_membership_payment WHERE membership_id = {$this->_id})"; | |
273 | $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $filter); | |
274 | if (!empty($softCreditList)) { | |
275 | $this->assign('softCredit', TRUE); | |
276 | $this->assign('softCreditRows', $softCreditList); | |
277 | } | |
278 | } | |
8d8bd076 | 279 | } |
6a488035 TO |
280 | } |
281 | ||
282 | if ($this->_action & CRM_Core_Action::RENEW) { | |
283 | $path = 'CRM_Member_Form_MembershipRenewal'; | |
284 | $title = ts('Renew Membership'); | |
285 | } | |
286 | else { | |
287 | $path = 'CRM_Member_Form_Membership'; | |
288 | $title = ts('Create Membership'); | |
289 | } | |
8d8bd076 | 290 | |
291 | $controller = new CRM_Core_Controller_Simple($path, $title, $this->_action); | |
6a488035 TO |
292 | $controller->setEmbedded(TRUE); |
293 | $controller->set('BAOName', $this->getBAOName()); | |
294 | $controller->set('id', $this->_id); | |
295 | $controller->set('cid', $this->_contactId); | |
296 | return $controller->run(); | |
297 | } | |
298 | ||
00be9182 | 299 | public function preProcess() { |
8d8bd076 | 300 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); |
6a488035 | 301 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); |
8d8bd076 | 302 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
6a488035 TO |
303 | |
304 | if ($context == 'standalone') { | |
305 | $this->_action = CRM_Core_Action::ADD; | |
306 | } | |
307 | else { | |
308 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); | |
309 | $this->assign('contactId', $this->_contactId); | |
310 | ||
311 | // check logged in url permission | |
312 | CRM_Contact_Page_View::checkUserPermission($this); | |
6a488035 TO |
313 | } |
314 | ||
315 | $this->assign('action', $this->_action); | |
316 | ||
317 | if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit memberships')) { | |
318 | // demote to view since user does not have edit membership rights | |
319 | $this->_permission = CRM_Core_Permission::VIEW; | |
320 | $this->assign('permission', 'view'); | |
321 | } | |
322 | } | |
323 | ||
324 | /** | |
dc195289 | 325 | * the main function that is called when the page loads, it decides the which action has to be taken for the page. |
6a488035 | 326 | * |
76e7a76c | 327 | * @return null |
6a488035 | 328 | */ |
00be9182 | 329 | public function run() { |
6a488035 TO |
330 | $this->preProcess(); |
331 | ||
332 | // check if we can process credit card membership | |
9be1374d EM |
333 | $newCredit = CRM_Core_Config::isEnabledBackOfficeCreditCardPayments(); |
334 | $this->assign('newCredit', $newCredit); | |
335 | ||
6a488035 TO |
336 | if ($newCredit) { |
337 | $this->_isPaymentProcessor = TRUE; | |
338 | } | |
339 | else { | |
340 | $this->_isPaymentProcessor = FALSE; | |
341 | } | |
342 | ||
343 | // Only show credit card membership signup if user has CiviContribute permission | |
344 | if (CRM_Core_Permission::access('CiviContribute')) { | |
345 | $this->_accessContribution = TRUE; | |
346 | $this->assign('accessContribution', TRUE); | |
91ef9be0 | 347 | |
348 | //show associated soft credit when contribution payment is paid by different person | |
349 | if ($this->_id && $this->_contactId) { | |
350 | $filter = " AND cc.id IN (SELECT contribution_id FROM civicrm_membership_payment WHERE membership_id = {$this->_id})"; | |
351 | $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $filter); | |
352 | if (!empty($softCreditList)) { | |
353 | $this->assign('softCredit', TRUE); | |
354 | $this->assign('softCreditRows', $softCreditList); | |
355 | } | |
356 | } | |
6a488035 TO |
357 | } |
358 | else { | |
359 | $this->_accessContribution = FALSE; | |
360 | $this->assign('accessContribution', FALSE); | |
91ef9be0 | 361 | $this->assign('softCredit', FALSE); |
6a488035 TO |
362 | } |
363 | ||
364 | if ($this->_action & CRM_Core_Action::VIEW) { | |
365 | $this->view(); | |
366 | } | |
d3e86119 | 367 | elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE | CRM_Core_Action::RENEW)) { |
8d8bd076 | 368 | self::setContext($this); |
6a488035 TO |
369 | $this->edit(); |
370 | } | |
371 | else { | |
8d8bd076 | 372 | self::setContext($this); |
6a488035 TO |
373 | $this->browse(); |
374 | } | |
375 | ||
376 | return parent::run(); | |
377 | } | |
378 | ||
bb3a214a | 379 | /** |
c490a46a | 380 | * @param CRM_Core_Form $form |
100fef9d | 381 | * @param int $contactId |
bb3a214a | 382 | */ |
8d8bd076 | 383 | public static function setContext(&$form, $contactId = NULL) { |
481a74f4 | 384 | $context = CRM_Utils_Request::retrieve('context', 'String', $form, FALSE, 'search'); |
6a488035 | 385 | |
8d8bd076 | 386 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $form); |
29571f63 | 387 | |
e803fd5a | 388 | $searchContext = CRM_Utils_Request::retrieve('searchContext', 'String', $form); |
29571f63 | 389 | |
6a488035 TO |
390 | //validate the qfKey |
391 | if (!CRM_Utils_Rule::qfKey($qfKey)) { | |
392 | $qfKey = NULL; | |
393 | } | |
394 | ||
395 | if (!$contactId) { | |
8d8bd076 | 396 | $contactId = $form->_contactId; |
6a488035 TO |
397 | } |
398 | ||
399 | switch ($context) { | |
400 | case 'dashboard': | |
8d8bd076 | 401 | $url = CRM_Utils_System::url('civicrm/member', 'reset=1'); |
6a488035 TO |
402 | break; |
403 | ||
404 | case 'membership': | |
8d8bd076 | 405 | $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$contactId}&selectedChild=member"); |
6a488035 TO |
406 | break; |
407 | ||
408 | case 'search': | |
409 | $urlParams = 'force=1'; | |
410 | if ($qfKey) { | |
411 | $urlParams .= "&qfKey=$qfKey"; | |
412 | } | |
8d8bd076 | 413 | $form->assign('searchKey', $qfKey); |
2a6da8d7 | 414 | |
29571f63 AS |
415 | if ($searchContext) { |
416 | $url = CRM_Utils_System::url("civicrm/$searchContext/search", $urlParams); | |
417 | } | |
418 | else { | |
419 | $url = CRM_Utils_System::url('civicrm/member/search', $urlParams); | |
420 | } | |
6a488035 TO |
421 | break; |
422 | ||
423 | case 'home': | |
424 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
425 | break; | |
426 | ||
427 | case 'activity': | |
428 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
429 | "reset=1&force=1&cid={$contactId}&selectedChild=activity" | |
430 | ); | |
431 | break; | |
432 | ||
433 | case 'standalone': | |
434 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
435 | break; | |
436 | ||
437 | case 'fulltext': | |
8d8bd076 | 438 | $action = CRM_Utils_Request::retrieve('action', 'String', $form); |
439 | $keyName = '&qfKey'; | |
6a488035 TO |
440 | $urlParams = 'force=1'; |
441 | $urlString = 'civicrm/contact/search/custom'; | |
442 | if ($action == CRM_Core_Action::UPDATE) { | |
8d8bd076 | 443 | if ($form->_contactId) { |
ec6d9c07 | 444 | $urlParams .= '&cid=' . $form->_contactId; |
6a488035 TO |
445 | } |
446 | $keyName = '&key'; | |
447 | $urlParams .= '&context=fulltext&action=view'; | |
448 | $urlString = 'civicrm/contact/view/membership'; | |
449 | } | |
450 | if ($qfKey) { | |
451 | $urlParams .= "$keyName=$qfKey"; | |
452 | } | |
8d8bd076 | 453 | $form->assign('searchKey', $qfKey); |
6a488035 TO |
454 | $url = CRM_Utils_System::url($urlString, $urlParams); |
455 | break; | |
456 | ||
457 | default: | |
458 | $cid = NULL; | |
459 | if ($contactId) { | |
460 | $cid = '&cid=' . $contactId; | |
461 | } | |
8d8bd076 | 462 | $url = CRM_Utils_System::url('civicrm/member/search', 'force=1' . $cid); |
6a488035 TO |
463 | break; |
464 | } | |
465 | ||
466 | $session = CRM_Core_Session::singleton(); | |
467 | $session->pushUserContext($url); | |
468 | } | |
469 | ||
470 | /** | |
fe482240 | 471 | * Get action links. |
6a488035 | 472 | * |
2a6da8d7 EM |
473 | * @param string $status |
474 | * @param null $isPaymentProcessor | |
475 | * @param null $accessContribution | |
476 | * @param bool $isCancelSupported | |
477 | * @param bool $isUpdateBilling | |
478 | * | |
a6c01b45 CW |
479 | * @return array |
480 | * (reference) of action links | |
6a488035 | 481 | */ |
ae5ffbb7 | 482 | public static function &links( |
500cfe81 | 483 | $status = 'all', |
353ffa53 TO |
484 | $isPaymentProcessor = NULL, |
485 | $accessContribution = NULL, | |
486 | $isCancelSupported = FALSE, | |
487 | $isUpdateBilling = FALSE | |
6a488035 TO |
488 | ) { |
489 | if (!CRM_Utils_Array::value('view', self::$_links)) { | |
490 | self::$_links['view'] = array( | |
491 | CRM_Core_Action::VIEW => array( | |
492 | 'name' => ts('View'), | |
493 | 'url' => 'civicrm/contact/view/membership', | |
494 | 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member', | |
495 | 'title' => ts('View Membership'), | |
496 | ), | |
497 | ); | |
498 | } | |
499 | ||
500 | if (!CRM_Utils_Array::value('all', self::$_links)) { | |
501 | $extraLinks = array( | |
502 | CRM_Core_Action::UPDATE => array( | |
503 | 'name' => ts('Edit'), | |
504 | 'url' => 'civicrm/contact/view/membership', | |
505 | 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member', | |
506 | 'title' => ts('Edit Membership'), | |
507 | ), | |
508 | CRM_Core_Action::RENEW => array( | |
509 | 'name' => ts('Renew'), | |
510 | 'url' => 'civicrm/contact/view/membership', | |
511 | 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member', | |
512 | 'title' => ts('Renew Membership'), | |
513 | ), | |
514 | CRM_Core_Action::FOLLOWUP => array( | |
515 | 'name' => ts('Renew-Credit Card'), | |
516 | 'url' => 'civicrm/contact/view/membership', | |
517 | 'qs' => 'action=renew&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member&mode=live', | |
518 | 'title' => ts('Renew Membership Using Credit Card'), | |
519 | ), | |
520 | CRM_Core_Action::DELETE => array( | |
521 | 'name' => ts('Delete'), | |
522 | 'url' => 'civicrm/contact/view/membership', | |
523 | 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&context=membership&selectedChild=member', | |
524 | 'title' => ts('Delete Membership'), | |
525 | ), | |
526 | ); | |
527 | if (!$isPaymentProcessor || !$accessContribution) { | |
528 | //unset the renew with credit card when payment | |
529 | //processor is not available or user is not permitted to create contributions | |
530 | unset($extraLinks[CRM_Core_Action::FOLLOWUP]); | |
531 | } | |
532 | self::$_links['all'] = self::$_links['view'] + $extraLinks; | |
533 | } | |
534 | ||
6a488035 TO |
535 | if ($isCancelSupported) { |
536 | $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.'); | |
537 | self::$_links['all'][CRM_Core_Action::DISABLE] = array( | |
538 | 'name' => ts('Cancel Auto-renewal'), | |
539 | 'url' => 'civicrm/contribute/unsubscribe', | |
540 | 'qs' => 'reset=1&cid=%%cid%%&mid=%%id%%&context=membership&selectedChild=member', | |
541 | 'title' => ts('Cancel Auto Renew Subscription'), | |
542 | 'extra' => 'onclick = "if (confirm(\'' . $cancelMessage . '\') ) { return true; else return false;}"', | |
543 | ); | |
544 | } | |
545 | elseif (isset(self::$_links['all'][CRM_Core_Action::DISABLE])) { | |
546 | unset(self::$_links['all'][CRM_Core_Action::DISABLE]); | |
547 | } | |
548 | ||
549 | if ($isUpdateBilling) { | |
550 | self::$_links['all'][CRM_Core_Action::MAP] = array( | |
551 | 'name' => ts('Change Billing Details'), | |
552 | 'url' => 'civicrm/contribute/updatebilling', | |
553 | 'qs' => 'reset=1&cid=%%cid%%&mid=%%id%%&context=membership&selectedChild=member', | |
554 | 'title' => ts('Change Billing Details'), | |
555 | ); | |
556 | } | |
557 | elseif (isset(self::$_links['all'][CRM_Core_Action::MAP])) { | |
558 | unset(self::$_links['all'][CRM_Core_Action::MAP]); | |
559 | } | |
560 | return self::$_links[$status]; | |
561 | } | |
562 | ||
563 | /** | |
fe482240 | 564 | * Define action links for membership types of related organization. |
6a488035 | 565 | * |
a6c01b45 CW |
566 | * @return array |
567 | * self::$_membershipTypesLinks array of action links | |
6a488035 | 568 | */ |
00be9182 | 569 | public static function &membershipTypesLinks() { |
6a488035 TO |
570 | if (!self::$_membershipTypesLinks) { |
571 | self::$_membershipTypesLinks = array( | |
572 | CRM_Core_Action::VIEW => array( | |
573 | 'name' => ts('Members'), | |
574 | 'url' => 'civicrm/member/search/', | |
575 | 'qs' => 'reset=1&force=1&type=%%id%%', | |
576 | 'title' => ts('Search'), | |
577 | ), | |
578 | CRM_Core_Action::UPDATE => array( | |
579 | 'name' => ts('Edit'), | |
580 | 'url' => 'civicrm/admin/member/membershipType', | |
581 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
582 | 'title' => ts('Edit Membership Type'), | |
583 | ), | |
584 | ); | |
585 | } | |
586 | return self::$_membershipTypesLinks; | |
587 | } | |
588 | ||
589 | /** | |
fe482240 | 590 | * used for the to show the associated. |
6a488035 | 591 | * contribution for the membership |
76e7a76c CW |
592 | * |
593 | * @param int $contactId | |
594 | * @param int $membershipId | |
6a488035 | 595 | */ |
141d3170 | 596 | public static function associatedContribution($contactId = NULL, $membershipId = NULL) { |
8d8bd076 | 597 | $controller = new CRM_Core_Controller_Simple( |
598 | 'CRM_Contribute_Form_Search', | |
599 | ts('Contributions'), | |
600 | NULL, | |
601 | FALSE, FALSE, TRUE | |
602 | ); | |
603 | $controller->setEmbedded(TRUE); | |
604 | $controller->reset(); | |
605 | $controller->set('force', 1); | |
606 | $controller->set('cid', $contactId); | |
607 | $controller->set('memberId', $membershipId); | |
608 | $controller->set('context', 'contribution'); | |
609 | $controller->process(); | |
610 | $controller->run(); | |
6a488035 TO |
611 | } |
612 | ||
613 | /** | |
fe482240 | 614 | * Get BAO Name. |
6a488035 | 615 | * |
a6c01b45 CW |
616 | * @return string |
617 | * Classname of BAO. | |
6a488035 | 618 | */ |
00be9182 | 619 | public function getBAOName() { |
6a488035 TO |
620 | return 'CRM_Member_BAO_Membership'; |
621 | } | |
96025800 | 622 | |
8a0604d2 | 623 | static function getPermissionedLinks($memTypeID, &$links) { |
66af7c48 PN |
624 | if (!self::isACLFinancialTypeStatus()) { |
625 | return FALSE; | |
626 | } | |
8a0604d2 E |
627 | $finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memTypeID, 'financial_type_id'); |
628 | $finType = CRM_Contribute_PseudoConstant::financialType($finTypeId); | |
629 | if (!CRM_Core_Permission::check('edit contributions of type ' . $finType)) { | |
630 | unset($links[CRM_Core_Action::UPDATE]); | |
e9864b40 E |
631 | unset($links[CRM_Core_Action::RENEW]); |
632 | unset($links[CRM_Core_Action::FOLLOWUP]); | |
8a0604d2 E |
633 | } |
634 | if (!CRM_Core_Permission::check('delete contributions of type ' . $finType)) { | |
635 | unset($links[CRM_Core_Action::DELETE]); | |
636 | } | |
637 | } | |
638 | ||
6a488035 | 639 | } |