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