3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * This class does pre processing for viewing an activity or their revisions.
37 class CRM_Case_Form_ActivityView
extends CRM_Core_Form
{
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',
52 //check for required permissions, CRM-6264
54 !CRM_Activity_BAO_Activity
::checkPermission($activityID, CRM_Core_Action
::VIEW
)
56 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
59 $this->assign('contactID', $contactID);
60 $this->assign('caseID', $caseID);
62 $this->assign('activityID', $activityID);
64 $xmlProcessor = new CRM_Case_XMLProcessor_Report();
65 $report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE);
67 $attachmentUrl = CRM_Core_BAO_File
::attachmentInfo('civicrm_activity', $activityID);
69 $report['fields'][] = [
70 'label' => 'Attachment(s)',
71 'value' => $attachmentUrl,
76 $tags = CRM_Core_BAO_EntityTag
::getTag($activityID, 'civicrm_activity');
78 $allTag = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_EntityTag', 'tag_id', ['onlyActive' => FALSE]);
79 foreach ($tags as $tid) {
80 $tags[$tid] = $allTag[$tid];
82 $report['fields'][] = [
84 'value' => implode('<br />', $tags),
89 $this->assign('report', $report);
91 $latestRevisionID = CRM_Activity_BAO_Activity
::getLatestActivityId($activityID);
93 $viewPriorActivities = [];
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;
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);
109 if (count($viewPriorActivities) > 1) {
110 $this->assign('activityID', $activityID);
113 if ($latestRevisionID != $activityID) {
114 $this->assign('latestRevisionID', $latestRevisionID);
118 $parentID = CRM_Activity_BAO_Activity
::getParentActivity($activityID);
120 $this->assign('parentID', $parentID);
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');
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];
133 $recentContactId = $contactID;
136 if (!isset($caseID)) {
137 $caseID = CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id');
140 $url = CRM_Utils_System
::url('civicrm/case/activity/view',
141 "reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home"
144 $recentContactDisplay = CRM_Contact_BAO_Contact
::displayName($recentContactId);
145 // add the recently created Activity
146 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE);
149 if (isset($activitySubject)) {
150 $title = $activitySubject . ' - ';
153 $title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')';
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"
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"
167 CRM_Utils_Recent
::add($title,
172 $recentContactDisplay,
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');
181 CRM_Utils_System
::resetBreadCrumb();
184 'title' => ts('Home'),
185 'url' => CRM_Utils_System
::url(),
188 'title' => ts('CiviCRM'),
189 'url' => CRM_Utils_System
::url('civicrm', 'reset=1'),
192 'title' => ts('CiviCase Dashboard'),
193 'url' => CRM_Utils_System
::url('civicrm/case', 'reset=1'),
196 'title' => $caseType,
197 'url' => CRM_Utils_System
::url('civicrm/contact/view/case', [
202 'cid' => $caseContact,
206 CRM_Utils_System
::appendBreadCrumb($breadcrumb);
211 'name' => ts('Done'),
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);