Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * This class contains all the function that are called using AJAX (jQuery) | |
20 | */ | |
21 | class CRM_Activity_Page_AJAX { | |
62d3ee27 | 22 | |
00be9182 | 23 | public static function getCaseActivity() { |
5d817a13 MM |
24 | // Should those params be passed through the validateParams method? |
25 | $caseID = CRM_Utils_Type::validate($_GET['caseID'], 'Integer'); | |
26 | $contactID = CRM_Utils_Type::validate($_GET['cid'], 'Integer'); | |
27 | $userID = CRM_Utils_Type::validate($_GET['userID'], 'Integer'); | |
28 | $context = CRM_Utils_Type::validate(CRM_Utils_Array::value('context', $_GET), 'String'); | |
6a488035 | 29 | |
be2fb01f | 30 | $optionalParameters = [ |
9c3f979f MM |
31 | 'source_contact_id' => 'Integer', |
32 | 'status_id' => 'Integer', | |
33 | 'activity_deleted' => 'Boolean', | |
34 | 'activity_type_id' => 'Integer', | |
ab9eca19 CW |
35 | // "Date" validation fails because it expects only numbers with no hyphens |
36 | 'activity_date_low' => 'Alphanumeric', | |
37 | 'activity_date_high' => 'Alphanumeric', | |
be2fb01f | 38 | ]; |
6a488035 | 39 | |
9c3f979f | 40 | $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); |
be2fb01f | 41 | $params += CRM_Core_Page_AJAX::validateParams([], $optionalParameters); |
6a488035 TO |
42 | |
43 | // get the activities related to given case | |
44 | $activities = CRM_Case_BAO_Case::getCaseActivity($caseID, $params, $contactID, $context, $userID); | |
45 | ||
ad280fb6 | 46 | CRM_Utils_JSON::output($activities); |
6a488035 TO |
47 | } |
48 | ||
00be9182 | 49 | public static function getCaseGlobalRelationships() { |
9c3f979f | 50 | $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); |
1d85d241 | 51 | |
6a488035 | 52 | // get the activities related to given case |
be2fb01f | 53 | $globalGroupInfo = []; |
1d85d241 | 54 | |
6a488035 | 55 | // get the total row count |
9c3f979f | 56 | CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, NULL, FALSE, TRUE, NULL, NULL); |
6a488035 | 57 | // limit the rows |
1d154485 | 58 | $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, $params['sortBy'] ?? NULL, $showLinks = TRUE, FALSE, $params['offset'], $params['rp']); |
1d85d241 | 59 | |
be2fb01f | 60 | $relationships = []; |
ad280fb6 JL |
61 | // after sort we can update username fields to be a url |
62 | foreach ($relGlobal as $key => $value) { | |
be2fb01f | 63 | $relationship = []; |
ad280fb6 JL |
64 | $relationship['sort_name'] = $value['sort_name']; |
65 | $relationship['phone'] = $value['phone']; | |
66 | $relationship['email'] = $value['email']; | |
1d85d241 | 67 | |
ad280fb6 JL |
68 | array_push($relationships, $relationship); |
69 | } | |
70 | ||
be2fb01f | 71 | $globalRelationshipsDT = []; |
ad280fb6 | 72 | $globalRelationshipsDT['data'] = $relationships; |
9c3f979f MM |
73 | $globalRelationshipsDT['recordsTotal'] = count($relationships); |
74 | $globalRelationshipsDT['recordsFiltered'] = count($relationships); | |
aab589e2 | 75 | |
ad280fb6 | 76 | CRM_Utils_JSON::output($globalRelationshipsDT); |
1d85d241 DL |
77 | } |
78 | ||
00be9182 | 79 | public static function getCaseClientRelationships() { |
353ffa53 | 80 | $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); |
6a488035 | 81 | $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); |
1d85d241 | 82 | |
9c3f979f | 83 | $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); |
6a488035 TO |
84 | |
85 | // Retrieve ALL client relationships | |
86 | $relClient = CRM_Contact_BAO_Relationship::getRelationship($contactID, | |
87 | CRM_Contact_BAO_Relationship::CURRENT, | |
88 | 0, 0, 0, NULL, NULL, FALSE | |
89 | ); | |
1d85d241 | 90 | |
f537dc05 | 91 | $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID, NULL, FALSE); |
1d85d241 | 92 | |
6a488035 TO |
93 | // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles |
94 | // so they don't show up twice. | |
be2fb01f | 95 | $clientRelationships = []; |
6a488035 TO |
96 | foreach ($relClient as $r) { |
97 | if (!array_key_exists($r['id'], $caseRelationships)) { | |
98 | $clientRelationships[] = $r; | |
99 | } | |
100 | } | |
1d85d241 | 101 | |
6a488035 | 102 | // sort clientRelationships array using jquery call params |
1d154485 JP |
103 | $sortArray = []; |
104 | if (!empty($params['_raw_values']['sort'])) { | |
105 | foreach ($clientRelationships as $key => $row) { | |
106 | $sortArray[$key] = $row[$params['_raw_values']['sort'][0]]; | |
107 | } | |
108 | $sort_type = "SORT_" . strtoupper($params['_raw_values']['order'][0]); | |
109 | array_multisort($sortArray, constant($sort_type), $clientRelationships); | |
6a488035 | 110 | } |
1d85d241 | 111 | |
be2fb01f | 112 | $relationships = []; |
6a488035 | 113 | // after sort we can update username fields to be a url |
22e263ad | 114 | foreach ($clientRelationships as $key => $value) { |
be2fb01f | 115 | $relationship = []; |
ad280fb6 JL |
116 | $relationship['relation'] = $value['relation']; |
117 | $relationship['name'] = '<a href=' . CRM_Utils_System::url('civicrm/contact/view', | |
353ffa53 | 118 | 'action=view&reset=1&cid=' . $clientRelationships[$key]['cid']) . '>' . $clientRelationships[$key]['name'] . '</a>'; |
ad280fb6 JL |
119 | $relationship['phone'] = $value['phone']; |
120 | $relationship['email'] = $value['email']; | |
121 | ||
122 | array_push($relationships, $relationship); | |
6a488035 | 123 | } |
1d85d241 | 124 | |
be2fb01f | 125 | $clientRelationshipsDT = []; |
ad280fb6 | 126 | $clientRelationshipsDT['data'] = $relationships; |
9c3f979f MM |
127 | $clientRelationshipsDT['recordsTotal'] = count($relationships); |
128 | $clientRelationshipsDT['recordsFiltered'] = count($relationships); | |
aab589e2 | 129 | |
ad280fb6 | 130 | CRM_Utils_JSON::output($clientRelationshipsDT); |
1d85d241 DL |
131 | } |
132 | ||
00be9182 | 133 | public static function getCaseRoles() { |
353ffa53 | 134 | $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); |
6a488035 | 135 | $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); |
1d85d241 | 136 | |
9c3f979f | 137 | $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); |
6a488035 | 138 | |
f537dc05 | 139 | $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID, NULL, FALSE); |
6a488035 TO |
140 | $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name'); |
141 | $xmlProcessor = new CRM_Case_XMLProcessor_Process(); | |
353ffa53 | 142 | $caseRoles = $xmlProcessor->get($caseTypeName, 'CaseRoles'); |
1d85d241 | 143 | |
6a488035 | 144 | $hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities'); |
1d85d241 | 145 | |
6a488035 | 146 | $managerRoleId = $xmlProcessor->getCaseManagerRoleId($caseTypeName); |
ad280fb6 | 147 | |
6a488035 | 148 | foreach ($caseRelationships as $key => $value) { |
3b1c37fe | 149 | // This role has been filled |
41cf58d3 | 150 | unset($caseRoles[$value['relation_type'] . '_' . $value['relationship_direction']]); |
b44e3f84 | 151 | // mark original case relationships record to use on setting edit links below |
6a488035 TO |
152 | $caseRelationships[$key]['source'] = 'caseRel'; |
153 | } | |
1d85d241 | 154 | |
6a488035 TO |
155 | $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($caseID); |
156 | ||
157 | // move/transform caseRoles array data to caseRelationships | |
158 | // for sorting and display | |
5b6db2c7 | 159 | // CRM-14466 added cid to the non-client array to avoid php notice |
22e263ad | 160 | foreach ($caseRoles as $id => $value) { |
6a488035 | 161 | if ($id != "client") { |
be2fb01f | 162 | $rel = []; |
6a488035 TO |
163 | $rel['relation'] = $value; |
164 | $rel['relation_type'] = $id; | |
f537dc05 | 165 | $rel['sort_name'] = '(not assigned)'; |
6a488035 TO |
166 | $rel['phone'] = ''; |
167 | $rel['email'] = ''; | |
f537dc05 SP |
168 | $rel['is_active'] = ''; |
169 | $rel['end_date'] = ''; | |
6a488035 TO |
170 | $rel['source'] = 'caseRoles'; |
171 | $caseRelationships[] = $rel; | |
0db6c3e1 TO |
172 | } |
173 | else { | |
22e263ad | 174 | foreach ($value as $clientRole) { |
be2fb01f | 175 | $relClient = []; |
5eb4e891 | 176 | $relClient['relation'] = ts('Client'); |
f537dc05 | 177 | $relClient['sort_name'] = $clientRole['sort_name']; |
6a488035 TO |
178 | $relClient['phone'] = $clientRole['phone']; |
179 | $relClient['email'] = $clientRole['email']; | |
180 | $relClient['cid'] = $clientRole['contact_id']; | |
231066be | 181 | $relClient['end_date'] = ''; |
6a488035 TO |
182 | $relClient['source'] = 'contact'; |
183 | $caseRelationships[] = $relClient; | |
184 | } | |
185 | } | |
186 | } | |
187 | ||
188 | // sort clientRelationships array using jquery call params | |
1d154485 JP |
189 | $sortArray = []; |
190 | if (!empty($params['_raw_values']['sort'])) { | |
191 | foreach ($caseRelationships as $key => $row) { | |
192 | $sortArray[$key] = $row[$params['_raw_values']['sort'][0]]; | |
193 | } | |
194 | $sort_type = "SORT_" . strtoupper($params['_raw_values']['order'][0]); | |
195 | array_multisort($sortArray, constant($sort_type), $caseRelationships); | |
6a488035 | 196 | } |
6a488035 | 197 | |
be2fb01f | 198 | $relationships = []; |
5b6db2c7 | 199 | |
6a488035 | 200 | // set user name, email and edit columns links |
ad280fb6 | 201 | foreach ($caseRelationships as $key => &$row) { |
f537dc05 SP |
202 | // add disabled class if role is inactive |
203 | if (isset($row['is_active'])) { | |
204 | if ($row['is_active'] == '0') { | |
205 | $row['DT_RowClass'] = 'disabled'; | |
206 | } | |
207 | } | |
3b1c37fe CW |
208 | $typeLabel = $row['relation']; |
209 | // Add "<br />(Case Manager)" to label | |
41cf58d3 | 210 | if (!empty($row['relation_type']) && !empty($row['relationship_direction']) && $row['relation_type'] . '_' . $row['relationship_direction'] == $managerRoleId) { |
3b1c37fe CW |
211 | $row['relation'] .= '<br />' . '(' . ts('Case Manager') . ')'; |
212 | } | |
6a488035 | 213 | // view user links |
3662628a | 214 | if (!empty($row['cid'])) { |
f537dc05 SP |
215 | $row['sort_name'] = '<a class="view-contact" title="' . ts('View Contact') . '" href=' . CRM_Utils_System::url('civicrm/contact/view', |
216 | 'action=view&reset=1&cid=' . $row['cid']) . '>' . $row['sort_name'] . '</a>'; | |
5b6db2c7 | 217 | } |
6a488035 | 218 | // email column links/icon |
c91df8b4 | 219 | if ($row['email']) { |
13a3d214 | 220 | $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') . '"><i class="crm-i fa-envelope" aria-hidden="true"></i></a>'; |
6a488035 | 221 | } |
f537dc05 SP |
222 | |
223 | // view end date if set | |
224 | if (!empty($row['end_date'])) { | |
225 | $row['end_date'] = CRM_Utils_Date::customFormat($row['end_date']); | |
226 | // add disabled class if end date is less than equal to current date. | |
227 | if (CRM_Utils_Date::overdue($row['end_date'])) { | |
228 | $row['DT_RowClass'] = 'disabled'; | |
229 | } | |
230 | } | |
231 | else { | |
232 | $row['end_date'] = ''; | |
233 | } | |
234 | ||
6a488035 | 235 | // edit links |
3662628a | 236 | $row['actions'] = ''; |
6a488035 | 237 | if ($hasAccessToAllCases) { |
e3756c36 CW |
238 | $contactType = empty($row['relation_type']) ? '' : (string) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $row['relation_type'], 'contact_type_b'); |
239 | $contactType = $contactType == 'Contact' ? '' : $contactType; | |
22e263ad | 240 | switch ($row['source']) { |
32864ccf | 241 | case 'caseRel': |
f537dc05 SP |
242 | if (empty($row['end_date'])) { |
243 | $row['actions'] = '<a href="#editCaseRoleDialog" title="' . ts('Reassign %1', [1 => $typeLabel]) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '_' . $row['relationship_direction'] . '" data-cid="' . $row['cid'] . '" data-rel_id="' . $row['rel_id'] . '"data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' . | |
244 | '<i class="crm-i fa-pencil" aria-hidden="true"></i>' . | |
245 | '</a>' . | |
246 | '<a href="#deleteCaseRoleDialog" title="' . ts('Remove %1', [1 => $typeLabel]) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '_' . $row['relationship_direction'] . '" data-cid="' . $row['cid'] . '" data-key="' . CRM_Core_Key::get('civicrm/ajax/delcaserole') . '">' . | |
247 | '<span class="icon delete-icon"></span>' . | |
248 | '</a>'; | |
249 | } | |
32864ccf | 250 | break; |
1d85d241 | 251 | |
32864ccf | 252 | case 'caseRoles': |
be2fb01f | 253 | $row['actions'] = '<a href="#editCaseRoleDialog" title="' . ts('Assign %1', [1 => $typeLabel]) . '" class="crm-hover-button case-miniform" data-contact_type="' . $contactType . '" data-rel_type="' . $row['relation_type'] . '_a_b" data-key="' . CRM_Core_Key::get('civicrm/ajax/relation') . '">' . |
13a3d214 | 254 | '<i class="crm-i fa-pencil" aria-hidden="true"></i>' . |
353ffa53 | 255 | '</a>'; |
32864ccf | 256 | break; |
6a488035 | 257 | } |
6a488035 | 258 | } |
ad280fb6 JL |
259 | unset($row['cid']); |
260 | unset($row['relation_type']); | |
261 | unset($row['rel_id']); | |
262 | unset($row['client_id']); | |
263 | unset($row['source']); | |
264 | array_push($relationships, $row); | |
6a488035 | 265 | } |
ad280fb6 JL |
266 | $params['total'] = count($relationships); |
267 | ||
be2fb01f | 268 | $caseRelationshipsDT = []; |
ad280fb6 JL |
269 | $caseRelationshipsDT['data'] = $relationships; |
270 | $caseRelationshipsDT['recordsTotal'] = $params['total']; | |
271 | $caseRelationshipsDT['recordsFiltered'] = $params['total']; | |
272 | ||
273 | CRM_Utils_JSON::output($caseRelationshipsDT); | |
ffd93213 | 274 | |
1d85d241 DL |
275 | } |
276 | ||
00be9182 | 277 | public static function convertToCaseActivity() { |
be2fb01f CW |
278 | $params = ['caseID', 'activityID', 'contactID', 'newSubject', 'targetContactIds', 'mode']; |
279 | $vals = []; | |
6a488035 | 280 | foreach ($params as $param) { |
9c1bc317 | 281 | $vals[$param] = $_POST[$param] ?? NULL; |
6a488035 TO |
282 | } |
283 | ||
ecdef330 | 284 | CRM_Utils_JSON::output(self::_convertToCaseActivity($vals)); |
6a488035 TO |
285 | } |
286 | ||
ffd93213 | 287 | /** |
c490a46a | 288 | * @param array $params |
ffd93213 EM |
289 | * |
290 | * @return array | |
291 | */ | |
00be9182 | 292 | public static function _convertToCaseActivity($params) { |
6a488035 | 293 | if (!$params['activityID'] || !$params['caseID']) { |
be2fb01f | 294 | return (['error_msg' => 'required params missing.']); |
6a488035 TO |
295 | } |
296 | ||
297 | $otherActivity = new CRM_Activity_DAO_Activity(); | |
298 | $otherActivity->id = $params['activityID']; | |
299 | if (!$otherActivity->find(TRUE)) { | |
be2fb01f | 300 | return (['error_msg' => 'activity record is missing.']); |
6a488035 | 301 | } |
9573d2c5 | 302 | $actDateTime = $otherActivity->activity_date_time; |
6a488035 | 303 | |
7808aae6 | 304 | // Create new activity record. |
6a488035 | 305 | $mainActivity = new CRM_Activity_DAO_Activity(); |
be2fb01f | 306 | $mainActVals = []; |
6a488035 TO |
307 | CRM_Core_DAO::storeValues($otherActivity, $mainActVals); |
308 | ||
7808aae6 | 309 | // Get new activity subject. |
6a488035 TO |
310 | if (!empty($params['newSubject'])) { |
311 | $mainActVals['subject'] = $params['newSubject']; | |
312 | } | |
313 | ||
314 | $mainActivity->copyValues($mainActVals); | |
315 | $mainActivity->id = NULL; | |
316 | $mainActivity->activity_date_time = $actDateTime; | |
7808aae6 | 317 | // Make sure this is current revision. |
6a488035 | 318 | $mainActivity->is_current_revision = TRUE; |
9a30d940 MWMC |
319 | $mainActivity->original_id = $otherActivity->id; |
320 | $otherActivity->is_current_revision = FALSE; | |
6a488035 TO |
321 | |
322 | $mainActivity->save(); | |
323 | $mainActivityId = $mainActivity->id; | |
324 | CRM_Activity_BAO_Activity::logActivityAction($mainActivity); | |
6a488035 | 325 | |
7808aae6 SB |
326 | // Mark previous activity as deleted. If it was a non-case activity |
327 | // then just change the subject. | |
be2fb01f | 328 | if (in_array($params['mode'], [ |
353ffa53 | 329 | 'move', |
79d7553f | 330 | 'file', |
be2fb01f | 331 | ])) { |
6a488035 TO |
332 | $caseActivity = new CRM_Case_DAO_CaseActivity(); |
333 | $caseActivity->case_id = $params['caseID']; | |
334 | $caseActivity->activity_id = $otherActivity->id; | |
335 | if ($params['mode'] == 'move' || $caseActivity->find(TRUE)) { | |
336 | $otherActivity->is_deleted = 1; | |
337 | } | |
338 | else { | |
be2fb01f | 339 | $otherActivity->subject = ts('(Filed on case %1)', [ |
c5c263ca | 340 | 1 => $params['caseID'], |
be2fb01f | 341 | ]) . ' ' . $otherActivity->subject; |
6a488035 | 342 | } |
6a488035 TO |
343 | $otherActivity->save(); |
344 | ||
6a488035 | 345 | } |
6a488035 | 346 | |
be2fb01f | 347 | $targetContacts = []; |
6a488035 TO |
348 | if (!empty($params['targetContactIds'])) { |
349 | $targetContacts = array_unique(explode(',', $params['targetContactIds'])); | |
350 | } | |
f813f78e | 351 | |
44f817d4 | 352 | $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate'); |
a24b3694 | 353 | $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); |
354 | $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); | |
355 | $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); | |
356 | ||
7b1ec1c6 | 357 | $sourceContactID = CRM_Activity_BAO_Activity::getSourceContactID($params['activityID']); |
be2fb01f | 358 | $src_params = [ |
7b1ec1c6 | 359 | 'activity_id' => $mainActivityId, |
360 | 'contact_id' => $sourceContactID, | |
21dfd5f5 | 361 | 'record_type_id' => $sourceID, |
be2fb01f | 362 | ]; |
7b1ec1c6 | 363 | CRM_Activity_BAO_ActivityContact::create($src_params); |
364 | ||
6a488035 | 365 | foreach ($targetContacts as $key => $value) { |
be2fb01f | 366 | $targ_params = [ |
6a488035 | 367 | 'activity_id' => $mainActivityId, |
1d85d241 | 368 | 'contact_id' => $value, |
21dfd5f5 | 369 | 'record_type_id' => $targetID, |
be2fb01f | 370 | ]; |
1d85d241 | 371 | CRM_Activity_BAO_ActivityContact::create($targ_params); |
6a488035 TO |
372 | } |
373 | ||
c012436d BS |
374 | //CRM-21114 retrieve assignee contacts from original case; allow overriding from params |
375 | $assigneeContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($params['activityID'], $assigneeID); | |
6a488035 TO |
376 | if (!empty($params['assigneeContactIds'])) { |
377 | $assigneeContacts = array_unique(explode(',', $params['assigneeContactIds'])); | |
378 | } | |
5402bfb8 | 379 | foreach ($assigneeContacts as $value) { |
be2fb01f | 380 | $assigneeParams = [ |
6a488035 | 381 | 'activity_id' => $mainActivityId, |
1d85d241 | 382 | 'contact_id' => $value, |
21dfd5f5 | 383 | 'record_type_id' => $assigneeID, |
be2fb01f | 384 | ]; |
1d85d241 | 385 | CRM_Activity_BAO_ActivityContact::create($assigneeParams); |
6a488035 TO |
386 | } |
387 | ||
7808aae6 | 388 | // Attach newly created activity to case. |
6a488035 TO |
389 | $caseActivity = new CRM_Case_DAO_CaseActivity(); |
390 | $caseActivity->case_id = $params['caseID']; | |
391 | $caseActivity->activity_id = $mainActivityId; | |
392 | $caseActivity->save(); | |
393 | $error_msg = $caseActivity->_lastError; | |
6a488035 TO |
394 | |
395 | $params['mainActivityId'] = $mainActivityId; | |
396 | CRM_Activity_BAO_Activity::copyExtendedActivityData($params); | |
388995aa | 397 | CRM_Utils_Hook::post('create', 'CaseActivity', $caseActivity->id, $caseActivity); |
6a488035 | 398 | |
be2fb01f | 399 | return (['error_msg' => $error_msg, 'newId' => $mainActivity->id]); |
6a488035 TO |
400 | } |
401 | ||
f2ac86d1 | 402 | /** |
403 | * Get activities for the contact. | |
404 | * | |
a413c3db | 405 | * @throws \CRM_Core_Exception |
f2ac86d1 | 406 | */ |
00be9182 | 407 | public static function getContactActivity() { |
be2fb01f | 408 | $requiredParameters = [ |
9c3f979f | 409 | 'cid' => 'Integer', |
be2fb01f | 410 | ]; |
6a488035 | 411 | |
be2fb01f | 412 | $optionalParameters = [ |
9c3f979f | 413 | 'context' => 'String', |
23289ddd | 414 | 'activity_type_id' => 'Integer', |
415 | 'activity_type_exclude_id' => 'Integer', | |
49d4d222 | 416 | 'activity_status_id' => 'String', |
6e793248 | 417 | 'activity_date_time_relative' => 'String', |
418 | 'activity_date_time_low' => 'String', | |
419 | 'activity_date_time_high' => 'String', | |
be2fb01f | 420 | ]; |
6a488035 | 421 | |
9c3f979f | 422 | $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); |
5d817a13 | 423 | $params += CRM_Core_Page_AJAX::validateParams($requiredParameters, $optionalParameters); |
3af26897 LS |
424 | // $params will be modified later on, need to save original filters |
425 | $filterParams = $params; | |
6a488035 | 426 | |
e8691b2c MM |
427 | // To be consistent, the cid parameter should be renamed to contact_id in |
428 | // the template file, see templates/CRM/Activity/Selector/Selector.tpl | |
429 | $params['contact_id'] = $params['cid']; | |
430 | unset($params['cid']); | |
431 | ||
6a488035 TO |
432 | // get the contact activities |
433 | $activities = CRM_Activity_BAO_Activity::getContactActivitySelector($params); | |
434 | ||
c7d77593 | 435 | foreach ($activities['data'] as $key => $value) { |
7808aae6 | 436 | // Check if recurring activity. |
b53cbfbc | 437 | if (!empty($value['is_recurring_activity'])) { |
04374d9d | 438 | $repeat = $value['is_recurring_activity']; |
be2fb01f | 439 | $activities['data'][$key]['activity_type'] .= '<br/><span class="bold">' . ts('Repeating (%1 of %2)', [1 => $repeat[0], 2 => $repeat[1]]) . '</span>'; |
97c7504f | 440 | } |
441 | } | |
442 | ||
6a488035 | 443 | // store the activity filter preference CRM-11761 |
a6d192c8 | 444 | if (Civi::settings()->get('preserve_activity_tab_filter') && ($userID = CRM_Core_Session::getLoggedInContactID())) { |
3af26897 | 445 | $activityFilter = []; |
a6d192c8 | 446 | unset($optionalParameters['context']); |
447 | foreach ($optionalParameters as $searchField => $dataType) { | |
c3a9ccbb | 448 | $formSearchField = $searchField; |
a413c3db | 449 | if ($searchField === 'activity_type_id') { |
c3a9ccbb JP |
450 | $formSearchField = 'activity_type_filter_id'; |
451 | } | |
a413c3db | 452 | elseif ($searchField === 'activity_type_exclude_id') { |
c3a9ccbb JP |
453 | $formSearchField = 'activity_type_exclude_filter_id'; |
454 | } | |
3af26897 LS |
455 | if (!empty($filterParams[$searchField])) { |
456 | $activityFilter[$formSearchField] = $filterParams[$searchField]; | |
be2fb01f | 457 | if (in_array($searchField, ['activity_date_time_low', 'activity_date_time_high'])) { |
e04e6d91 | 458 | $activityFilter['activity_date_time_relative'] = 0; |
a6d192c8 | 459 | } |
a413c3db | 460 | elseif ($searchField === 'activity_status_id') { |
a6d192c8 | 461 | $activityFilter['status_id'] = explode(',', $activityFilter[$searchField]); |
462 | } | |
463 | } | |
a6d192c8 | 464 | } |
f3548d18 | 465 | |
c3c679b0 | 466 | Civi::contactSettings()->set('activity_tab_filter', $activityFilter); |
6a488035 | 467 | } |
1d85d241 | 468 | |
7d12de7f | 469 | CRM_Utils_JSON::output($activities); |
6a488035 | 470 | } |
96025800 | 471 | |
6a488035 | 472 | } |