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