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