Commit | Line | Data |
---|---|---|
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 | * |
33 | */ | |
34 | ||
35 | /** | |
36 | * This class contains all the function that are called using AJAX (jQuery) | |
37 | */ | |
38 | class CRM_Activity_Page_AJAX { | |
39 | static function getCaseActivity() { | |
40 | $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); | |
41 | $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); | |
42 | $userID = CRM_Utils_Type::escape($_GET['userID'], 'Integer'); | |
43 | $context = CRM_Utils_Type::escape(CRM_Utils_Array::value('context', $_GET), 'String'); | |
44 | ||
45 | $sortMapper = array( | |
46 | 0 => 'display_date', 1 => 'ca.subject', 2 => 'ca.activity_type_id', | |
47 | 3 => 'acc.sort_name', 4 => 'cc.sort_name', 5 => 'ca.status_id', | |
48 | ); | |
49 | ||
50 | $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); | |
51 | $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; | |
52 | $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; | |
53 | $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; | |
54 | $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; | |
55 | ||
56 | $params = $_POST; | |
57 | if ($sort && $sortOrder) { | |
58 | $params['sortname'] = $sort; | |
59 | $params['sortorder'] = $sortOrder; | |
60 | } | |
61 | $params['page'] = ($offset / $rowCount) + 1; | |
62 | $params['rp'] = $rowCount; | |
63 | ||
64 | // get the activities related to given case | |
65 | $activities = CRM_Case_BAO_Case::getCaseActivity($caseID, $params, $contactID, $context, $userID); | |
66 | ||
67 | $iFilteredTotal = $iTotal = $params['total']; | |
68 | $selectorElements = array('display_date', 'subject', 'type', 'with_contacts', 'reporter', 'status', 'links', 'class'); | |
69 | ||
70 | echo CRM_Utils_JSON::encodeDataTableSelector($activities, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
71 | CRM_Utils_System::civiExit(); | |
72 | } | |
73 | ||
74 | static function getCaseGlobalRelationships() { | |
75 | $sortMapper = array( | |
76 | 0 => 'sort_name', 1 => 'phone', 2 => 'email', | |
77 | ); | |
1d85d241 | 78 | |
6a488035 TO |
79 | $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); |
80 | $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; | |
81 | $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; | |
82 | $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; | |
83 | $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; | |
1d85d241 | 84 | |
6a488035 TO |
85 | $params = $_POST; |
86 | if ($sort && $sortOrder) { | |
87 | $sortSQL = $sort .' '.$sortOrder; | |
88 | } | |
1d85d241 | 89 | |
6a488035 TO |
90 | // get the activities related to given case |
91 | $globalGroupInfo = array(); | |
1d85d241 | 92 | |
6a488035 TO |
93 | // get the total row count |
94 | $relGlobalTotalCount = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, NULL, FALSE, TRUE, NULL, NULL); | |
95 | // limit the rows | |
1d85d241 DL |
96 | $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, $sortSQL, $showLinks = TRUE, FALSE, $offset, $rowCount); |
97 | ||
6a488035 TO |
98 | $iFilteredTotal = $iTotal = $relGlobalTotalCount; |
99 | $selectorElements = array('sort_name', 'phone', 'email'); | |
1d85d241 | 100 | |
6a488035 TO |
101 | echo CRM_Utils_JSON::encodeDataTableSelector($relGlobal, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); |
102 | CRM_Utils_System::civiExit(); | |
1d85d241 DL |
103 | } |
104 | ||
6a488035 TO |
105 | static function getCaseClientRelationships() { |
106 | $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); | |
107 | $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); | |
1d85d241 | 108 | |
6a488035 TO |
109 | $sortMapper = array( |
110 | 0 => 'relation', 1 => 'name', 2 => 'phone', 3 => 'email' | |
111 | ); | |
1d85d241 | 112 | |
6a488035 TO |
113 | $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); |
114 | $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; | |
115 | $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; | |
116 | $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : 'relation'; | |
117 | $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; | |
1d85d241 | 118 | |
6a488035 TO |
119 | $params = $_POST; |
120 | if ($sort && $sortOrder) { | |
121 | $sortSQL = $sort .' '.$sortOrder; | |
122 | } | |
123 | ||
124 | // Retrieve ALL client relationships | |
125 | $relClient = CRM_Contact_BAO_Relationship::getRelationship($contactID, | |
126 | CRM_Contact_BAO_Relationship::CURRENT, | |
127 | 0, 0, 0, NULL, NULL, FALSE | |
128 | ); | |
1d85d241 | 129 | |
6a488035 | 130 | $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); |
1d85d241 | 131 | |
6a488035 TO |
132 | // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles |
133 | // so they don't show up twice. | |
134 | $clientRelationships = array(); | |
135 | foreach ($relClient as $r) { | |
136 | if (!array_key_exists($r['id'], $caseRelationships)) { | |
137 | $clientRelationships[] = $r; | |
138 | } | |
139 | } | |
1d85d241 | 140 | |
6a488035 TO |
141 | // sort clientRelationships array using jquery call params |
142 | foreach ($clientRelationships as $key => $row) { | |
1d85d241 | 143 | $sortArray[$key] = $row[$sort]; |
6a488035 | 144 | } |
0e2079a1 CW |
145 | $sort_type = "SORT_" . strtoupper($sortOrder); |
146 | array_multisort($sortArray, constant($sort_type), $clientRelationships); | |
1d85d241 | 147 | |
6a488035 TO |
148 | //limit the rows |
149 | $allClientRelationships = $clientRelationships; | |
150 | $clientRelationships = array_slice($allClientRelationships, $offset, $rowCount, TRUE); | |
1d85d241 | 151 | |
6a488035 TO |
152 | // after sort we can update username fields to be a url |
153 | foreach($clientRelationships as $key => $value) { | |
154 | $clientRelationships[$key]['name'] = '<a href='.CRM_Utils_System::url('civicrm/contact/view', | |
155 | 'action=view&reset=1&cid='.$clientRelationships[$key]['cid']).'>'.$clientRelationships[$key]['name'].'</a>'; | |
156 | } | |
1d85d241 | 157 | |
6a488035 TO |
158 | $iFilteredTotal = $iTotal = $params['total'] = count($allClientRelationships); |
159 | $selectorElements = array('relation', 'name', 'phone', 'email'); | |
1d85d241 | 160 | |
6a488035 TO |
161 | echo CRM_Utils_JSON::encodeDataTableSelector($clientRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); |
162 | CRM_Utils_System::civiExit(); | |
1d85d241 DL |
163 | } |
164 | ||
165 | ||
6a488035 TO |
166 | static function getCaseRoles() { |
167 | $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); | |
168 | $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); | |
1d85d241 | 169 | |
6a488035 TO |
170 | $sortMapper = array( |
171 | 0 => 'relation', 1 => 'name', 2 => 'phone', 3 => 'email', 4 => 'actions' | |
172 | ); | |
1d85d241 | 173 | |
6a488035 TO |
174 | $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); |
175 | $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; | |
176 | $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; | |
177 | $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : 'relation'; | |
178 | $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; | |
1d85d241 | 179 | |
6a488035 TO |
180 | $params = $_POST; |
181 | if ($sort && $sortOrder) { | |
182 | $sortSQL = $sort .' '.$sortOrder; | |
183 | } | |
184 | ||
185 | $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); | |
186 | $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name'); | |
187 | $xmlProcessor = new CRM_Case_XMLProcessor_Process(); | |
188 | $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles'); | |
1d85d241 | 189 | |
6a488035 | 190 | $hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities'); |
1d85d241 | 191 | |
6a488035 TO |
192 | $managerRoleId = $xmlProcessor->getCaseManagerRoleId($caseTypeName); |
193 | if (!empty($managerRoleId)) { | |
194 | $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; | |
195 | } | |
1d85d241 | 196 | |
6a488035 TO |
197 | foreach ($caseRelationships as $key => $value) { |
198 | //calculate roles that don't have relationships | |
a7488080 | 199 | if (!empty($caseRoles[$value['relation_type']])) { |
6a488035 TO |
200 | //keep naming from careRoles array |
201 | $caseRelationships[$key]['relation'] = $caseRoles[$value['relation_type']]; | |
202 | unset($caseRoles[$value['relation_type']]); | |
203 | } | |
204 | // mark orginal case relationships record to use on setting edit links below | |
205 | $caseRelationships[$key]['source'] = 'caseRel'; | |
206 | } | |
1d85d241 | 207 | |
6a488035 TO |
208 | $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID); |
209 | ||
210 | // move/transform caseRoles array data to caseRelationships | |
211 | // for sorting and display | |
212 | foreach($caseRoles as $id => $value) { | |
213 | if ($id != "client") { | |
214 | $rel = array(); | |
215 | $rel['relation'] = $value; | |
216 | $rel['relation_type'] = $id; | |
217 | $rel['name'] = '(not assigned)'; | |
218 | $rel['phone'] = ''; | |
219 | $rel['email'] = ''; | |
220 | $rel['source'] = 'caseRoles'; | |
221 | $caseRelationships[] = $rel; | |
222 | } else { | |
223 | foreach($value as $clientRole) { | |
224 | $relClient = array(); | |
225 | $relClient['relation'] = 'Client'; | |
226 | $relClient['name'] = $clientRole['sort_name']; | |
227 | $relClient['phone'] = $clientRole['phone']; | |
228 | $relClient['email'] = $clientRole['email']; | |
229 | $relClient['cid'] = $clientRole['contact_id']; | |
230 | $relClient['source'] = 'contact'; | |
231 | $caseRelationships[] = $relClient; | |
232 | } | |
233 | } | |
234 | } | |
235 | ||
236 | // sort clientRelationships array using jquery call params | |
237 | foreach ($caseRelationships as $key => $row) { | |
238 | $sortArray[$key] = $row[$sort]; | |
239 | } | |
240 | ||
0e2079a1 CW |
241 | $sort_type = "SORT_" . strtoupper($sortOrder); |
242 | array_multisort($sortArray, constant($sort_type), $caseRelationships); | |
6a488035 TO |
243 | |
244 | //limit rows display | |
245 | $allCaseRelationships = $caseRelationships; | |
246 | $caseRelationships = array_slice($allCaseRelationships, $offset, $rowCount, TRUE); | |
247 | ||
248 | // set user name, email and edit columns links | |
249 | // idx will count number of current row / needed by edit links | |
250 | $idx = 1; | |
c91df8b4 CW |
251 | foreach ($caseRelationships as &$row) { |
252 | // Get rid of the "<br />(Case Manager)" from label | |
253 | list($typeLabel) = explode('<', $row['relation']); | |
6a488035 | 254 | // view user links |
c91df8b4 CW |
255 | if ($row['cid']) { |
256 | $row['name'] = '<a class="view-contact" title="'. ts('View Contact') .'" href='.CRM_Utils_System::url('civicrm/contact/view', | |
257 | 'action=view&reset=1&cid='.$row['cid']).'>'.$row['name'].'</a>'; | |
6a488035 TO |
258 | } |
259 | // email column links/icon | |
c91df8b4 | 260 | if ($row['email']) { |
00ca8648 | 261 | $row['email'] = '<a class="crm-hover-button crm-popup" href="'.CRM_Utils_System::url('civicrm/activity/email/add', 'reset=1&action=add&atype=3&cid='.$row['cid']).'&caseid='.$caseID.'" title="'. ts('Send an Email') . '"><span class="icon email-icon"></span></a>'; |
6a488035 TO |
262 | } |
263 | // edit links | |
264 | if ($hasAccessToAllCases) { | |
c91df8b4 | 265 | switch($row['source']){ |
6a488035 | 266 | case 'caseRel': |
c91df8b4 CW |
267 | $row['actions'] = |
268 | '<a href="#editCaseRoleDialog" title="'. ts('Reassign %1', array(1 => $typeLabel)) .'" class="crm-hover-button case-miniform" data-rel_type="'. $row['relation_type'] .'" data-rel_id="'. $row['rel_id'] .'"data-key="'. CRM_Core_Key::get('civicrm/ajax/relation') .'">'. | |
269 | '<span class="icon edit-icon"></span>'. | |
270 | '</a>'. | |
271 | '<a href="#deleteCaseRoleDialog" title="'. ts('Remove %1', array(1 => $typeLabel)) .'" class="crm-hover-button case-miniform" data-rel_type="'.$row['relation_type'].'" data-key="'. CRM_Core_Key::get('civicrm/ajax/delcaserole') .'">'. | |
272 | '<span class="icon delete-icon"></span>'. | |
273 | '</a>'; | |
6a488035 | 274 | break; |
1d85d241 | 275 | |
6a488035 | 276 | case 'caseRoles': |
c91df8b4 CW |
277 | $row['actions'] = |
278 | '<a href="#editCaseRoleDialog" title="'. ts('Assign %1', array(1 => $typeLabel)) .'" class="crm-hover-button case-miniform" data-rel_type="'. $row['relation_type'] .'" data-key="'. CRM_Core_Key::get('civicrm/ajax/relation') .'">'. | |
279 | '<span class="icon edit-icon"></span>'. | |
280 | '</a>'; | |
6a488035 TO |
281 | break; |
282 | } | |
283 | } else { | |
c91df8b4 | 284 | $row['actions'] = ''; |
6a488035 TO |
285 | } |
286 | $idx++; | |
287 | } | |
288 | $iFilteredTotal = $iTotal = $params['total'] = count($allCaseRelationships); | |
289 | $selectorElements = array('relation', 'name', 'phone', 'email', 'actions'); | |
1d85d241 | 290 | |
6a488035 TO |
291 | echo CRM_Utils_JSON::encodeDataTableSelector($caseRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); |
292 | CRM_Utils_System::civiExit(); | |
1d85d241 DL |
293 | } |
294 | ||
6a488035 TO |
295 | static function convertToCaseActivity() { |
296 | $params = array('caseID', 'activityID', 'contactID', 'newSubject', 'targetContactIds', 'mode'); | |
297 | foreach ($params as $param) { | |
298 | $vals[$param] = CRM_Utils_Array::value($param, $_POST); | |
299 | } | |
300 | ||
301 | $retval = self::_convertToCaseActivity($vals); | |
302 | ||
303 | echo json_encode($retval); | |
304 | CRM_Utils_System::civiExit(); | |
305 | } | |
306 | ||
307 | static function _convertToCaseActivity($params) { | |
308 | if (!$params['activityID'] || !$params['caseID']) { | |
309 | return (array('error_msg' => 'required params missing.')); | |
310 | } | |
311 | ||
312 | $otherActivity = new CRM_Activity_DAO_Activity(); | |
313 | $otherActivity->id = $params['activityID']; | |
314 | if (!$otherActivity->find(TRUE)) { | |
315 | return (array('error_msg' => 'activity record is missing.')); | |
316 | } | |
317 | $actDateTime = CRM_Utils_Date::isoToMysql($otherActivity->activity_date_time); | |
318 | ||
319 | //create new activity record. | |
320 | $mainActivity = new CRM_Activity_DAO_Activity(); | |
321 | $mainActVals = array(); | |
322 | CRM_Core_DAO::storeValues($otherActivity, $mainActVals); | |
323 | ||
324 | //get new activity subject. | |
325 | if (!empty($params['newSubject'])) { | |
326 | $mainActVals['subject'] = $params['newSubject']; | |
327 | } | |
328 | ||
329 | $mainActivity->copyValues($mainActVals); | |
330 | $mainActivity->id = NULL; | |
331 | $mainActivity->activity_date_time = $actDateTime; | |
332 | //make sure this is current revision. | |
333 | $mainActivity->is_current_revision = TRUE; | |
334 | //drop all relations. | |
335 | $mainActivity->parent_id = $mainActivity->original_id = NULL; | |
336 | ||
337 | $mainActivity->save(); | |
338 | $mainActivityId = $mainActivity->id; | |
339 | CRM_Activity_BAO_Activity::logActivityAction($mainActivity); | |
340 | $mainActivity->free(); | |
341 | ||
342 | /* Mark previous activity as deleted. If it was a non-case activity | |
7b1ec1c6 | 343 | * then just change the subject. |
344 | */ | |
6a488035 TO |
345 | |
346 | if (in_array($params['mode'], array( | |
347 | 'move', 'file'))) { | |
348 | $caseActivity = new CRM_Case_DAO_CaseActivity(); | |
349 | $caseActivity->case_id = $params['caseID']; | |
350 | $caseActivity->activity_id = $otherActivity->id; | |
351 | if ($params['mode'] == 'move' || $caseActivity->find(TRUE)) { | |
352 | $otherActivity->is_deleted = 1; | |
353 | } | |
354 | else { | |
355 | $otherActivity->subject = ts('(Filed on case %1)', array( | |
7b1ec1c6 | 356 | 1 => $params['caseID'] |
357 | )) . ' ' . $otherActivity->subject; | |
6a488035 TO |
358 | } |
359 | $otherActivity->activity_date_time = $actDateTime; | |
360 | $otherActivity->save(); | |
361 | ||
362 | $caseActivity->free(); | |
363 | } | |
364 | $otherActivity->free(); | |
365 | ||
366 | $targetContacts = array(); | |
367 | if (!empty($params['targetContactIds'])) { | |
368 | $targetContacts = array_unique(explode(',', $params['targetContactIds'])); | |
369 | } | |
f813f78e | 370 | |
e7e657f0 | 371 | $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); |
a24b3694 | 372 | $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); |
373 | $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); | |
374 | $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); | |
375 | ||
7b1ec1c6 | 376 | $sourceContactID = CRM_Activity_BAO_Activity::getSourceContactID($params['activityID']); |
377 | $src_params = array( | |
378 | 'activity_id' => $mainActivityId, | |
379 | 'contact_id' => $sourceContactID, | |
380 | 'record_type_id' => $sourceID | |
381 | ); | |
382 | CRM_Activity_BAO_ActivityContact::create($src_params); | |
383 | ||
6a488035 TO |
384 | foreach ($targetContacts as $key => $value) { |
385 | $targ_params = array( | |
386 | 'activity_id' => $mainActivityId, | |
1d85d241 | 387 | 'contact_id' => $value, |
a24b3694 | 388 | 'record_type_id' => $targetID |
6a488035 | 389 | ); |
1d85d241 | 390 | CRM_Activity_BAO_ActivityContact::create($targ_params); |
6a488035 TO |
391 | } |
392 | ||
393 | // typically this will be empty, since assignees on another case may be completely different | |
394 | $assigneeContacts = array(); | |
395 | if (!empty($params['assigneeContactIds'])) { | |
396 | $assigneeContacts = array_unique(explode(',', $params['assigneeContactIds'])); | |
397 | } | |
398 | foreach ($assigneeContacts as $key => $value) { | |
399 | $assigneeParams = array( | |
400 | 'activity_id' => $mainActivityId, | |
1d85d241 | 401 | 'contact_id' => $value, |
a24b3694 | 402 | 'record_type_id' => $assigneeID |
6a488035 | 403 | ); |
1d85d241 | 404 | CRM_Activity_BAO_ActivityContact::create($assigneeParams); |
6a488035 TO |
405 | } |
406 | ||
407 | //attach newly created activity to case. | |
408 | $caseActivity = new CRM_Case_DAO_CaseActivity(); | |
409 | $caseActivity->case_id = $params['caseID']; | |
410 | $caseActivity->activity_id = $mainActivityId; | |
411 | $caseActivity->save(); | |
412 | $error_msg = $caseActivity->_lastError; | |
413 | $caseActivity->free(); | |
414 | ||
415 | $params['mainActivityId'] = $mainActivityId; | |
416 | CRM_Activity_BAO_Activity::copyExtendedActivityData($params); | |
417 | ||
418 | return (array('error_msg' => $error_msg, 'newId' => $mainActivity->id)); | |
419 | } | |
420 | ||
421 | static function getContactActivity() { | |
422 | $contactID = CRM_Utils_Type::escape($_POST['contact_id'], 'Integer'); | |
423 | $context = CRM_Utils_Type::escape(CRM_Utils_Array::value('context', $_GET), 'String'); | |
424 | ||
425 | $sortMapper = array( | |
f3548d18 BS |
426 | 0 => 'activity_type', |
427 | 1 => 'subject', | |
428 | 2 => 'source_contact_name', | |
429 | 3 => '', | |
8c7ca479 | 430 | 4 => '', |
431 | 5 => 'activity_date_time', | |
432 | 6 => 'status_id', | |
6a488035 TO |
433 | ); |
434 | ||
f3548d18 BS |
435 | $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); |
436 | $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; | |
437 | $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; | |
438 | $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; | |
6a488035 TO |
439 | $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; |
440 | ||
441 | $params = $_POST; | |
442 | if ($sort && $sortOrder) { | |
443 | $params['sortBy'] = $sort . ' ' . $sortOrder; | |
444 | } | |
445 | ||
446 | $params['page'] = ($offset / $rowCount) + 1; | |
447 | $params['rp'] = $rowCount; | |
448 | ||
449 | $params['contact_id'] = $contactID; | |
450 | $params['context'] = $context; | |
451 | ||
452 | // get the contact activities | |
453 | $activities = CRM_Activity_BAO_Activity::getContactActivitySelector($params); | |
454 | ||
455 | // store the activity filter preference CRM-11761 | |
456 | $session = CRM_Core_Session::singleton(); | |
457 | $userID = $session->get('userID'); | |
458 | if ($userID) { | |
f3548d18 BS |
459 | //flush cache before setting filter to account for global cache (memcache) |
460 | $domainID = CRM_Core_Config::domainID(); | |
461 | $cacheKey = CRM_Core_BAO_Setting::inCache( | |
462 | CRM_Core_BAO_Setting::PERSONAL_PREFERENCES_NAME, | |
463 | 'activity_tab_filter', | |
464 | NULL, | |
465 | $userID, | |
466 | TRUE, | |
467 | $domainID, | |
468 | TRUE | |
469 | ); | |
470 | if ( $cacheKey ) { | |
471 | CRM_Core_BAO_Setting::flushCache($cacheKey); | |
472 | } | |
473 | ||
474 | $activityFilter = array( | |
da0b2039 DL |
475 | 'activity_type_filter_id' => empty($params['activity_type_id']) ? '' : |
476 | CRM_Utils_Type::escape($params['activity_type_id'], 'Integer'), | |
477 | 'activity_type_exclude_filter_id' => empty($params['activity_type_exclude_id']) ? '' : | |
478 | CRM_Utils_Type::escape($params['activity_type_exclude_id'], 'Integer'), | |
f3548d18 BS |
479 | ); |
480 | ||
481 | CRM_Core_BAO_Setting::setItem( | |
482 | $activityFilter, | |
483 | CRM_Core_BAO_Setting::PERSONAL_PREFERENCES_NAME, | |
484 | 'activity_tab_filter', | |
485 | NULL, | |
486 | $userID, | |
487 | $userID | |
488 | ); | |
6a488035 | 489 | } |
1d85d241 | 490 | |
6a488035 TO |
491 | $iFilteredTotal = $iTotal = $params['total']; |
492 | $selectorElements = array( | |
493 | 'activity_type', 'subject', 'source_contact', | |
494 | 'target_contact', 'assignee_contact', | |
50f5a393 | 495 | 'activity_date', 'status','links', 'class', |
6a488035 TO |
496 | ); |
497 | ||
498 | echo CRM_Utils_JSON::encodeDataTableSelector($activities, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); | |
499 | CRM_Utils_System::civiExit(); | |
500 | } | |
501 | } | |
502 |