INFRA-132 - Cleanup generated dao docblocks
[civicrm-core.git] / CRM / Grant / Page / Tab.php
CommitLineData
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * This class handle grant related functions
38 *
39 */
40class CRM_Grant_Page_Tab extends CRM_Contact_Page_View {
41
42 /**
43 * The action links that we need to display for the browse screen
44 *
45 * @var array
6a488035
TO
46 */
47 static $_links = NULL;
48 public $_permission = NULL;
49 public $_contactId = NULL;
50
51 /**
dc195289 52 * called when action is browse
6a488035
TO
53 *
54 * return null
95ea96be
EM
55 */
56 function browse() {
6a488035
TO
57 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Search', ts('Grants'), $this->_action);
58 $controller->setEmbedded(TRUE);
59 $controller->reset();
60 $controller->set('cid', $this->_contactId);
61 $controller->set('context', 'grant');
62 $controller->process();
63 $controller->run();
64
65 if ($this->_contactId) {
66 $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
67 $this->assign('displayName', $displayName);
4e8065a9 68 $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('grant', $this->_contactId);
6a488035
TO
69 }
70 }
71
72 /**
dc195289 73 * called when action is view
6a488035
TO
74 *
75 * return null
6a488035 76 */
00be9182 77 public function view() {
6a488035
TO
78 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_GrantView', 'View Grant', $this->_action);
79 $controller->setEmbedded(TRUE);
80 $controller->set('id', $this->_id);
81 $controller->set('cid', $this->_contactId);
82
83 return $controller->run();
84 }
85
86 /**
dc195289 87 * called when action is update or new
6a488035
TO
88 *
89 * return null
6a488035 90 */
00be9182 91 public function edit() {
6a488035
TO
92 $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_Grant', 'Create grant', $this->_action);
93 $controller->setEmbedded(TRUE);
94 $controller->set('id', $this->_id);
95 $controller->set('cid', $this->_contactId);
96
97 return $controller->run();
98 }
99
100 /**
100fef9d 101 * Build all the data structures needed to build the form
6a488035
TO
102 *
103 * @return void
6a488035 104 */
00be9182 105 public function preProcess() {
353ffa53 106 $context = CRM_Utils_Request::retrieve('context', 'String', $this);
6a488035 107 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
353ffa53 108 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
6a488035
TO
109
110 if ($context == 'standalone') {
111 $this->_action = CRM_Core_Action::ADD;
112 }
113 else {
114 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
115 $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
116 $this->assign('contactId', $this->_contactId);
117 $this->assign('displayName', $displayName);
118
119 // check logged in url permission
120 CRM_Contact_Page_View::checkUserPermission($this);
6a488035
TO
121 }
122 $this->assign('action', $this->_action);
123
124 if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit grants')) {
125 // demote to view since user does not have edit grant rights
126 $this->_permission = CRM_Core_Permission::VIEW;
127 $this->assign('permission', 'view');
128 }
129 }
130
131 /**
dc195289 132 * the main function that is called when the page loads,
6a488035
TO
133 * it decides the which action has to be taken for the page.
134 *
135 * return null
6a488035 136 */
00be9182 137 public function run() {
6a488035
TO
138 $this->preProcess();
139
140 $this->setContext();
141
142 if ($this->_action & CRM_Core_Action::VIEW) {
143 $this->view();
144 }
145 elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
146 $this->edit();
147 }
148 else {
149 $this->browse();
150 }
151 return parent::run();
152 }
153
00be9182 154 public function setContext() {
353ffa53 155 $context = CRM_Utils_Request::retrieve('context', 'String', $this);
6a488035 156 $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this);
353ffa53 157 $session = CRM_Core_Session::singleton();
6a488035
TO
158
159 $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
160 //validate the qfKey
161 if (!CRM_Utils_Rule::qfKey($qfKey)) {
162 $qfKey = NULL;
163 }
164
165 switch ($context) {
166 case 'search':
167 $urlParams = 'force=1';
168 if ($qfKey) {
169 $urlParams .= "&qfKey=$qfKey";
170 }
171 $this->assign('searchKey', $qfKey);
172
173 $url = CRM_Utils_System::url('civicrm/grant/search', $urlParams);
174 break;
175
176 case 'dashboard':
177 $url = CRM_Utils_System::url('civicrm/grant', 'reset=1');
178 break;
179
180 case 'edit':
181 $url = CRM_utils_System::url('civicrm/contact/view/grant', 'reset=1&id=' . $this->_id . '&cid=' . $this->_contactId . '&action=view&context=grant&selectedChild=grant');
182 break;
183
184 case 'grant':
185 $url = CRM_Utils_System::url('civicrm/contact/view', 'action=browse&selectedChild=grant&cid=' . $this->_contactId);
186 break;
187
188 case 'standalone':
189 $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
190 break;
191
192 default:
193 $cid = NULL;
194 if ($this->_contactId) {
195 $cid = '&cid=' . $this->_contactId;
196 }
197 $url = CRM_Utils_System::url('civicrm/grant/search', 'reset=1&force=1' . $cid);
198 break;
199 }
200 $session->pushUserContext($url);
201
202 if (CRM_Utils_Request::retrieve('confirmed', 'Boolean',
353ffa53
TO
203 CRM_Core_DAO::$_nullObject
204 )
205 ) {
6a488035
TO
206 CRM_Grant_BAO_Grant::del($this->_id);
207 CRM_Utils_System::redirect($url);
208 }
209 }
210}