3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Pledge_Page_Tab
extends CRM_Core_Page
{
18 public $_permission = NULL;
19 public $_contactId = NULL;
22 * called when action is browse.
24 public function browse() {
25 $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_Search', ts('Pledges'), $this->_action
);
26 $controller->setEmbedded(TRUE);
28 $controller->set('cid', $this->_contactId
);
29 $controller->set('context', 'pledge');
30 $controller->set('limit', '25');
31 $controller->process();
34 if ($this->_contactId
) {
35 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
36 $this->assign('displayName', $displayName);
37 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('pledge', $this->_contactId
);
38 // Refresh other tabs with related data
39 $this->ajaxResponse
['updateTabs'] = [
40 '#tab_contribute' => CRM_Contact_BAO_Contact
::getCountComponent('contribution', $this->_contactId
),
41 '#tab_activity' => CRM_Contact_BAO_Contact
::getCountComponent('activity', $this->_contactId
),
47 * called when action is view.
51 public function view() {
52 $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_PledgeView',
56 $controller->setEmbedded(TRUE);
57 $controller->set('id', $this->_id
);
58 $controller->set('cid', $this->_contactId
);
60 return $controller->run();
64 * called when action is update or new.
68 public function edit() {
69 $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_Pledge',
73 $controller->setEmbedded(TRUE);
74 $controller->set('id', $this->_id
);
75 $controller->set('cid', $this->_contactId
);
77 return $controller->run();
80 public function preProcess() {
81 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
82 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
83 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
85 if ($context == 'standalone') {
86 $this->_action
= CRM_Core_Action
::ADD
;
89 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
90 $this->assign('contactId', $this->_contactId
);
92 // check logged in url permission
93 CRM_Contact_Page_View
::checkUserPermission($this);
96 $this->assign('action', $this->_action
);
98 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit pledges')) {
99 // demote to view since user does not have edit pledge rights
100 $this->_permission
= CRM_Core_Permission
::VIEW
;
101 $this->assign('permission', 'view');
106 * the main function that is called when the page loads, it decides the which action has to be taken for the page.
110 public function run() {
113 // check if we can process credit card registration
114 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
116 self
::setContext($this);
118 if ($this->_action
& CRM_Core_Action
::VIEW
) {
121 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
124 elseif ($this->_action
& CRM_Core_Action
::DETACH
) {
125 CRM_Pledge_BAO_Pledge
::cancel($this->_id
);
126 $session = CRM_Core_Session
::singleton();
127 $session->setStatus(ts('Pledge has been Cancelled and all scheduled (not completed) payments have been cancelled.<br />'));
128 CRM_Utils_System
::redirect($session->popUserContext());
134 return parent
::run();
142 public static function setContext(&$form) {
143 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $form, FALSE, 'search');
145 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $form);
146 // validate the qfKey
147 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
153 case 'pledgeDashboard':
154 $url = CRM_Utils_System
::url('civicrm/pledge', 'reset=1');
158 $urlParams = 'force=1';
160 $urlParams .= "&qfKey=$qfKey";
163 $url = CRM_Utils_System
::url('civicrm/pledge/search', $urlParams);
167 $url = CRM_Utils_System
::url('civicrm/user', 'reset=1');
171 $url = CRM_Utils_System
::url('civicrm/contact/view',
172 "reset=1&force=1&cid={$form->_contactId}&selectedChild=pledge"
177 $url = CRM_Utils_System
::url('civicrm/dashboard', 'force=1');
181 $url = CRM_Utils_System
::url('civicrm/contact/view',
182 "reset=1&force=1&cid={$form->_contactId}&selectedChild=activity"
187 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
192 if ($form->_contactId
) {
193 $cid = '&cid=' . $form->_contactId
;
195 $url = CRM_Utils_System
::url('civicrm/pledge/search',
200 $session = CRM_Core_Session
::singleton();
201 $session->pushUserContext($url);