Merge pull request #3833 from NileemaJadhav/CRM-HR-master
[civicrm-core.git] / CRM / Case / Form / ActivityView.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
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 *
355ba699 47 * @return void
6a488035
TO
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 );
6a488035
TO
58
59 //check for required permissions, CRM-6264
60 if ($activityID &&
61 !CRM_Activity_BAO_Activity::checkPermission($activityID, CRM_Core_Action::VIEW)
62 ) {
63 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
64 }
65
66 $this->assign('contactID', $contactID);
67 $this->assign('caseID', $caseID);
6a488035
TO
68 // CRM-9145
69 $this->assign('activityID', $activityID);
70
71 $xmlProcessor = new CRM_Case_XMLProcessor_Report();
72 $report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE);
73
74 $attachmentUrl = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityID);
75 if ($attachmentUrl) {
76 $report['fields'][] = array(
77 'label' => 'Attachment(s)',
78 'value' => $attachmentUrl,
79 'type' => 'Link',
80 );
81 }
82
83 $tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity');
84 if (!empty($tags)) {
cd43c5e3 85 $allTag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
6a488035
TO
86 foreach ($tags as $tid) {
87 $tags[$tid] = $allTag[$tid];
88 }
89 $report['fields'][] = array(
90 'label' => 'Tags',
91 'value' => implode('<br />', $tags),
92 'type' => 'String',
93 );
94 }
95
96 $this->assign('report', $report);
97
98 $latestRevisionID = CRM_Activity_BAO_Activity::getLatestActivityId($activityID);
99
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;
105 }
106 }
107
108 if ($revs) {
56cbe6ae 109 CRM_Utils_System::setTitle(ts('Activity Revision History'));
6a488035 110 $this->assign('revs', $revs);
6a488035
TO
111 $this->assign('result', $viewPriorActivities);
112 $this->assign('subject', $activitySubject);
113 $this->assign('latestRevisionID', $latestRevisionID);
114 }
115 else {
116 if (count($viewPriorActivities) > 1) {
117 $this->assign('activityID', $activityID);
118 }
119
120 if ($latestRevisionID != $activityID) {
121 $this->assign('latestRevisionID', $latestRevisionID);
122 }
123 }
124
125 $parentID = CRM_Activity_BAO_Activity::getParentActivity($activityID);
126 if ($parentID) {
127 $this->assign('parentID', $parentID);
128 }
129
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');
132
e7e657f0 133 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
034500d4 134 $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
135 $activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID);
6a488035
TO
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