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
19 * This class handle grant related functions
22 class CRM_Grant_Page_Tab
extends CRM_Contact_Page_View
{
25 * The action links that we need to display for the browse screen.
29 public static $_links = NULL;
30 public $_permission = NULL;
31 public $_contactId = NULL;
34 * called when action is browse.
37 public function browse() {
38 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Search', ts('Grants'), $this->_action
);
39 $controller->setEmbedded(TRUE);
41 $controller->set('cid', $this->_contactId
);
42 $controller->set('context', 'grant');
43 $controller->process();
46 if ($this->_contactId
) {
47 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
48 $this->assign('displayName', $displayName);
49 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('grant', $this->_contactId
);
54 * called when action is view.
58 public function view() {
59 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_GrantView', 'View Grant', $this->_action
);
60 $controller->setEmbedded(TRUE);
61 $controller->set('id', $this->_id
);
62 $controller->set('cid', $this->_contactId
);
64 return $controller->run();
68 * called when action is update or new.
72 public function edit() {
73 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Grant', 'Create grant', $this->_action
);
74 $controller->setEmbedded(TRUE);
75 $controller->set('id', $this->_id
);
76 $controller->set('cid', $this->_contactId
);
78 return $controller->run();
82 * Build all the data structures needed to build the form.
86 public function preProcess() {
87 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
88 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
89 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
91 if ($context == 'standalone') {
92 $this->_action
= CRM_Core_Action
::ADD
;
95 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
96 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
97 $this->assign('contactId', $this->_contactId
);
98 $this->assign('displayName', $displayName);
100 // check logged in url permission
101 CRM_Contact_Page_View
::checkUserPermission($this);
103 $this->assign('action', $this->_action
);
105 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit grants')) {
106 // demote to view since user does not have edit grant rights
107 $this->_permission
= CRM_Core_Permission
::VIEW
;
108 $this->assign('permission', 'view');
113 * the main function that is called when the page loads,
114 * it decides the which action has to be taken for the page.
118 public function run() {
123 if ($this->_action
& CRM_Core_Action
::VIEW
) {
126 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
132 return parent
::run();
135 public function setContext() {
136 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
137 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Integer', $this);
138 $session = CRM_Core_Session
::singleton();
140 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
142 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
148 $urlParams = 'force=1';
150 $urlParams .= "&qfKey=$qfKey";
152 $this->assign('searchKey', $qfKey);
154 $url = CRM_Utils_System
::url('civicrm/grant/search', $urlParams);
158 $url = CRM_Utils_System
::url('civicrm/grant', 'reset=1');
162 $url = CRM_Utils_System
::url('civicrm/contact/view/grant', 'reset=1&id=' . $this->_id
. '&cid=' . $this->_contactId
. '&action=view&context=grant&selectedChild=grant');
166 $url = CRM_Utils_System
::url('civicrm/contact/view', 'action=browse&selectedChild=grant&cid=' . $this->_contactId
);
170 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
175 if ($this->_contactId
) {
176 $cid = '&cid=' . $this->_contactId
;
178 $url = CRM_Utils_System
::url('civicrm/grant/search', 'reset=1&force=1' . $cid);
181 $session->pushUserContext($url);
183 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean')) {
184 CRM_Grant_BAO_Grant
::del($this->_id
);
185 CRM_Utils_System
::redirect($url);