clean up(CRM-12274)
[civicrm-core.git] / CRM / Case / Form / ActivityView.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
32 * $Id$
33 *
34 */
35
36/**
37 * This class does pre processing for viewing an activity or their revisions
38 *
39 */
40class CRM_Case_Form_ActivityView extends CRM_Core_Form {
41
42 /**
43 * Function to process the view
44 *
45 * @access public
46 *
47 * @return None
48 */
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',
55 $activityID,
56 'subject'
57 );
58 $type = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject);
59
60 //check for required permissions, CRM-6264
61 if ($activityID &&
62 !CRM_Activity_BAO_Activity::checkPermission($activityID, CRM_Core_Action::VIEW)
63 ) {
64 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
65 }
66
67 $this->assign('contactID', $contactID);
68 $this->assign('caseID', $caseID);
69 $this->assign('type', $type);
70 // CRM-9145
71 $this->assign('activityID', $activityID);
72
73 $xmlProcessor = new CRM_Case_XMLProcessor_Report();
74 $report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE);
75
76 $attachmentUrl = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityID);
77 if ($attachmentUrl) {
78 $report['fields'][] = array(
79 'label' => 'Attachment(s)',
80 'value' => $attachmentUrl,
81 'type' => 'Link',
82 );
83 }
84
85 $tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity');
86 if (!empty($tags)) {
87 $allTag = CRM_Core_PseudoConstant::tag();
88 foreach ($tags as $tid) {
89 $tags[$tid] = $allTag[$tid];
90 }
91 $report['fields'][] = array(
92 'label' => 'Tags',
93 'value' => implode('<br />', $tags),
94 'type' => 'String',
95 );
96 }
97
98 $this->assign('report', $report);
99
100 $latestRevisionID = CRM_Activity_BAO_Activity::getLatestActivityId($activityID);
101
102 $viewPriorActivities = array();
103 $priorActivities = CRM_Activity_BAO_Activity::getPriorAcitivities($activityID);
104 foreach ($priorActivities as $activityId => $activityValues) {
105 if (CRM_Case_BAO_Case::checkPermission($activityId, 'view', NULL, $contactID)) {
106 $viewPriorActivities[$activityId] = $activityValues;
107 }
108 }
109
110 if ($revs) {
111 $this->assign('revs', $revs);
112
113 $this->assign('result', $viewPriorActivities);
114 $this->assign('subject', $activitySubject);
115 $this->assign('latestRevisionID', $latestRevisionID);
116 }
117 else {
118 if (count($viewPriorActivities) > 1) {
119 $this->assign('activityID', $activityID);
120 }
121
122 if ($latestRevisionID != $activityID) {
123 $this->assign('latestRevisionID', $latestRevisionID);
124 }
125 }
126
127 $parentID = CRM_Activity_BAO_Activity::getParentActivity($activityID);
128 if ($parentID) {
129 $this->assign('parentID', $parentID);
130 }
131
132 //viewing activity should get diplayed in recent list.CRM-4670
133 $activityTypeID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'activity_type_id');
134
034500d4 135 $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
136 $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
137 $activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID);
6a488035
TO
138 if (!empty($activityTargetContacts)) {
139 $recentContactId = $activityTargetContacts[0];
140 }
141 else {
142 $recentContactId = $contactID;
143 }
144
145 if (!isset($caseID)) {
146 $caseID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id');
147 }
148
149 $url = CRM_Utils_System::url('civicrm/case/activity/view',
150 "reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home"
151 );
152
153 $recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId);
154 // add the recently created Activity
155 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE);
156
157 $title = "";
158 if (isset($activitySubject)) {
159 $title = $activitySubject . ' - ';
160 }
161
162 $title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')';
163
164 $recentOther = array();
165 if (CRM_Case_BAO_Case::checkPermission($activityID, 'edit')) {
166 $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/case/activity',
167 "reset=1&action=update&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"
168 );
169 }
170 if (CRM_Case_BAO_Case::checkPermission($activityID, 'delete')) {
171 $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/case/activity',
172 "reset=1&action=delete&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"
173 );
174 }
175
176 CRM_Utils_Recent::add($title,
177 $url,
178 $activityID,
179 'Activity',
180 $recentContactId,
181 $recentContactDisplay,
182 $recentOther
183 );
184 }
185}
186