Add upgrade for label to name conversion
[civicrm-core.git] / CRM / Event / Page / Tab.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Event_Page_Tab extends CRM_Core_Page {
18
19 public $_permission = NULL;
20 public $_contactId = NULL;
21
22 /**
23 * called when action is browse.
24 */
25 public function browse() {
26 $controller = new CRM_Core_Controller_Simple(
27 'CRM_Event_Form_Search',
28 ts('Events'),
29 $this->_action
30 );
31 $controller->setEmbedded(TRUE);
32 $controller->reset();
33 $controller->set('cid', $this->_contactId);
34 $controller->set('context', 'participant');
35 $controller->process();
36 $controller->run();
37
38 if ($this->_contactId) {
39 $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
40 $this->assign('displayName', $displayName);
41 $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('participant', $this->_contactId);
42 // Refresh other tabs with related data
43 $this->ajaxResponse['updateTabs'] = [
44 '#tab_activity' => CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId),
45 ];
46 if (CRM_Core_Permission::access('CiviContribute')) {
47 $this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
48 }
49 }
50 }
51
52 /**
53 * called when action is view.
54 *
55 * @return null
56 */
57 public function view() {
58 // build associated contributions
59 $this->associatedContribution();
60
61 $controller = new CRM_Core_Controller_Simple(
62 'CRM_Event_Form_ParticipantView',
63 ts('View Participant'),
64 $this->_action
65 );
66 $controller->setEmbedded(TRUE);
67 $controller->set('id', $this->_id);
68 $controller->set('cid', $this->_contactId);
69
70 return $controller->run();
71 }
72
73 /**
74 * called when action is update or new.
75 *
76 * @return null
77 */
78 public function edit() {
79 // set https for offline cc transaction
80 $mode = CRM_Utils_Request::retrieve('mode', 'Alphanumeric', $this);
81 if ($mode == 'test' || $mode == 'live') {
82 CRM_Utils_System::redirectToSSL();
83 }
84
85 if ($this->_action != CRM_Core_Action::ADD) {
86 // get associated contributions only on edit/delete
87 $this->associatedContribution();
88 }
89
90 $controller = new CRM_Core_Controller_Simple(
91 'CRM_Event_Form_Participant',
92 'Create Participation',
93 $this->_action
94 );
95
96 $controller->setEmbedded(TRUE);
97 $controller->set('id', $this->_id);
98 $controller->set('cid', $this->_contactId);
99
100 return $controller->run();
101 }
102
103 public function delete() {
104 $controller = new CRM_Core_Controller_Simple(
105 'CRM_Event_Form_Participant',
106 ts('Delete Participant'),
107 $this->_action
108 );
109
110 $controller->setEmbedded(TRUE);
111 $controller->set('id', $this->_id);
112 $controller->set('cid', $this->_contactId);
113 $controller->run();
114 }
115
116 public function preProcess() {
117 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
118 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
119 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
120
121 if (($context == 'standalone' || $context === 'search') && $this->_action !== CRM_Core_Action::VIEW) {
122 $this->_action = CRM_Core_Action::ADD;
123 }
124 else {
125 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
126 $this->assign('contactId', $this->_contactId);
127
128 // check logged in url permission
129 CRM_Contact_Page_View::checkUserPermission($this);
130 }
131
132 $this->assign('action', $this->_action);
133
134 if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit event participants')) {
135 // demote to view since user does not have edit event participants rights
136 $this->_permission = CRM_Core_Permission::VIEW;
137 $this->assign('permission', 'view');
138 }
139 }
140
141 /**
142 * the main function that is called when the page loads, it decides the which action has to be taken for the page.
143 *
144 * @return null
145 */
146 public function run() {
147 $this->preProcess();
148
149 // check if we can process credit card registration
150 $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments());
151
152 // Only show credit card registration button if user has CiviContribute permission
153 if (CRM_Core_Permission::access('CiviContribute')) {
154 $this->assign('accessContribution', TRUE);
155 }
156 else {
157 $this->assign('accessContribution', FALSE);
158 }
159
160 $this->setContext();
161
162 if ($this->_action & CRM_Core_Action::VIEW) {
163 $this->view();
164 }
165 elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
166 $this->edit();
167 }
168 elseif ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::DETACH)) {
169 $this->delete();
170 }
171 else {
172 $this->browse();
173 }
174
175 return parent::run();
176 }
177
178 public function setContext() {
179 $context = CRM_Utils_Request::retrieve('context',
180 'String', $this, FALSE, 'search'
181 );
182 $compContext = CRM_Utils_Request::retrieve('compContext',
183 'String', $this
184 );
185
186 $searchContext = CRM_Utils_Request::retrieve('searchContext', 'String', $this);
187
188 $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
189
190 //validate the qfKey
191 if (!CRM_Utils_Rule::qfKey($qfKey)) {
192 $qfKey = NULL;
193 }
194
195 switch ($context) {
196 case 'dashboard':
197 $url = CRM_Utils_System::url('civicrm/event', 'reset=1');
198 break;
199
200 case 'search':
201 $urlParams = 'force=1';
202 if ($qfKey) {
203 $urlParams .= "&qfKey=$qfKey";
204 }
205 $this->assign('searchKey', $qfKey);
206
207 if ($compContext == 'advanced') {
208 $url = CRM_Utils_System::url('civicrm/contact/search/advanced', $urlParams);
209 }
210 elseif ($searchContext) {
211 $url = CRM_Utils_System::url("civicrm/$searchContext/search", $urlParams);
212 }
213 else {
214 $url = CRM_Utils_System::url('civicrm/event/search', $urlParams);
215 }
216 break;
217
218 case 'user':
219 $url = CRM_Utils_System::url('civicrm/user', 'reset=1');
220 break;
221
222 case 'participant':
223 $url = CRM_Utils_System::url('civicrm/contact/view',
224 "reset=1&force=1&cid={$this->_contactId}&selectedChild=participant"
225 );
226 break;
227
228 case 'home':
229 $url = CRM_Utils_System::url('civicrm/dashboard', 'force=1');
230 break;
231
232 case 'activity':
233 $url = CRM_Utils_System::url('civicrm/contact/view',
234 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
235 );
236 break;
237
238 case 'standalone':
239 $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
240 break;
241
242 case 'fulltext':
243 $keyName = '&qfKey';
244 $urlParams = 'force=1';
245 $urlString = 'civicrm/contact/search/custom';
246 if ($this->_action == CRM_Core_Action::UPDATE) {
247 if ($this->_contactId) {
248 $urlParams .= '&cid=' . $this->_contactId;
249 }
250 $keyName = '&key';
251 $urlParams .= '&context=fulltext&action=view';
252 $urlString = 'civicrm/contact/view/participant';
253 }
254 if ($qfKey) {
255 $urlParams .= "$keyName=$qfKey";
256 }
257 $this->assign('searchKey', $qfKey);
258 $url = CRM_Utils_System::url($urlString, $urlParams);
259 break;
260
261 default:
262 $cid = NULL;
263 if ($this->_contactId) {
264 $cid = '&cid=' . $this->_contactId;
265 }
266 $url = CRM_Utils_System::url('civicrm/event/search',
267 'force=1' . $cid
268 );
269 break;
270 }
271 $session = CRM_Core_Session::singleton();
272 $session->pushUserContext($url);
273 }
274
275 /**
276 * used for the to show the associated
277 * contribution for the participant
278 */
279 public function associatedContribution() {
280 if (CRM_Core_Permission::access('CiviContribute')) {
281 $this->assign('accessContribution', TRUE);
282 $controller = new CRM_Core_Controller_Simple(
283 'CRM_Contribute_Form_Search',
284 ts('Contributions'),
285 NULL,
286 FALSE, FALSE, TRUE
287 );
288 $controller->setEmbedded(TRUE);
289 $controller->set('force', 1);
290 $controller->set('skip_cid', TRUE);
291 $controller->set('participantId', $this->_id);
292 $controller->set('context', 'contribution');
293 $controller->process();
294 $controller->run();
295 }
296 else {
297 $this->assign('accessContribution', FALSE);
298 }
299 }
300
301 }