dev/core#165 - Fix case activity breadcrumb
[civicrm-core.git] / CRM / Case / Form / ActivityView.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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
31 * @copyright CiviCRM LLC (c) 2004-2018
32 */
33
34 /**
35 * This class does pre processing for viewing an activity or their revisions.
36 */
37 class CRM_Case_Form_ActivityView extends CRM_Core_Form {
38
39 /**
40 * Process the view.
41 */
42 public function preProcess() {
43 $contactID = CRM_Utils_Request::retrieve('cid', 'Integer', $this, TRUE);
44 $activityID = CRM_Utils_Request::retrieve('aid', 'Integer', $this, TRUE);
45 $revs = CRM_Utils_Request::retrieve('revs', 'Boolean');
46 $caseID = CRM_Utils_Request::retrieve('caseID', 'Boolean');
47 $activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity',
48 $activityID,
49 'subject'
50 );
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);
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) {
69 $report['fields'][] = array(
70 'label' => 'Attachment(s)',
71 'value' => $attachmentUrl,
72 'type' => 'Link',
73 );
74 }
75
76 $tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity');
77 if (!empty($tags)) {
78 $allTag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
79 foreach ($tags as $tid) {
80 $tags[$tid] = $allTag[$tid];
81 }
82 $report['fields'][] = array(
83 'label' => 'Tags',
84 'value' => implode('<br />', $tags),
85 'type' => 'String',
86 );
87 }
88
89 $this->assign('report', $report);
90
91 $latestRevisionID = CRM_Activity_BAO_Activity::getLatestActivityId($activityID);
92
93 $viewPriorActivities = array();
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) {
102 CRM_Utils_System::setTitle(ts('Activity Revision History'));
103 $this->assign('revs', $revs);
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
126 $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
127 $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
128 $activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID);
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
155 $recentOther = array();
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 );
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);
207 }
208
209 }