3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
37 * This class does pre processing for viewing an activity or their revisions
40 class CRM_Case_Form_ActivityView
extends CRM_Core_Form
{
48 public function preProcess() {
49 $contactID = CRM_Utils_Request
::retrieve('cid', 'Integer', $this, TRUE);
50 $activityID = CRM_Utils_Request
::retrieve('aid', 'Integer', $this, TRUE);
51 $revs = CRM_Utils_Request
::retrieve('revs', 'Boolean', CRM_Core_DAO
::$_nullObject);
52 $caseID = CRM_Utils_Request
::retrieve('caseID', 'Boolean', CRM_Core_DAO
::$_nullObject);
53 $activitySubject = CRM_Core_DAO
::getFieldValue('CRM_Activity_DAO_Activity',
58 //check for required permissions, CRM-6264
60 !CRM_Activity_BAO_Activity
::checkPermission($activityID, CRM_Core_Action
::VIEW
)
62 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
65 $this->assign('contactID', $contactID);
66 $this->assign('caseID', $caseID);
68 $this->assign('activityID', $activityID);
70 $xmlProcessor = new CRM_Case_XMLProcessor_Report();
71 $report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE);
73 $attachmentUrl = CRM_Core_BAO_File
::attachmentInfo('civicrm_activity', $activityID);
75 $report['fields'][] = array(
76 'label' => 'Attachment(s)',
77 'value' => $attachmentUrl,
82 $tags = CRM_Core_BAO_EntityTag
::getTag($activityID, 'civicrm_activity');
84 $allTag = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
85 foreach ($tags as $tid) {
86 $tags[$tid] = $allTag[$tid];
88 $report['fields'][] = array(
90 'value' => implode('<br />', $tags),
95 $this->assign('report', $report);
97 $latestRevisionID = CRM_Activity_BAO_Activity
::getLatestActivityId($activityID);
99 $viewPriorActivities = array();
100 $priorActivities = CRM_Activity_BAO_Activity
::getPriorAcitivities($activityID);
101 foreach ($priorActivities as $activityId => $activityValues) {
102 if (CRM_Case_BAO_Case
::checkPermission($activityId, 'view', NULL, $contactID)) {
103 $viewPriorActivities[$activityId] = $activityValues;
108 CRM_Utils_System
::setTitle(ts('Activity Revision History'));
109 $this->assign('revs', $revs);
110 $this->assign('result', $viewPriorActivities);
111 $this->assign('subject', $activitySubject);
112 $this->assign('latestRevisionID', $latestRevisionID);
115 if (count($viewPriorActivities) > 1) {
116 $this->assign('activityID', $activityID);
119 if ($latestRevisionID != $activityID) {
120 $this->assign('latestRevisionID', $latestRevisionID);
124 $parentID = CRM_Activity_BAO_Activity
::getParentActivity($activityID);
126 $this->assign('parentID', $parentID);
129 //viewing activity should get diplayed in recent list.CRM-4670
130 $activityTypeID = CRM_Core_DAO
::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'activity_type_id');
132 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
133 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
134 $activityTargetContacts = CRM_Activity_BAO_ActivityContact
::retrieveContactIdsByActivityId($activityID, $targetID);
135 if (!empty($activityTargetContacts)) {
136 $recentContactId = $activityTargetContacts[0];
139 $recentContactId = $contactID;
142 if (!isset($caseID)) {
143 $caseID = CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id');
146 $url = CRM_Utils_System
::url('civicrm/case/activity/view',
147 "reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home"
150 $recentContactDisplay = CRM_Contact_BAO_Contact
::displayName($recentContactId);
151 // add the recently created Activity
152 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE);
155 if (isset($activitySubject)) {
156 $title = $activitySubject . ' - ';
159 $title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')';
161 $recentOther = array();
162 if (CRM_Case_BAO_Case
::checkPermission($activityID, 'edit')) {
163 $recentOther['editUrl'] = CRM_Utils_System
::url('civicrm/case/activity',
164 "reset=1&action=update&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"
167 if (CRM_Case_BAO_Case
::checkPermission($activityID, 'delete')) {
168 $recentOther['deleteUrl'] = CRM_Utils_System
::url('civicrm/case/activity',
169 "reset=1&action=delete&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"
173 CRM_Utils_Recent
::add($title,
178 $recentContactDisplay,