Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
df371444 | 35 | * This class does pre processing for viewing an activity or their revisions. |
6a488035 TO |
36 | */ |
37 | class CRM_Case_Form_ActivityView extends CRM_Core_Form { | |
38 | ||
39 | /** | |
fe482240 | 40 | * Process the view. |
6a488035 TO |
41 | */ |
42 | public function preProcess() { | |
353ffa53 TO |
43 | $contactID = CRM_Utils_Request::retrieve('cid', 'Integer', $this, TRUE); |
44 | $activityID = CRM_Utils_Request::retrieve('aid', 'Integer', $this, TRUE); | |
a3d827a7 CW |
45 | $revs = CRM_Utils_Request::retrieve('revs', 'Boolean'); |
46 | $caseID = CRM_Utils_Request::retrieve('caseID', 'Boolean'); | |
6a488035 TO |
47 | $activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', |
48 | $activityID, | |
49 | 'subject' | |
50 | ); | |
6a488035 TO |
51 | |
52 | //check for required permissions, CRM-6264 | |
53 | if ($activityID && | |
54 | !CRM_Activity_BAO_Activity::checkPermission($activityID, CRM_Core_Action::VIEW) | |
55 | ) { | |
56 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); | |
57 | } | |
58 | ||
59 | $this->assign('contactID', $contactID); | |
60 | $this->assign('caseID', $caseID); | |
6a488035 TO |
61 | // CRM-9145 |
62 | $this->assign('activityID', $activityID); | |
63 | ||
64 | $xmlProcessor = new CRM_Case_XMLProcessor_Report(); | |
65 | $report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE); | |
66 | ||
67 | $attachmentUrl = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityID); | |
68 | if ($attachmentUrl) { | |
be2fb01f | 69 | $report['fields'][] = [ |
6a488035 TO |
70 | 'label' => 'Attachment(s)', |
71 | 'value' => $attachmentUrl, | |
72 | 'type' => 'Link', | |
be2fb01f | 73 | ]; |
6a488035 TO |
74 | } |
75 | ||
76 | $tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity'); | |
77 | if (!empty($tags)) { | |
be2fb01f | 78 | $allTag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', ['onlyActive' => FALSE]); |
6a488035 TO |
79 | foreach ($tags as $tid) { |
80 | $tags[$tid] = $allTag[$tid]; | |
81 | } | |
be2fb01f | 82 | $report['fields'][] = [ |
6a488035 TO |
83 | 'label' => 'Tags', |
84 | 'value' => implode('<br />', $tags), | |
85 | 'type' => 'String', | |
be2fb01f | 86 | ]; |
6a488035 TO |
87 | } |
88 | ||
89 | $this->assign('report', $report); | |
90 | ||
91 | $latestRevisionID = CRM_Activity_BAO_Activity::getLatestActivityId($activityID); | |
92 | ||
be2fb01f | 93 | $viewPriorActivities = []; |
6a488035 TO |
94 | $priorActivities = CRM_Activity_BAO_Activity::getPriorAcitivities($activityID); |
95 | foreach ($priorActivities as $activityId => $activityValues) { | |
96 | if (CRM_Case_BAO_Case::checkPermission($activityId, 'view', NULL, $contactID)) { | |
97 | $viewPriorActivities[$activityId] = $activityValues; | |
98 | } | |
99 | } | |
100 | ||
101 | if ($revs) { | |
56cbe6ae | 102 | CRM_Utils_System::setTitle(ts('Activity Revision History')); |
6a488035 | 103 | $this->assign('revs', $revs); |
6a488035 TO |
104 | $this->assign('result', $viewPriorActivities); |
105 | $this->assign('subject', $activitySubject); | |
106 | $this->assign('latestRevisionID', $latestRevisionID); | |
107 | } | |
108 | else { | |
109 | if (count($viewPriorActivities) > 1) { | |
110 | $this->assign('activityID', $activityID); | |
111 | } | |
112 | ||
113 | if ($latestRevisionID != $activityID) { | |
114 | $this->assign('latestRevisionID', $latestRevisionID); | |
115 | } | |
116 | } | |
117 | ||
118 | $parentID = CRM_Activity_BAO_Activity::getParentActivity($activityID); | |
119 | if ($parentID) { | |
120 | $this->assign('parentID', $parentID); | |
121 | } | |
122 | ||
123 | //viewing activity should get diplayed in recent list.CRM-4670 | |
124 | $activityTypeID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'activity_type_id'); | |
125 | ||
44f817d4 | 126 | $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate'); |
034500d4 | 127 | $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); |
128 | $activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID); | |
6a488035 TO |
129 | if (!empty($activityTargetContacts)) { |
130 | $recentContactId = $activityTargetContacts[0]; | |
131 | } | |
132 | else { | |
133 | $recentContactId = $contactID; | |
134 | } | |
135 | ||
136 | if (!isset($caseID)) { | |
137 | $caseID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id'); | |
138 | } | |
139 | ||
140 | $url = CRM_Utils_System::url('civicrm/case/activity/view', | |
141 | "reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home" | |
142 | ); | |
143 | ||
144 | $recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId); | |
145 | // add the recently created Activity | |
146 | $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE); | |
147 | ||
148 | $title = ""; | |
149 | if (isset($activitySubject)) { | |
150 | $title = $activitySubject . ' - '; | |
151 | } | |
152 | ||
153 | $title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')'; | |
154 | ||
be2fb01f | 155 | $recentOther = []; |
6a488035 TO |
156 | if (CRM_Case_BAO_Case::checkPermission($activityID, 'edit')) { |
157 | $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/case/activity', | |
158 | "reset=1&action=update&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home" | |
159 | ); | |
160 | } | |
161 | if (CRM_Case_BAO_Case::checkPermission($activityID, 'delete')) { | |
162 | $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/case/activity', | |
163 | "reset=1&action=delete&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home" | |
164 | ); | |
165 | } | |
166 | ||
167 | CRM_Utils_Recent::add($title, | |
168 | $url, | |
169 | $activityID, | |
170 | 'Activity', | |
171 | $recentContactId, | |
172 | $recentContactDisplay, | |
173 | $recentOther | |
174 | ); | |
8867b911 CW |
175 | |
176 | // Set breadcrumb to take the user back to the case being viewed | |
177 | $caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseID, 'case_type_id'); | |
178 | $caseType = CRM_Core_PseudoConstant::getLabel('CRM_Case_BAO_Case', 'case_type_id', $caseTypeId); | |
179 | $caseContact = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseContact', $caseID, 'contact_id', 'case_id'); | |
180 | ||
181 | CRM_Utils_System::resetBreadCrumb(); | |
182 | $breadcrumb = [ | |
183 | [ | |
184 | 'title' => ts('Home'), | |
185 | 'url' => CRM_Utils_System::url(), | |
186 | ], | |
187 | [ | |
188 | 'title' => ts('CiviCRM'), | |
189 | 'url' => CRM_Utils_System::url('civicrm', 'reset=1'), | |
190 | ], | |
191 | [ | |
192 | 'title' => ts('CiviCase Dashboard'), | |
193 | 'url' => CRM_Utils_System::url('civicrm/case', 'reset=1'), | |
194 | ], | |
195 | [ | |
196 | 'title' => $caseType, | |
197 | 'url' => CRM_Utils_System::url('civicrm/contact/view/case', [ | |
198 | 'reset' => 1, | |
199 | 'id' => $caseID, | |
200 | 'context' => 'case', | |
201 | 'action' => 'view', | |
202 | 'cid' => $caseContact, | |
203 | ]), | |
204 | ], | |
205 | ]; | |
206 | CRM_Utils_System::appendBreadCrumb($breadcrumb); | |
7bf3b68c MWMC |
207 | |
208 | $this->addButtons([ | |
209 | [ | |
210 | 'type' => 'cancel', | |
211 | 'name' => ts('Done'), | |
212 | ], | |
213 | ]); | |
214 | // Add additional action links | |
215 | $activityDeleted = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'is_deleted'); | |
216 | $actionLinks = CRM_Case_Selector_Search::permissionedActionLinks($caseID, $contactID, CRM_Core_Session::getLoggedInContactID(), NULL, $activityTypeID, $activityDeleted, $activityID, FALSE); | |
217 | $this->assign('actionLinks', $actionLinks); | |
6a488035 | 218 | } |
96025800 | 219 | |
6a488035 | 220 | } |