3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class does pre processing for viewing an activity or their revisions
40 class CRM_Case_Form_ActivityView
extends CRM_Core_Form
{
49 public function preProcess() {
50 $contactID = CRM_Utils_Request
::retrieve('cid', 'Integer', $this, TRUE);
51 $activityID = CRM_Utils_Request
::retrieve('aid', 'Integer', $this, TRUE);
52 $revs = CRM_Utils_Request
::retrieve('revs', 'Boolean', CRM_Core_DAO
::$_nullObject);
53 $caseID = CRM_Utils_Request
::retrieve('caseID', 'Boolean', CRM_Core_DAO
::$_nullObject);
54 $activitySubject = CRM_Core_DAO
::getFieldValue('CRM_Activity_DAO_Activity',
59 //check for required permissions, CRM-6264
61 !CRM_Activity_BAO_Activity
::checkPermission($activityID, CRM_Core_Action
::VIEW
)
63 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
66 $this->assign('contactID', $contactID);
67 $this->assign('caseID', $caseID);
69 $this->assign('activityID', $activityID);
71 $xmlProcessor = new CRM_Case_XMLProcessor_Report();
72 $report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE);
74 $attachmentUrl = CRM_Core_BAO_File
::attachmentInfo('civicrm_activity', $activityID);
76 $report['fields'][] = array(
77 'label' => 'Attachment(s)',
78 'value' => $attachmentUrl,
83 $tags = CRM_Core_BAO_EntityTag
::getTag($activityID, 'civicrm_activity');
85 $allTag = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
86 foreach ($tags as $tid) {
87 $tags[$tid] = $allTag[$tid];
89 $report['fields'][] = array(
91 'value' => implode('<br />', $tags),
96 $this->assign('report', $report);
98 $latestRevisionID = CRM_Activity_BAO_Activity
::getLatestActivityId($activityID);
100 $viewPriorActivities = array();
101 $priorActivities = CRM_Activity_BAO_Activity
::getPriorAcitivities($activityID);
102 foreach ($priorActivities as $activityId => $activityValues) {
103 if (CRM_Case_BAO_Case
::checkPermission($activityId, 'view', NULL, $contactID)) {
104 $viewPriorActivities[$activityId] = $activityValues;
109 CRM_Utils_System
::setTitle(ts('Activity Revision History'));
110 $this->assign('revs', $revs);
111 $this->assign('result', $viewPriorActivities);
112 $this->assign('subject', $activitySubject);
113 $this->assign('latestRevisionID', $latestRevisionID);
116 if (count($viewPriorActivities) > 1) {
117 $this->assign('activityID', $activityID);
120 if ($latestRevisionID != $activityID) {
121 $this->assign('latestRevisionID', $latestRevisionID);
125 $parentID = CRM_Activity_BAO_Activity
::getParentActivity($activityID);
127 $this->assign('parentID', $parentID);
130 //viewing activity should get diplayed in recent list.CRM-4670
131 $activityTypeID = CRM_Core_DAO
::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'activity_type_id');
133 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
134 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
135 $activityTargetContacts = CRM_Activity_BAO_ActivityContact
::retrieveContactIdsByActivityId($activityID, $targetID);
136 if (!empty($activityTargetContacts)) {
137 $recentContactId = $activityTargetContacts[0];
140 $recentContactId = $contactID;
143 if (!isset($caseID)) {
144 $caseID = CRM_Core_DAO
::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id');
147 $url = CRM_Utils_System
::url('civicrm/case/activity/view',
148 "reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home"
151 $recentContactDisplay = CRM_Contact_BAO_Contact
::displayName($recentContactId);
152 // add the recently created Activity
153 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE);
156 if (isset($activitySubject)) {
157 $title = $activitySubject . ' - ';
160 $title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')';
162 $recentOther = array();
163 if (CRM_Case_BAO_Case
::checkPermission($activityID, 'edit')) {
164 $recentOther['editUrl'] = CRM_Utils_System
::url('civicrm/case/activity',
165 "reset=1&action=update&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"
168 if (CRM_Case_BAO_Case
::checkPermission($activityID, 'delete')) {
169 $recentOther['deleteUrl'] = CRM_Utils_System
::url('civicrm/case/activity',
170 "reset=1&action=delete&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"
174 CRM_Utils_Recent
::add($title,
179 $recentContactDisplay,