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 | /** | |
3819f101 | 19 | * This class generates view mode for CiviCase. |
6a488035 TO |
20 | */ |
21 | class CRM_Case_Form_CaseView extends CRM_Core_Form { | |
c490a46a | 22 | /** |
100fef9d | 23 | * Check for merge cases. |
c490a46a CW |
24 | * @var bool |
25 | */ | |
6a488035 TO |
26 | private $_mergeCases = FALSE; |
27 | ||
28 | /** | |
fe482240 | 29 | * Set variables up before form is built. |
6a488035 TO |
30 | */ |
31 | public function preProcess() { | |
9c1bc317 | 32 | $this->_showRelatedCases = $_GET['relatedCases'] ?? NULL; |
6a488035 TO |
33 | |
34 | $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); | |
35 | $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); | |
36 | $this->assign('multiClient', $isMultiClient); | |
37 | ||
38 | //pull the related cases. | |
39 | $this->assign('showRelatedCases', FALSE); | |
40 | if ($this->_showRelatedCases) { | |
41 | $relatedCases = $this->get('relatedCases'); | |
42 | if (!isset($relatedCases)) { | |
a3d827a7 CW |
43 | $cId = CRM_Utils_Request::retrieve('cid', 'Integer'); |
44 | $caseId = CRM_Utils_Request::retrieve('id', 'Integer'); | |
6e19e2ea | 45 | $relatedCases = CRM_Case_BAO_Case::getRelatedCases($caseId); |
6a488035 TO |
46 | } |
47 | $this->assign('relatedCases', $relatedCases); | |
48 | $this->assign('showRelatedCases', TRUE); | |
5ffd5a35 | 49 | CRM_Utils_System::setTitle(ts('Related Cases')); |
6a488035 TO |
50 | return; |
51 | } | |
52 | ||
6a488035 TO |
53 | $this->_hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities'); |
54 | $this->assign('hasAccessToAllCases', $this->_hasAccessToAllCases); | |
55 | ||
0a1a8b63 CW |
56 | $this->assign('contactID', $this->_contactID = (int) $this->get('cid')); |
57 | $this->assign('caseID', $this->_caseID = (int) $this->get('id')); | |
58 | ||
59 | // Access check. | |
60 | if (!CRM_Case_BAO_Case::accessCase($this->_caseID, FALSE)) { | |
f28d3b6a | 61 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this case.')); |
0a1a8b63 | 62 | } |
6a488035 | 63 | |
edc80cda | 64 | $fulltext = CRM_Utils_Request::retrieve('context', 'Alphanumeric'); |
6a488035 TO |
65 | if ($fulltext == 'fulltext') { |
66 | $this->assign('fulltext', $fulltext); | |
67 | } | |
68 | ||
e7e57280 | 69 | $this->assign('contactType', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type')); |
0a1a8b63 | 70 | $this->assign('userID', CRM_Core_Session::getLoggedInContactID()); |
6a488035 TO |
71 | |
72 | //retrieve details about case | |
be2fb01f | 73 | $params = ['id' => $this->_caseID]; |
6a488035 | 74 | |
be2fb01f | 75 | $returnProperties = ['case_type_id', 'subject', 'status_id', 'start_date']; |
6a488035 TO |
76 | CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, $returnProperties); |
77 | ||
353ffa53 | 78 | $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE); |
6a488035 | 79 | $caseTypeName = CRM_Case_BAO_Case::getCaseType($this->_caseID, 'name'); |
353ffa53 | 80 | $caseType = CRM_Case_BAO_Case::getCaseType($this->_caseID); |
6a488035 | 81 | |
be2fb01f | 82 | $this->_caseDetails = [ |
6a488035 | 83 | 'case_type' => $caseType, |
6b409353 CW |
84 | 'case_status' => $statuses[$values['case_status_id']] ?? NULL, |
85 | 'case_subject' => $values['subject'] ?? NULL, | |
6a488035 | 86 | 'case_start_date' => $values['case_start_date'], |
be2fb01f | 87 | ]; |
6a488035 TO |
88 | $this->_caseType = $caseTypeName; |
89 | $this->assign('caseDetails', $this->_caseDetails); | |
90 | ||
6a488035 TO |
91 | // add to recently viewed |
92 | ||
93 | $url = CRM_Utils_System::url('civicrm/contact/view/case', | |
94 | "action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home" | |
95 | ); | |
96 | ||
97 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID); | |
98 | $this->assign('displayName', $displayName); | |
99 | ||
b74958a4 | 100 | CRM_Utils_System::setTitle($displayName . ' - ' . $caseType); |
6a488035 | 101 | |
be2fb01f | 102 | $recentOther = []; |
6a488035 TO |
103 | if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) { |
104 | $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case', | |
105 | "action=delete&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home" | |
106 | ); | |
107 | } | |
108 | ||
b74958a4 | 109 | // Add the recently viewed case |
6a488035 TO |
110 | CRM_Utils_Recent::add($displayName . ' - ' . $caseType, |
111 | $url, | |
112 | $this->_caseID, | |
113 | 'Case', | |
114 | $this->_contactID, | |
115 | NULL, | |
116 | $recentOther | |
117 | ); | |
118 | ||
6a488035 TO |
119 | //get the related cases for given case. |
120 | $relatedCases = $this->get('relatedCases'); | |
121 | if (!isset($relatedCases)) { | |
6e19e2ea | 122 | $relatedCases = CRM_Case_BAO_Case::getRelatedCases($this->_caseID); |
6a488035 TO |
123 | $relatedCases = empty($relatedCases) ? FALSE : $relatedCases; |
124 | $this->set('relatedCases', $relatedCases); | |
125 | } | |
5ffd5a35 CW |
126 | $this->assign('hasRelatedCases', (bool) $relatedCases); |
127 | if ($relatedCases) { | |
be2fb01f | 128 | $this->assign('relatedCaseLabel', ts('%1 Related Case', [ |
5d4fcf54 TO |
129 | 'count' => count($relatedCases), |
130 | 'plural' => '%1 Related Cases', | |
131 | ])); | |
be2fb01f | 132 | $this->assign('relatedCaseUrl', CRM_Utils_System::url('civicrm/contact/view/case', [ |
5ffd5a35 CW |
133 | 'id' => $this->_caseID, |
134 | 'cid' => $this->_contactID, | |
135 | 'relatedCases' => 1, | |
136 | 'action' => 'view', | |
be2fb01f | 137 | ])); |
5ffd5a35 | 138 | } |
6a488035 | 139 | |
8ffdec17 | 140 | $entitySubType = !empty($values['case_type_id']) ? $values['case_type_id'] : NULL; |
6a488035 | 141 | $this->assign('caseTypeID', $entitySubType); |
517755e0 | 142 | $groupTree = CRM_Core_BAO_CustomGroup::getTree('Case', |
0b330e6d | 143 | NULL, |
6a488035 TO |
144 | $this->_caseID, |
145 | NULL, | |
146 | $entitySubType | |
147 | ); | |
e34e6979 | 148 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_caseID); |
6a488035 TO |
149 | } |
150 | ||
151 | /** | |
3819f101 | 152 | * Set default values for the form. |
6a488035 | 153 | * |
3819f101 | 154 | * @return array; |
6a488035 | 155 | */ |
00be9182 | 156 | public function setDefaultValues() { |
be2fb01f | 157 | $defaults = []; |
6a488035 TO |
158 | return $defaults; |
159 | } | |
160 | ||
161 | /** | |
fe482240 | 162 | * Build the form object. |
6a488035 TO |
163 | */ |
164 | public function buildQuickForm() { | |
165 | //this call is for show related cases. | |
166 | if ($this->_showRelatedCases) { | |
167 | return; | |
168 | } | |
169 | ||
0004ae05 | 170 | $allowedRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactID); |
9c7ffe36 CW |
171 | $relationshipTypeMetadata = CRM_Contact_Form_Relationship::getRelationshipTypeMetadata($allowedRelationshipTypes); |
172 | ||
173 | $caseTypeDefinition = civicrm_api3('CaseType', 'getsingle', ['name' => $this->_caseType])['definition']; | |
174 | ||
175 | foreach ($caseTypeDefinition['caseRoles'] as $role) { | |
176 | if (!empty($role['groups'])) { | |
177 | $relationshipType = civicrm_api3('RelationshipType', 'get', [ | |
178 | 'sequential' => 1, | |
179 | 'name_a_b' => $role['name'], | |
180 | 'name_b_a' => $role['name'], | |
181 | 'options' => ['limit' => 1, 'or' => [["name_a_b", "name_b_a"]]], | |
182 | ]); | |
183 | if (($relationshipType['values'][0]['name_a_b'] ?? NULL) === $role['name']) { | |
184 | $relationshipTypeMetadata[$relationshipType['id']]['group_a'] = $role['groups']; | |
185 | } | |
186 | if (($relationshipType['values'][0]['name_b_a'] ?? NULL) === $role['name']) { | |
187 | $relationshipTypeMetadata[$relationshipType['id']]['group_b'] = $role['groups']; | |
188 | } | |
189 | } | |
190 | } | |
0004ae05 | 191 | |
5ffd5a35 | 192 | CRM_Core_Resources::singleton() |
96ed17aa | 193 | ->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header') |
0004ae05 | 194 | ->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js', 2, 'html-header') |
9c7ffe36 | 195 | ->addVars('relationshipTypes', $relationshipTypeMetadata); |
5ffd5a35 | 196 | |
6a488035 | 197 | $xmlProcessor = new CRM_Case_XMLProcessor_Process(); |
353ffa53 TO |
198 | $caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles'); |
199 | $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); | |
6a488035 TO |
200 | |
201 | //adding case manager.CRM-4510. | |
202 | $managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType); | |
203 | if (!empty($managerRoleId)) { | |
204 | $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')'; | |
205 | } | |
206 | ||
207 | $aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE); | |
208 | ||
5346744e | 209 | $allActTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id', 'validate'); |
5ffd5a35 | 210 | $emailActivityType = array_search('Email', $allActTypes); |
fd54c68d | 211 | $pdfActivityType = array_search('Print PDF Letter', $allActTypes); |
5ffd5a35 | 212 | |
e43d5206 CW |
213 | if ($pdfActivityType) { |
214 | $this->assign('exportDoc', CRM_Utils_System::url('civicrm/activity/pdf/add', | |
215 | "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$pdfActivityType")); | |
216 | } | |
217 | ||
6a488035 | 218 | // remove Open Case activity type since we're inside an existing case |
5ffd5a35 | 219 | if ($openActTypeId = array_search('Open Case', $allActTypes)) { |
6a488035 TO |
220 | unset($aTypes[$openActTypeId]); |
221 | } | |
222 | ||
abd06efc CW |
223 | // Only show "link cases" activity if other cases exist. |
224 | $linkActTypeId = array_search('Link Cases', $allActTypes); | |
225 | if ($linkActTypeId) { | |
be2fb01f | 226 | $count = civicrm_api3('Case', 'getcount', [ |
0a1a8b63 | 227 | 'check_permissions' => TRUE, |
be2fb01f | 228 | 'id' => ['!=' => $this->_caseID], |
abd06efc | 229 | 'is_deleted' => 0, |
be2fb01f | 230 | ]); |
abd06efc CW |
231 | if (!$count) { |
232 | unset($aTypes[$linkActTypeId]); | |
233 | } | |
6a488035 TO |
234 | } |
235 | ||
236 | if (!$xmlProcessor->getNaturalActivityTypeSort()) { | |
237 | asort($aTypes); | |
238 | } | |
239 | ||
be2fb01f | 240 | $activityLinks = ['' => ts('Add Activity')]; |
5ffd5a35 CW |
241 | foreach ($aTypes as $type => $label) { |
242 | if ($type == $emailActivityType) { | |
243 | $url = CRM_Utils_System::url('civicrm/activity/email/add', | |
244 | "action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype=$type", | |
245 | FALSE, NULL, FALSE | |
246 | ); | |
ed92d614 | 247 | } |
481a74f4 | 248 | elseif ($type == $pdfActivityType) { |
e547f744 | 249 | $url = CRM_Utils_System::url('civicrm/activity/pdf/add', |
fd54c68d | 250 | "action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$type", |
481a74f4 | 251 | FALSE, NULL, FALSE); |
5e54ab6c | 252 | } |
5ffd5a35 CW |
253 | else { |
254 | $url = CRM_Utils_System::url('civicrm/case/activity', | |
255 | "action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$type", | |
256 | FALSE, NULL, FALSE | |
257 | ); | |
258 | } | |
259 | $activityLinks[$url] = $label; | |
260 | } | |
261 | ||
be2fb01f | 262 | $this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, ['class' => 'crm-select2 crm-action-menu fa-calendar-check-o twenty']); |
6a488035 | 263 | if ($this->_hasAccessToAllCases) { |
2a06342c | 264 | $this->add('select', 'report_id', '', |
be2fb01f | 265 | ['' => ts('Activity Audit')] + $reports, |
2a06342c | 266 | FALSE, |
be2fb01f | 267 | ['class' => 'crm-select2 crm-action-menu fa-list-alt'] |
6a488035 | 268 | ); |
2a06342c | 269 | $this->add('select', 'timeline_id', '', |
be2fb01f | 270 | ['' => ts('Add Timeline')] + $reports, |
2a06342c | 271 | FALSE, |
be2fb01f | 272 | ['class' => 'crm-select2 crm-action-menu fa-list-ol'] |
6a488035 TO |
273 | ); |
274 | } | |
f0050a47 | 275 | // This button is hidden but gets clicked by javascript at |
276 | // https://github.com/civicrm/civicrm-core/blob/bd28ecf8121a85bc069cad3ab912a0c3dff8fdc5/templates/CRM/Case/Form/CaseView.js#L194 | |
277 | // by the onChange handler for the above timeline_id select. | |
cbd83dde AH |
278 | $this->addElement('xbutton', $this->getButtonName('next'), ' ', [ |
279 | 'class' => 'hiddenElement', | |
280 | 'type' => 'submit', | |
281 | ]); | |
6a488035 | 282 | |
0a1a8b63 | 283 | $this->buildMergeCaseForm(); |
6a488035 | 284 | |
fc7d8951 | 285 | //call activity form |
504f0f9c | 286 | self::activityForm($this, $aTypes); |
6a488035 TO |
287 | |
288 | //get case related relationships (Case Role) | |
289 | $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID); | |
290 | ||
291 | //save special label because we unset it in the loop | |
292 | $managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId]; | |
293 | ||
6a488035 | 294 | foreach ($caseRelationships as $key => & $value) { |
6a488035 | 295 | if (!empty($managerRoleId)) { |
41cf58d3 | 296 | if (substr($managerRoleId, 0, -4) == $value['relation_type'] && substr($managerRoleId, -3) == $value['relationship_direction']) { |
6a488035 TO |
297 | $value['relation'] = $managerLabel; |
298 | } | |
299 | } | |
300 | ||
301 | //calculate roles that don't have relationships | |
a7488080 | 302 | if (!empty($caseRoles[$value['relation_type']])) { |
6a488035 TO |
303 | unset($caseRoles[$value['relation_type']]); |
304 | } | |
305 | } | |
306 | ||
6a488035 TO |
307 | $this->assign('caseRelationships', $caseRelationships); |
308 | ||
309 | //also add client as role. CRM-4438 | |
310 | $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID); | |
311 | ||
312 | $this->assign('caseRoles', $caseRoles); | |
313 | ||
6a488035 TO |
314 | // Retrieve ALL client relationships |
315 | $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID, | |
316 | CRM_Contact_BAO_Relationship::CURRENT, | |
317 | 0, 0, 0, NULL, NULL, FALSE | |
318 | ); | |
319 | ||
320 | // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles | |
321 | // so they don't show up twice. | |
be2fb01f | 322 | $clientRelationships = []; |
6a488035 TO |
323 | foreach ($relClient as $r) { |
324 | if (!array_key_exists($r['id'], $caseRelationships)) { | |
325 | $clientRelationships[] = $r; | |
326 | } | |
327 | } | |
328 | $this->assign('clientRelationships', $clientRelationships); | |
329 | ||
330 | // Now global contact list that appears on all cases. | |
be2fb01f | 331 | $globalGroupInfo = []; |
d79c94d5 | 332 | CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo); |
6a488035 TO |
333 | $this->assign('globalGroupInfo', $globalGroupInfo); |
334 | ||
3b1c37fe | 335 | // List relationship types for adding an arbitrary new role to the case |
0004ae05 CW |
336 | $this->add('select', |
337 | 'role_type', | |
338 | ts('Relationship Type'), | |
be2fb01f | 339 | ['' => ts('- select type -')] + $allowedRelationshipTypes, |
0004ae05 | 340 | FALSE, |
be2fb01f | 341 | ['class' => 'crm-select2 twenty', 'data-select-params' => '{"allowClear": false}'] |
0004ae05 | 342 | ); |
6a488035 TO |
343 | |
344 | $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID); | |
345 | if (is_array($hookCaseSummary)) { | |
346 | $this->assign('hookCaseSummary', $hookCaseSummary); | |
347 | } | |
348 | ||
b733747a | 349 | $allTags = CRM_Core_BAO_Tag::getColorTags('civicrm_case'); |
6a488035 TO |
350 | |
351 | if (!empty($allTags)) { | |
b733747a | 352 | $this->add('select2', 'case_tag', ts('Tags'), $allTags, FALSE, |
be2fb01f | 353 | ['id' => 'tags', 'multiple' => 'multiple'] |
6a488035 TO |
354 | ); |
355 | ||
356 | $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case'); | |
357 | ||
6a488035 | 358 | foreach ($tags as $tid) { |
b733747a CW |
359 | $tagInfo = CRM_Utils_Array::findInTree($tid, $allTags); |
360 | if ($tagInfo) { | |
361 | $tags[$tid] = $tagInfo; | |
6fd5424b | 362 | } |
363 | else { | |
364 | unset($tags[$tid]); | |
365 | } | |
6a488035 TO |
366 | } |
367 | ||
be2fb01f | 368 | $this->setDefaults(['case_tag' => implode(',', array_keys($tags))]); |
b733747a CW |
369 | |
370 | $this->assign('tags', $tags); | |
6a488035 TO |
371 | $this->assign('showTags', TRUE); |
372 | } | |
373 | else { | |
374 | $this->assign('showTags', FALSE); | |
375 | } | |
376 | ||
377 | // build tagset widget | |
378 | ||
379 | // see if we have any tagsets which can be assigned to cases | |
380 | $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); | |
be2fb01f | 381 | $tagSetTags = []; |
6a488035 | 382 | if ($parentNames) { |
79564bd4 | 383 | $this->assign('showTags', TRUE); |
be2fb01f | 384 | $tagSetItems = civicrm_api3('entityTag', 'get', [ |
79564bd4 CW |
385 | 'entity_id' => $this->_caseID, |
386 | 'entity_table' => 'civicrm_case', | |
8eecc659 | 387 | 'tag_id.parent_id.is_tagset' => 1, |
be2fb01f CW |
388 | 'options' => ['limit' => 0], |
389 | 'return' => ["tag_id.parent_id", "tag_id.parent_id.name", "tag_id.name"], | |
390 | ]); | |
8eecc659 | 391 | foreach ($tagSetItems['values'] as $tag) { |
be2fb01f CW |
392 | $tagSetTags += [ |
393 | $tag['tag_id.parent_id'] => [ | |
8eecc659 | 394 | 'name' => $tag['tag_id.parent_id.name'], |
be2fb01f CW |
395 | 'items' => [], |
396 | ], | |
397 | ]; | |
8eecc659 | 398 | $tagSetTags[$tag['tag_id.parent_id']]['items'][] = $tag['tag_id.name']; |
79564bd4 | 399 | } |
6a488035 | 400 | } |
8eecc659 | 401 | $this->assign('tagSetTags', $tagSetTags); |
95ef220a | 402 | CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE); |
6a488035 | 403 | |
be2fb01f | 404 | $this->addButtons([ |
5d4fcf54 TO |
405 | [ |
406 | 'type' => 'cancel', | |
407 | 'name' => ts('Done'), | |
408 | 'spacing' => ' ', | |
409 | 'isDefault' => TRUE, | |
410 | ], | |
411 | ]); | |
6a488035 TO |
412 | } |
413 | ||
414 | /** | |
fe482240 | 415 | * Process the form. |
6a488035 TO |
416 | */ |
417 | public function postProcess() { | |
418 | $params = $this->controller->exportValues($this->_name); | |
419 | $buttonName = $this->controller->getButtonName(); | |
420 | ||
421 | // user context | |
422 | $url = CRM_Utils_System::url('civicrm/contact/view/case', | |
423 | "reset=1&action=view&cid={$this->_contactID}&id={$this->_caseID}&show=1" | |
424 | ); | |
425 | $session = CRM_Core_Session::singleton(); | |
426 | $session->pushUserContext($url); | |
427 | ||
221e7200 | 428 | if (!empty($params['timeline_id']) && $buttonName == '_qf_CaseView_next') { |
be2fb01f | 429 | civicrm_api3('Case', 'addtimeline', [ |
ae76ce5e CW |
430 | 'case_id' => $this->_caseID, |
431 | 'timeline' => $params['timeline_id'], | |
be2fb01f | 432 | ]); |
ae76ce5e | 433 | |
353ffa53 | 434 | $xmlProcessor = new CRM_Case_XMLProcessor_Process(); |
6a488035 | 435 | $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets'); |
6a488035 | 436 | CRM_Core_Session::setStatus(ts('Activities from the %1 activity set have been added to this case.', |
be2fb01f | 437 | [1 => $reports[$params['timeline_id']]] |
6a488035 TO |
438 | ), ts('Done'), 'success'); |
439 | } | |
440 | elseif ($this->_mergeCases && | |
441 | $buttonName == '_qf_CaseView_next_merge_case' | |
442 | ) { | |
443 | ||
444 | $mainCaseId = $params['merge_case_id']; | |
445 | $otherCaseId = $this->_caseID; | |
446 | ||
447 | //merge two cases. | |
448 | CRM_Case_BAO_Case::mergeCases($this->_contactID, $mainCaseId, NULL, $otherCaseId); | |
449 | ||
450 | //redirect user to main case view. | |
451 | $url = CRM_Utils_System::url('civicrm/contact/view/case', | |
452 | "reset=1&action=view&cid={$this->_contactID}&id={$mainCaseId}&show=1" | |
453 | ); | |
454 | $session = CRM_Core_Session::singleton(); | |
455 | $session->pushUserContext($url); | |
456 | } | |
6a488035 | 457 | } |
85859f88 CW |
458 | |
459 | /** | |
460 | * Build the activity selector/datatable | |
461 | * @param CRM_Core_Form $form | |
64bd5a0e TO |
462 | * @param array $aTypes |
463 | * To include acivities related to current case id $form->_caseID. | |
85859f88 | 464 | */ |
be2fb01f | 465 | public static function activityForm($form, $aTypes = []) { |
85859f88 CW |
466 | $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($form->_contactID, $form->_caseID); |
467 | //build reporter select | |
be2fb01f | 468 | $reporters = ["" => ts(' - any reporter - ')]; |
85859f88 CW |
469 | foreach ($caseRelationships as $key => & $value) { |
470 | $reporters[$value['cid']] = $value['name'] . " ( {$value['relation']} )"; | |
471 | } | |
be2fb01f | 472 | $form->add('select', 'reporter_id', ts('Reporter/Role'), $reporters, FALSE, ['id' => 'reporter_id_' . $form->_caseID]); |
85859f88 CW |
473 | |
474 | // take all case activity types for search filter, CRM-7187 | |
be2fb01f | 475 | $aTypesFilter = []; |
85859f88 CW |
476 | $allCaseActTypes = CRM_Case_PseudoConstant::caseActivityType(); |
477 | foreach ($allCaseActTypes as $typeDetails) { | |
be2fb01f | 478 | if (!in_array($typeDetails['name'], ['Open Case'])) { |
9c1bc317 | 479 | $aTypesFilter[$typeDetails['id']] = $typeDetails['label'] ?? NULL; |
85859f88 CW |
480 | } |
481 | } | |
504f0f9c | 482 | $aTypesFilter = $aTypesFilter + $aTypes; |
85859f88 | 483 | asort($aTypesFilter); |
be2fb01f | 484 | $form->add('select', 'activity_type_filter_id', ts('Activity Type'), ['' => ts('- select activity type -')] + $aTypesFilter, FALSE, ['id' => 'activity_type_filter_id_' . $form->_caseID]); |
85859f88 CW |
485 | |
486 | $activityStatus = CRM_Core_PseudoConstant::activityStatus(); | |
be2fb01f | 487 | $form->add('select', 'status_id', ts('Status'), ["" => ts(' - any status - ')] + $activityStatus, FALSE, ['id' => 'status_id_' . $form->_caseID]); |
85859f88 | 488 | |
ab9eca19 CW |
489 | // activity date search filters |
490 | $form->add('datepicker', 'activity_date_low_' . $form->_caseID, ts('Activity Dates - From'), [], FALSE, ['time' => FALSE]); | |
491 | $form->add('datepicker', 'activity_date_high_' . $form->_caseID, ts('To'), [], FALSE, ['time' => FALSE]); | |
85859f88 CW |
492 | |
493 | if (CRM_Core_Permission::check('administer CiviCRM')) { | |
be2fb01f | 494 | $form->add('checkbox', 'activity_deleted', ts('Deleted Activities'), '', FALSE, ['id' => 'activity_deleted_' . $form->_caseID]); |
85859f88 CW |
495 | } |
496 | } | |
96025800 | 497 | |
0a1a8b63 CW |
498 | /** |
499 | * Form elements for merging cases | |
500 | */ | |
501 | public function buildMergeCaseForm() { | |
be2fb01f CW |
502 | $otherCases = []; |
503 | $result = civicrm_api3('Case', 'get', [ | |
0a1a8b63 CW |
504 | 'check_permissions' => TRUE, |
505 | 'contact_id' => $this->_contactID, | |
506 | 'is_deleted' => 0, | |
4e110487 | 507 | 'option.limit' => 0, |
be2fb01f CW |
508 | 'id' => ['!=' => $this->_caseID], |
509 | 'return' => ['id', 'start_date', 'case_type_id.title'], | |
510 | ]); | |
0a1a8b63 | 511 | foreach ($result['values'] as $id => $case) { |
be2fb01f | 512 | $otherCases[$id] = "#$id: {$case['case_type_id.title']} " . ts('(opened %1)', [1 => $case['start_date']]); |
0a1a8b63 CW |
513 | } |
514 | ||
515 | $this->assign('mergeCases', $this->_mergeCases = (bool) $otherCases); | |
516 | ||
517 | if ($otherCases) { | |
518 | $this->add('select', 'merge_case_id', | |
519 | ts('Select Case for Merge'), | |
be2fb01f | 520 | [ |
0a1a8b63 | 521 | '' => ts('- select case -'), |
be2fb01f | 522 | ] + $otherCases, |
0a1a8b63 | 523 | FALSE, |
be2fb01f | 524 | ['class' => 'crm-select2 huge'] |
0a1a8b63 | 525 | ); |
f0050a47 | 526 | // This button is hidden but gets clicked by javascript at |
527 | // https://github.com/civicrm/civicrm-core/blob/bd28ecf8121a85bc069cad3ab912a0c3dff8fdc5/templates/CRM/Case/Form/CaseView.js#L55 | |
528 | // when the mergeCasesDialog is saved. | |
cbd83dde | 529 | $this->addElement('xbutton', |
0a1a8b63 CW |
530 | $this->getButtonName('next', 'merge_case'), |
531 | ts('Merge'), | |
be2fb01f | 532 | [ |
0a1a8b63 | 533 | 'class' => 'hiddenElement', |
cbd83dde | 534 | 'type' => 'submit', |
be2fb01f | 535 | ] |
0a1a8b63 CW |
536 | ); |
537 | } | |
538 | } | |
539 | ||
ed92d614 | 540 | } |