Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
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 | /** | |
fe482240 | 43 | * Process the view. |
6a488035 | 44 | * |
6a488035 | 45 | * |
355ba699 | 46 | * @return void |
6a488035 TO |
47 | */ |
48 | public function preProcess() { | |
353ffa53 TO |
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); | |
6a488035 TO |
53 | $activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', |
54 | $activityID, | |
55 | 'subject' | |
56 | ); | |
6a488035 TO |
57 | |
58 | //check for required permissions, CRM-6264 | |
59 | if ($activityID && | |
60 | !CRM_Activity_BAO_Activity::checkPermission($activityID, CRM_Core_Action::VIEW) | |
61 | ) { | |
62 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); | |
63 | } | |
64 | ||
65 | $this->assign('contactID', $contactID); | |
66 | $this->assign('caseID', $caseID); | |
6a488035 TO |
67 | // CRM-9145 |
68 | $this->assign('activityID', $activityID); | |
69 | ||
70 | $xmlProcessor = new CRM_Case_XMLProcessor_Report(); | |
71 | $report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE); | |
72 | ||
73 | $attachmentUrl = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityID); | |
74 | if ($attachmentUrl) { | |
75 | $report['fields'][] = array( | |
76 | 'label' => 'Attachment(s)', | |
77 | 'value' => $attachmentUrl, | |
78 | 'type' => 'Link', | |
79 | ); | |
80 | } | |
81 | ||
82 | $tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity'); | |
83 | if (!empty($tags)) { | |
cd43c5e3 | 84 | $allTag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); |
6a488035 TO |
85 | foreach ($tags as $tid) { |
86 | $tags[$tid] = $allTag[$tid]; | |
87 | } | |
88 | $report['fields'][] = array( | |
89 | 'label' => 'Tags', | |
90 | 'value' => implode('<br />', $tags), | |
91 | 'type' => 'String', | |
92 | ); | |
93 | } | |
94 | ||
95 | $this->assign('report', $report); | |
96 | ||
97 | $latestRevisionID = CRM_Activity_BAO_Activity::getLatestActivityId($activityID); | |
98 | ||
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; | |
104 | } | |
105 | } | |
106 | ||
107 | if ($revs) { | |
56cbe6ae | 108 | CRM_Utils_System::setTitle(ts('Activity Revision History')); |
6a488035 | 109 | $this->assign('revs', $revs); |
6a488035 TO |
110 | $this->assign('result', $viewPriorActivities); |
111 | $this->assign('subject', $activitySubject); | |
112 | $this->assign('latestRevisionID', $latestRevisionID); | |
113 | } | |
114 | else { | |
115 | if (count($viewPriorActivities) > 1) { | |
116 | $this->assign('activityID', $activityID); | |
117 | } | |
118 | ||
119 | if ($latestRevisionID != $activityID) { | |
120 | $this->assign('latestRevisionID', $latestRevisionID); | |
121 | } | |
122 | } | |
123 | ||
124 | $parentID = CRM_Activity_BAO_Activity::getParentActivity($activityID); | |
125 | if ($parentID) { | |
126 | $this->assign('parentID', $parentID); | |
127 | } | |
128 | ||
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'); | |
131 | ||
e7e657f0 | 132 | $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); |
034500d4 | 133 | $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); |
134 | $activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID); | |
6a488035 TO |
135 | if (!empty($activityTargetContacts)) { |
136 | $recentContactId = $activityTargetContacts[0]; | |
137 | } | |
138 | else { | |
139 | $recentContactId = $contactID; | |
140 | } | |
141 | ||
142 | if (!isset($caseID)) { | |
143 | $caseID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id'); | |
144 | } | |
145 | ||
146 | $url = CRM_Utils_System::url('civicrm/case/activity/view', | |
147 | "reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home" | |
148 | ); | |
149 | ||
150 | $recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId); | |
151 | // add the recently created Activity | |
152 | $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE); | |
153 | ||
154 | $title = ""; | |
155 | if (isset($activitySubject)) { | |
156 | $title = $activitySubject . ' - '; | |
157 | } | |
158 | ||
159 | $title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')'; | |
160 | ||
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" | |
165 | ); | |
166 | } | |
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" | |
170 | ); | |
171 | } | |
172 | ||
173 | CRM_Utils_Recent::add($title, | |
174 | $url, | |
175 | $activityID, | |
176 | 'Activity', | |
177 | $recentContactId, | |
178 | $recentContactDisplay, | |
179 | $recentOther | |
180 | ); | |
181 | } | |
96025800 | 182 | |
6a488035 | 183 | } |