[REF] Update fetchAll function signature to match parent function
[civicrm-core.git] / CRM / Activity / Page / Tab.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
b6c94f42 19 * Main page for viewing activities,
6a488035
TO
20 */
21class CRM_Activity_Page_Tab extends CRM_Core_Page {
22
23 /**
fe482240 24 * Browse all activities for a particular contact.
6a488035 25 */
00be9182 26 public function browse() {
6a488035
TO
27 $this->assign('admin', FALSE);
28 $this->assign('context', 'activity');
29
30 // also create the form element for the activity filter box
39c4fa3a
DL
31 $controller = new CRM_Core_Controller_Simple(
32 'CRM_Activity_Form_ActivityFilter',
33 ts('Activity Filter'),
34 NULL,
35 FALSE, FALSE, TRUE
6a488035
TO
36 );
37 $controller->set('contactId', $this->_contactId);
38 $controller->setEmbedded(TRUE);
39 $controller->run();
4e8065a9 40 $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId);
6a488035
TO
41 }
42
70599df6 43 /**
44 * Edit tab.
45 *
46 * @return mixed
47 */
00be9182 48 public function edit() {
6a488035 49 // used for ajax tabs
edc80cda 50 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
6a488035
TO
51 $this->assign('context', $context);
52
53 $this->_id = CRM_Utils_Request::retrieve('id', 'Integer', $this);
54
55 $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Integer', $this);
56
57 $activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
58
59 // Email and Create Letter activities use a different form class
81eb483d
PN
60 $emailTypeValue = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity',
61 'activity_type_id',
62 'Email'
6a488035
TO
63 );
64
81eb483d
PN
65 $letterTypeValue = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity',
66 'activity_type_id',
67 'Print PDF Letter'
6a488035
TO
68 );
69
6a488035
TO
70 switch ($activityTypeId) {
71 case $emailTypeValue:
72 $wrapper = new CRM_Utils_Wrapper();
be2fb01f 73 $arguments = ['attachUpload' => 1];
6a488035
TO
74 return $wrapper->run('CRM_Contact_Form_Task_Email', ts('Email a Contact'), $arguments);
75
76 case $letterTypeValue:
77 $wrapper = new CRM_Utils_Wrapper();
be2fb01f 78 $arguments = ['attachUpload' => 1];
6a488035
TO
79 return $wrapper->run('CRM_Contact_Form_Task_PDF', ts('Create PDF Letter'), $arguments);
80
81 default:
82 $controller = new CRM_Core_Controller_Simple('CRM_Activity_Form_Activity',
83 ts('Contact Activities'),
84 $this->_action,
85 FALSE, FALSE, FALSE, TRUE
86 );
87 }
88
89 $controller->setEmbedded(TRUE);
90
91 $controller->set('contactId', $this->_contactId);
92 $controller->set('atype', $activityTypeId);
93 $controller->set('id', $this->_id);
94 $controller->set('pid', $this->get('pid'));
95 $controller->set('action', $this->_action);
96 $controller->set('context', $context);
97
98 $controller->process();
99 $controller->run();
100 }
101
102 /**
b6c94f42 103 * Heart of the viewing process.
6a488035 104 *
b6c94f42 105 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
6a488035 106 */
00be9182 107 public function preProcess() {
6a488035
TO
108 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
109 $this->assign('contactId', $this->_contactId);
7808aae6 110 // FIXME: need to fix this conflict
6a488035
TO
111 $this->assign('contactID', $this->_contactId);
112
113 // check logged in url permission
114 CRM_Contact_Page_View::checkUserPermission($this);
115
6a488035
TO
116 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
117 $this->assign('action', $this->_action);
55806731 118 $this->assign('allow_edit_inbound_emails', CRM_Activity_BAO_Activity::checkEditInboundEmailsPermissions());
6a488035
TO
119
120 // also create the form element for the activity links box
39c4fa3a
DL
121 $controller = new CRM_Core_Controller_Simple(
122 'CRM_Activity_Form_ActivityLinks',
123 ts('Activity Links'),
124 NULL,
125 FALSE, FALSE, TRUE
6a488035
TO
126 );
127 $controller->setEmbedded(TRUE);
128 $controller->run();
129 }
130
00be9182 131 public function delete() {
39c4fa3a
DL
132 $controller = new CRM_Core_Controller_Simple(
133 'CRM_Activity_Form_Activity',
6a488035
TO
134 ts('Activity Record'),
135 $this->_action
136 );
137 $controller->set('id', $this->_id);
138 $controller->setEmbedded(TRUE);
139 $controller->process();
140 $controller->run();
141 }
142
143 /**
100fef9d 144 * Perform actions and display for activities.
6a488035 145 */
00be9182 146 public function run() {
edc80cda 147 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
6a488035 148 $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
353ffa53 149 $action = CRM_Utils_Request::retrieve('action', 'String', $this);
6a488035
TO
150 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
151
7808aae6 152 // Do check for view/edit operation.
6a488035 153 if ($this->_id &&
be2fb01f 154 in_array($action, [CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW])
6a488035
TO
155 ) {
156 if (!CRM_Activity_BAO_Activity::checkPermission($this->_id, $action)) {
157 CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
158 }
159 }
160
161 if ($context == 'standalone' || (!$contactId && ($action != CRM_Core_Action::DELETE) && !$this->_id)) {
162 $this->_action = CRM_Core_Action::ADD;
163 $this->assign('action', $this->_action);
164 }
165 else {
166 // we should call contact view, preprocess only for activity in contact summary
167 $this->preProcess();
168 }
169
170 // route behaviour of contact/view/activity based on action defined
32864ccf 171 if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::VIEW)
6a488035
TO
172 ) {
173 $this->edit();
174 $activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
175
176 // Email and Create Letter activities use a different form class
81eb483d
PN
177 $emailTypeValue = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity',
178 'activity_type_id',
179 'Email'
6a488035
TO
180 );
181
81eb483d
PN
182 $letterTypeValue = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity',
183 'activity_type_id',
184 'Print PDF Letter'
6a488035
TO
185 );
186
be2fb01f 187 if (in_array($activityTypeId, [
353ffa53 188 $emailTypeValue,
8d7a9d07 189 $letterTypeValue,
be2fb01f 190 ])) {
6a488035
TO
191 return;
192 }
193 }
194 elseif ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::DETACH)) {
195 $this->delete();
196 }
197 else {
198 $this->browse();
199 }
200
201 return parent::run();
202 }
96025800 203
6a488035 204}