Commit | Line | Data |
---|---|---|
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 | */ | |
40 | class 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 | ||
135 | $activityTargetContacts = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activityID); | |
136 | if (!empty($activityTargetContacts)) { | |
137 | $recentContactId = $activityTargetContacts[0]; | |
138 | } | |
139 | else { | |
140 | $recentContactId = $contactID; | |
141 | } | |
142 | ||
143 | if (!isset($caseID)) { | |
144 | $caseID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id'); | |
145 | } | |
146 | ||
147 | $url = CRM_Utils_System::url('civicrm/case/activity/view', | |
148 | "reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home" | |
149 | ); | |
150 | ||
151 | $recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId); | |
152 | // add the recently created Activity | |
153 | $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE); | |
154 | ||
155 | $title = ""; | |
156 | if (isset($activitySubject)) { | |
157 | $title = $activitySubject . ' - '; | |
158 | } | |
159 | ||
160 | $title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')'; | |
161 | ||
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" | |
166 | ); | |
167 | } | |
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" | |
171 | ); | |
172 | } | |
173 | ||
174 | CRM_Utils_Recent::add($title, | |
175 | $url, | |
176 | $activityID, | |
177 | 'Activity', | |
178 | $recentContactId, | |
179 | $recentContactDisplay, | |
180 | $recentOther | |
181 | ); | |
182 | } | |
183 | } | |
184 |