Merge pull request #18114 from eileenmcnaughton/phone
[civicrm-core.git] / CRM / Case / Form / CaseView.php
CommitLineData
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 */
21class 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.
9d30c8d1 278 $this->addElement('submit', $this->getButtonName('next'), ' ', ['class' => 'hiddenElement']);
6a488035 279
0a1a8b63 280 $this->buildMergeCaseForm();
6a488035 281
fc7d8951 282 //call activity form
504f0f9c 283 self::activityForm($this, $aTypes);
6a488035
TO
284
285 //get case related relationships (Case Role)
286 $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID);
287
288 //save special label because we unset it in the loop
289 $managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId];
290
6a488035 291 foreach ($caseRelationships as $key => & $value) {
6a488035 292 if (!empty($managerRoleId)) {
41cf58d3 293 if (substr($managerRoleId, 0, -4) == $value['relation_type'] && substr($managerRoleId, -3) == $value['relationship_direction']) {
6a488035
TO
294 $value['relation'] = $managerLabel;
295 }
296 }
297
298 //calculate roles that don't have relationships
a7488080 299 if (!empty($caseRoles[$value['relation_type']])) {
6a488035
TO
300 unset($caseRoles[$value['relation_type']]);
301 }
302 }
303
6a488035
TO
304 $this->assign('caseRelationships', $caseRelationships);
305
306 //also add client as role. CRM-4438
307 $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID);
308
309 $this->assign('caseRoles', $caseRoles);
310
6a488035
TO
311 // Retrieve ALL client relationships
312 $relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID,
313 CRM_Contact_BAO_Relationship::CURRENT,
314 0, 0, 0, NULL, NULL, FALSE
315 );
316
317 // Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles
318 // so they don't show up twice.
be2fb01f 319 $clientRelationships = [];
6a488035
TO
320 foreach ($relClient as $r) {
321 if (!array_key_exists($r['id'], $caseRelationships)) {
322 $clientRelationships[] = $r;
323 }
324 }
325 $this->assign('clientRelationships', $clientRelationships);
326
327 // Now global contact list that appears on all cases.
be2fb01f 328 $globalGroupInfo = [];
d79c94d5 329 CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo);
6a488035
TO
330 $this->assign('globalGroupInfo', $globalGroupInfo);
331
3b1c37fe 332 // List relationship types for adding an arbitrary new role to the case
0004ae05
CW
333 $this->add('select',
334 'role_type',
335 ts('Relationship Type'),
be2fb01f 336 ['' => ts('- select type -')] + $allowedRelationshipTypes,
0004ae05 337 FALSE,
be2fb01f 338 ['class' => 'crm-select2 twenty', 'data-select-params' => '{"allowClear": false}']
0004ae05 339 );
6a488035
TO
340
341 $hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID);
342 if (is_array($hookCaseSummary)) {
343 $this->assign('hookCaseSummary', $hookCaseSummary);
344 }
345
b733747a 346 $allTags = CRM_Core_BAO_Tag::getColorTags('civicrm_case');
6a488035
TO
347
348 if (!empty($allTags)) {
b733747a 349 $this->add('select2', 'case_tag', ts('Tags'), $allTags, FALSE,
be2fb01f 350 ['id' => 'tags', 'multiple' => 'multiple']
6a488035
TO
351 );
352
353 $tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case');
354
6a488035 355 foreach ($tags as $tid) {
b733747a
CW
356 $tagInfo = CRM_Utils_Array::findInTree($tid, $allTags);
357 if ($tagInfo) {
358 $tags[$tid] = $tagInfo;
6fd5424b 359 }
360 else {
361 unset($tags[$tid]);
362 }
6a488035
TO
363 }
364
be2fb01f 365 $this->setDefaults(['case_tag' => implode(',', array_keys($tags))]);
b733747a
CW
366
367 $this->assign('tags', $tags);
6a488035
TO
368 $this->assign('showTags', TRUE);
369 }
370 else {
371 $this->assign('showTags', FALSE);
372 }
373
374 // build tagset widget
375
376 // see if we have any tagsets which can be assigned to cases
377 $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case');
be2fb01f 378 $tagSetTags = [];
6a488035 379 if ($parentNames) {
79564bd4 380 $this->assign('showTags', TRUE);
be2fb01f 381 $tagSetItems = civicrm_api3('entityTag', 'get', [
79564bd4
CW
382 'entity_id' => $this->_caseID,
383 'entity_table' => 'civicrm_case',
8eecc659 384 'tag_id.parent_id.is_tagset' => 1,
be2fb01f
CW
385 'options' => ['limit' => 0],
386 'return' => ["tag_id.parent_id", "tag_id.parent_id.name", "tag_id.name"],
387 ]);
8eecc659 388 foreach ($tagSetItems['values'] as $tag) {
be2fb01f
CW
389 $tagSetTags += [
390 $tag['tag_id.parent_id'] => [
8eecc659 391 'name' => $tag['tag_id.parent_id.name'],
be2fb01f
CW
392 'items' => [],
393 ],
394 ];
8eecc659 395 $tagSetTags[$tag['tag_id.parent_id']]['items'][] = $tag['tag_id.name'];
79564bd4 396 }
6a488035 397 }
8eecc659 398 $this->assign('tagSetTags', $tagSetTags);
95ef220a 399 CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE);
6a488035 400
be2fb01f 401 $this->addButtons([
5d4fcf54
TO
402 [
403 'type' => 'cancel',
404 'name' => ts('Done'),
405 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
406 'isDefault' => TRUE,
407 ],
408 ]);
6a488035
TO
409 }
410
411 /**
fe482240 412 * Process the form.
6a488035
TO
413 */
414 public function postProcess() {
415 $params = $this->controller->exportValues($this->_name);
416 $buttonName = $this->controller->getButtonName();
417
418 // user context
419 $url = CRM_Utils_System::url('civicrm/contact/view/case',
420 "reset=1&action=view&cid={$this->_contactID}&id={$this->_caseID}&show=1"
421 );
422 $session = CRM_Core_Session::singleton();
423 $session->pushUserContext($url);
424
8cc574cf 425 if (!empty($params['timeline_id']) && !empty($_POST['_qf_CaseView_next'])) {
be2fb01f 426 civicrm_api3('Case', 'addtimeline', [
ae76ce5e
CW
427 'case_id' => $this->_caseID,
428 'timeline' => $params['timeline_id'],
be2fb01f 429 ]);
ae76ce5e 430
353ffa53 431 $xmlProcessor = new CRM_Case_XMLProcessor_Process();
6a488035 432 $reports = $xmlProcessor->get($this->_caseType, 'ActivitySets');
6a488035 433 CRM_Core_Session::setStatus(ts('Activities from the %1 activity set have been added to this case.',
be2fb01f 434 [1 => $reports[$params['timeline_id']]]
6a488035
TO
435 ), ts('Done'), 'success');
436 }
437 elseif ($this->_mergeCases &&
438 $buttonName == '_qf_CaseView_next_merge_case'
439 ) {
440
441 $mainCaseId = $params['merge_case_id'];
442 $otherCaseId = $this->_caseID;
443
444 //merge two cases.
445 CRM_Case_BAO_Case::mergeCases($this->_contactID, $mainCaseId, NULL, $otherCaseId);
446
447 //redirect user to main case view.
448 $url = CRM_Utils_System::url('civicrm/contact/view/case',
449 "reset=1&action=view&cid={$this->_contactID}&id={$mainCaseId}&show=1"
450 );
451 $session = CRM_Core_Session::singleton();
452 $session->pushUserContext($url);
453 }
6a488035 454 }
85859f88
CW
455
456 /**
457 * Build the activity selector/datatable
458 * @param CRM_Core_Form $form
64bd5a0e
TO
459 * @param array $aTypes
460 * To include acivities related to current case id $form->_caseID.
85859f88 461 */
be2fb01f 462 public static function activityForm($form, $aTypes = []) {
85859f88
CW
463 $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($form->_contactID, $form->_caseID);
464 //build reporter select
be2fb01f 465 $reporters = ["" => ts(' - any reporter - ')];
85859f88
CW
466 foreach ($caseRelationships as $key => & $value) {
467 $reporters[$value['cid']] = $value['name'] . " ( {$value['relation']} )";
468 }
be2fb01f 469 $form->add('select', 'reporter_id', ts('Reporter/Role'), $reporters, FALSE, ['id' => 'reporter_id_' . $form->_caseID]);
85859f88
CW
470
471 // take all case activity types for search filter, CRM-7187
be2fb01f 472 $aTypesFilter = [];
85859f88
CW
473 $allCaseActTypes = CRM_Case_PseudoConstant::caseActivityType();
474 foreach ($allCaseActTypes as $typeDetails) {
be2fb01f 475 if (!in_array($typeDetails['name'], ['Open Case'])) {
9c1bc317 476 $aTypesFilter[$typeDetails['id']] = $typeDetails['label'] ?? NULL;
85859f88
CW
477 }
478 }
504f0f9c 479 $aTypesFilter = $aTypesFilter + $aTypes;
85859f88 480 asort($aTypesFilter);
be2fb01f 481 $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
482
483 $activityStatus = CRM_Core_PseudoConstant::activityStatus();
be2fb01f 484 $form->add('select', 'status_id', ts('Status'), ["" => ts(' - any status - ')] + $activityStatus, FALSE, ['id' => 'status_id_' . $form->_caseID]);
85859f88 485
ab9eca19
CW
486 // activity date search filters
487 $form->add('datepicker', 'activity_date_low_' . $form->_caseID, ts('Activity Dates - From'), [], FALSE, ['time' => FALSE]);
488 $form->add('datepicker', 'activity_date_high_' . $form->_caseID, ts('To'), [], FALSE, ['time' => FALSE]);
85859f88
CW
489
490 if (CRM_Core_Permission::check('administer CiviCRM')) {
be2fb01f 491 $form->add('checkbox', 'activity_deleted', ts('Deleted Activities'), '', FALSE, ['id' => 'activity_deleted_' . $form->_caseID]);
85859f88
CW
492 }
493 }
96025800 494
0a1a8b63
CW
495 /**
496 * Form elements for merging cases
497 */
498 public function buildMergeCaseForm() {
be2fb01f
CW
499 $otherCases = [];
500 $result = civicrm_api3('Case', 'get', [
0a1a8b63
CW
501 'check_permissions' => TRUE,
502 'contact_id' => $this->_contactID,
503 'is_deleted' => 0,
4e110487 504 'option.limit' => 0,
be2fb01f
CW
505 'id' => ['!=' => $this->_caseID],
506 'return' => ['id', 'start_date', 'case_type_id.title'],
507 ]);
0a1a8b63 508 foreach ($result['values'] as $id => $case) {
be2fb01f 509 $otherCases[$id] = "#$id: {$case['case_type_id.title']} " . ts('(opened %1)', [1 => $case['start_date']]);
0a1a8b63
CW
510 }
511
512 $this->assign('mergeCases', $this->_mergeCases = (bool) $otherCases);
513
514 if ($otherCases) {
515 $this->add('select', 'merge_case_id',
516 ts('Select Case for Merge'),
be2fb01f 517 [
0a1a8b63 518 '' => ts('- select case -'),
be2fb01f 519 ] + $otherCases,
0a1a8b63 520 FALSE,
be2fb01f 521 ['class' => 'crm-select2 huge']
0a1a8b63 522 );
f0050a47 523 // This button is hidden but gets clicked by javascript at
524 // https://github.com/civicrm/civicrm-core/blob/bd28ecf8121a85bc069cad3ab912a0c3dff8fdc5/templates/CRM/Case/Form/CaseView.js#L55
525 // when the mergeCasesDialog is saved.
9d30c8d1 526 $this->addElement('submit',
0a1a8b63
CW
527 $this->getButtonName('next', 'merge_case'),
528 ts('Merge'),
be2fb01f 529 [
0a1a8b63 530 'class' => 'hiddenElement',
be2fb01f 531 ]
0a1a8b63
CW
532 );
533 }
534 }
535
ed92d614 536}