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