REF - Switch CRM_Utils_Array::value to empty in conditionals
[civicrm-core.git] / CRM / Report / Form / Case / Detail.php
CommitLineData
6a488035 1<?php
6a488035
TO
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 * $Id$
17 *
18 */
19class CRM_Report_Form_Case_Detail extends CRM_Report_Form {
20
21 protected $_relField = FALSE;
22
6d81d64a 23 protected $_addressField = TRUE;
6a488035
TO
24
25 protected $_activityLast = FALSE;
26
27 protected $_activityLastCompleted = FALSE;
28
29 protected $_includeCaseDetailExtra = FALSE;
30
f519cbaa 31 protected $_caseDetailExtra = [];
430ae6dd 32
f519cbaa 33 protected $_customGroupExtends = ['Case'];
b326c682 34
5e851416
BS
35 protected $_caseTypeNameOrderBy = FALSE;
36
74cf4551 37 /**
74cf4551 38 */
00be9182 39 public function __construct() {
01bf13dc 40 $this->case_statuses = CRM_Core_OptionGroup::values('case_status');
9d72cede
EM
41 $this->case_types = CRM_Case_PseudoConstant::caseType();
42 $rels = CRM_Core_PseudoConstant::relationshipType();
6a488035
TO
43 foreach ($rels as $relid => $v) {
44 $this->rel_types[$relid] = $v['label_b_a'];
45 }
46
f519cbaa 47 $this->caseActivityTypes = [];
6a488035
TO
48 foreach (CRM_Case_PseudoConstant::caseActivityType() as $typeDetail) {
49 $this->caseActivityTypes[$typeDetail['id']] = $typeDetail['label'];
50 }
51
f519cbaa 52 $this->_columns = [
53 'civicrm_case' => [
6a488035 54 'dao' => 'CRM_Case_DAO_Case',
f519cbaa 55 'fields' => [
56 'id' => [
9d72cede 57 'title' => ts('Case ID'),
6a488035
TO
58 'no_display' => TRUE,
59 'required' => TRUE,
f519cbaa 60 ],
61 'subject' => [
9d72cede 62 'title' => ts('Subject'),
6a488035 63 'required' => TRUE,
f519cbaa 64 ],
65 'start_date' => [
9d72cede 66 'title' => ts('Start Date'),
6a488035 67 'type' => CRM_Utils_Type::T_DATE,
f519cbaa 68 ],
69 'end_date' => [
9d72cede 70 'title' => ts('End Date'),
6a488035 71 'type' => CRM_Utils_Type::T_DATE,
f519cbaa 72 ],
73 'status_id' => ['title' => ts('Case Status')],
74 'case_type_id' => ['title' => ts('Case Type')],
75 'is_deleted' => [
9d72cede 76 'title' => ts('Deleted?'),
a31b650c 77 'default' => FALSE,
58f5d9da 78 'type' => CRM_Utils_Type::T_BOOLEAN,
f519cbaa 79 ],
80 ],
81 'filters' => [
82 'start_date' => [
9d72cede 83 'title' => ts('Start Date'),
6a488035
TO
84 'operatorType' => CRM_Report_Form::OP_DATE,
85 'type' => CRM_Utils_Type::T_DATE,
f519cbaa 86 ],
87 'end_date' => [
9d72cede 88 'title' => ts('End Date'),
6a488035
TO
89 'operatorType' => CRM_Report_Form::OP_DATE,
90 'type' => CRM_Utils_Type::T_DATE,
f519cbaa 91 ],
92 'status_id' => [
9d72cede 93 'title' => ts('Case Status'),
09b5cdcf 94 'type' => CRM_Utils_Type::T_INT,
6a488035 95 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
7a5c0c6c 96 'options' => CRM_Case_BAO_Case::buildOptions('status_id', 'search'),
f519cbaa 97 ],
98 'case_type_id' => [
9d72cede 99 'title' => ts('Case Type'),
09b5cdcf 100 'type' => CRM_Utils_Type::T_INT,
6a488035 101 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
7a5c0c6c 102 'options' => CRM_Case_BAO_Case::buildOptions('case_type_id', 'search'),
f519cbaa 103 ],
104 'is_deleted' => [
9d72cede 105 'title' => ts('Deleted?'),
58f5d9da 106 'type' => CRM_Utils_Type::T_BOOLEAN,
a31b650c 107 'default' => 0,
f519cbaa 108 ],
109 ],
110 'order_bys' => [
111 'start_date' => [
5e851416
BS
112 'title' => ts('Start Date'),
113 'default_weight' => 1,
f519cbaa 114 ],
115 'end_date' => [
5e851416 116 'title' => ts('End Date'),
f519cbaa 117 ],
118 'status_id' => [
5e851416 119 'title' => ts('Status'),
f519cbaa 120 ],
f519cbaa 121 ],
122 ],
0f880d50 123 'civicrm_case_type' => [
124 'dao' => 'CRM_Case_DAO_Case',
125 'order_bys' => [
126 'case_type_title' => [
127 'title' => 'Case Type',
128 'name' => 'title',
c86d4e7c
SL
129 ],
130 ],
0f880d50 131 ],
f519cbaa 132 'civicrm_contact' => [
6a488035 133 'dao' => 'CRM_Contact_DAO_Contact',
f519cbaa 134 'fields' => [
135 'client_sort_name' => [
6a488035
TO
136 'name' => 'sort_name',
137 'title' => ts('Client Name'),
138 'required' => TRUE,
f519cbaa 139 ],
140 'id' => [
6a488035
TO
141 'no_display' => TRUE,
142 'required' => TRUE,
f519cbaa 143 ],
144 ],
145 'filters' => [
146 'sort_name' => ['title' => ts('Client Name')],
147 ],
148 ],
149 'civicrm_relationship' => [
6a488035 150 'dao' => 'CRM_Contact_DAO_Relationship',
f519cbaa 151 'fields' => [
152 'case_role' => [
9d72cede 153 'name' => 'relationship_type_id',
6a488035 154 'title' => ts('Case Role(s)'),
f519cbaa 155 ],
156 ],
157 'filters' => [
158 'case_role' => [
6a488035
TO
159 'name' => 'relationship_type_id',
160 'title' => ts('Case Role(s)'),
09b5cdcf 161 'type' => CRM_Utils_Type::T_INT,
6a488035
TO
162 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
163 'options' => $this->rel_types,
f519cbaa 164 ],
165 'is_active' => [
742749c5
AP
166 'title' => ts('Active Role?'),
167 'type' => CRM_Utils_Type::T_BOOLEAN,
f519cbaa 168 ],
169 ],
170 ],
171 'civicrm_email' => [
6a488035 172 'dao' => 'CRM_Core_DAO_Email',
f519cbaa 173 'fields' => [
174 'email' => [
9d72cede 175 'title' => ts('Email'),
6a488035 176 'no_repeat' => TRUE,
f519cbaa 177 ],
178 ],
6a488035 179 'grouping' => 'contact-fields',
f519cbaa 180 ],
181 'civicrm_phone' => [
6a488035 182 'dao' => 'CRM_Core_DAO_Phone',
f519cbaa 183 'fields' => [
184 'phone' => [
9d72cede 185 'title' => ts('Phone'),
6a488035 186 'no_repeat' => TRUE,
f519cbaa 187 ],
188 ],
6a488035 189 'grouping' => 'contact-fields',
f519cbaa 190 ],
191 'civicrm_address' => [
6a488035 192 'dao' => 'CRM_Core_DAO_Address',
f519cbaa 193 'fields' => [
6a488035 194 'street_address' => NULL,
f519cbaa 195 'state_province_id' => [
9d72cede 196 'title' => ts('State/Province'),
f519cbaa 197 ],
198 'country_id' => ['title' => ts('Country')],
199 ],
6a488035 200 'grouping' => 'contact-fields',
f519cbaa 201 'filters' => [
202 'country_id' => [
9d72cede 203 'title' => ts('Country'),
6a488035
TO
204 'type' => CRM_Utils_Type::T_INT,
205 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
206 'options' => CRM_Core_PseudoConstant::country(),
f519cbaa 207 ],
208 'state_province_id' => [
9d72cede 209 'title' => ts('State/Province'),
6a488035
TO
210 'type' => CRM_Utils_Type::T_INT,
211 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
212 'options' => CRM_Core_PseudoConstant::stateProvince(),
f519cbaa 213 ],
214 ],
215 ],
216 'civicrm_worldregion' => [
6a488035 217 'dao' => 'CRM_Core_DAO_Worldregion',
f519cbaa 218 'filters' => [
219 'worldregion_id' => [
6a488035 220 'name' => 'id',
f418f381 221 'title' => ts('World Region'),
6a488035
TO
222 'type' => CRM_Utils_Type::T_INT,
223 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
224 'options' => CRM_Core_PseudoConstant::worldRegion(),
f519cbaa 225 ],
226 ],
227 ],
228 'civicrm_country' => [
6a488035 229 'dao' => 'CRM_Core_DAO_Country',
f519cbaa 230 ],
231 'civicrm_activity_last' => [
6a488035 232 'dao' => 'CRM_Activity_DAO_Activity',
f519cbaa 233 'fields' => [
234 'last_activity_activity_subject' => [
34463fa9
DH
235 'name' => 'subject',
236 'title' => ts('Subject of the last activity in the case'),
f519cbaa 237 ],
238 'last_activity_activity_type' => [
34463fa9
DH
239 'name' => 'activity_type_id',
240 'title' => ts('Activity type of the last activity'),
f519cbaa 241 ],
242 'last_activity_date_time' => [
34463fa9
DH
243 'name' => 'activity_date_time',
244 'title' => ts('Last Action Date'),
245 'operatorType' => CRM_Report_Form::OP_DATE,
f519cbaa 246 ],
247 ],
248 'filters' => [
249 'last_activity_date_time' => [
6a488035
TO
250 'name' => 'activity_date_time',
251 'title' => ts('Last Action Date'),
252 'operatorType' => CRM_Report_Form::OP_DATE,
f519cbaa 253 ],
254 ],
6a488035 255 'alias' => 'civireport_activity_last',
f519cbaa 256 ],
257 'civicrm_activity_last_completed' => [
6a488035 258 'dao' => 'CRM_Activity_DAO_Activity',
f519cbaa 259 'fields' => [
260 'last_completed_activity_subject' => [
6a488035
TO
261 'name' => 'subject',
262 'title' => ts('Subject of the last completed activity in the case'),
f519cbaa 263 ],
264 'last_completed_activity_type' => [
6a488035
TO
265 'name' => 'activity_type_id',
266 'title' => ts('Activity type of the last completed activity'),
f519cbaa 267 ],
268 'last_completed_date_time' => [
34463fa9
DH
269 'name' => 'activity_date_time',
270 'title' => ts('Last Completed Action Date'),
271 'operatorType' => CRM_Report_Form::OP_DATE,
f519cbaa 272 ],
273 ],
274 'filters' => [
275 'last_completed_date_time' => [
34463fa9
DH
276 'name' => 'activity_date_time',
277 'title' => ts('Last Completed Action Date'),
278 'operatorType' => CRM_Report_Form::OP_DATE,
f519cbaa 279 ],
280 ],
281 ],
282 ];
6a488035 283
f519cbaa 284 $this->_options = [
285 'my_cases' => [
9d72cede 286 'title' => ts('My Cases'),
6a488035 287 'type' => 'checkbox',
f519cbaa 288 ],
289 ];
6a488035
TO
290 parent::__construct();
291 }
292
00be9182 293 public function preProcess() {
6a488035
TO
294 parent::preProcess();
295 }
296
00be9182 297 public function buildQuickForm() {
6a488035
TO
298 parent::buildQuickForm();
299 $this->caseDetailSpecialColumnsAdd();
300 }
301
00be9182 302 public function caseDetailSpecialColumnsAdd() {
f519cbaa 303 $elements = [];
6a488035 304 $elements[] = &$this->createElement('select', 'case_activity_all_dates', NULL,
f519cbaa 305 [
21dfd5f5 306 '' => ts('- select -'),
f519cbaa 307 ] + $this->caseActivityTypes
6a488035
TO
308 );
309 $this->addGroup($elements, 'case_detail_extra');
310
f519cbaa 311 $this->_caseDetailExtra = [
312 'case_activity_all_dates' => [
9d72cede 313 'title' => ts('List of all dates of activities of Type'),
6a488035 314 'name' => 'activity_date_time',
f519cbaa 315 ],
316 ];
6a488035
TO
317
318 $this->assign('caseDetailExtra', $this->_caseDetailExtra);
319 }
320
00be9182 321 public function select() {
0f880d50 322 // @todo - get rid of this function & use parent. Use selectWhere to setthe clause for the
323 // few fields that need custom handling.
f519cbaa 324 $select = [];
325 $this->_columnHeaders = [];
6a488035
TO
326 foreach ($this->_columns as $tableName => $table) {
327 if (array_key_exists('fields', $table)) {
328 foreach ($table['fields'] as $fieldName => $field) {
9d72cede
EM
329 if (!empty($field['required']) ||
330 !empty($this->_params['fields'][$fieldName])
331 ) {
6d81d64a 332 if ($tableName == 'civicrm_relationship') {
6a488035
TO
333 $this->_relField = TRUE;
334 }
335 if ($fieldName == 'sort_name') {
2f4c2f5d 336 $select[] = "GROUP_CONCAT({$field['dbAlias']} ORDER BY {$field['dbAlias']} )
6a488035
TO
337 as {$tableName}_{$fieldName}";
338 }
34463fa9
DH
339 if ($tableName == 'civicrm_activity_last') {
340 $this->_activityLast = TRUE;
341 }
6a488035
TO
342 if ($tableName == 'civicrm_activity_last_completed') {
343 $this->_activityLastCompleted = TRUE;
344 }
345
346 if ($fieldName == 'case_role') {
347 $select[] = "GROUP_CONCAT(DISTINCT({$field['dbAlias']}) ORDER BY {$field['dbAlias']}) as {$tableName}_{$fieldName}";
348 }
349 else {
350 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
351 }
352
9c1bc317 353 $this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = $field['type'] ?? NULL;
6a488035
TO
354 $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];
355 }
356 }
357 }
358 }
5e851416 359
d1641c51 360 $this->_selectClauses = $select;
6a488035
TO
361
362 $this->_select = 'SELECT ' . implode(', ', $select) . ' ';
363 }
364
00be9182 365 public function from() {
6a488035
TO
366
367 $case = $this->_aliases['civicrm_case'];
368 $conact = $this->_aliases['civicrm_contact'];
369
370 $this->_from = "
371 FROM civicrm_case $case
372 LEFT JOIN civicrm_case_contact civireport_case_contact on civireport_case_contact.case_id = {$case}.id
373 LEFT JOIN civicrm_contact $conact ON {$conact}.id = civireport_case_contact.contact_id
374 ";
375 if ($this->_relField) {
376 $this->_from .= "
377 LEFT JOIN civicrm_relationship {$this->_aliases['civicrm_relationship']} ON {$this->_aliases['civicrm_relationship']}.case_id = {$case}.id
378";
379 }
380
6d81d64a 381 $this->joinAddressFromContact();
382 $this->joinPhoneFromContact();
383 $this->joinEmailFromContact();
384
385 if ($this->isTableSelected('civicrm_worldregion')) {
6a488035
TO
386 $this->_from .= "
387 LEFT JOIN civicrm_country {$this->_aliases['civicrm_country']}
388 ON {$this->_aliases['civicrm_country']}.id ={$this->_aliases['civicrm_address']}.country_id
389 LEFT JOIN civicrm_worldregion {$this->_aliases['civicrm_worldregion']}
390 ON {$this->_aliases['civicrm_country']}.region_id = {$this->_aliases['civicrm_worldregion']}.id ";
391 }
392
393 // Include clause for last activity of the case
394 if ($this->_activityLast) {
395 $this->_from .= " LEFT JOIN civicrm_activity {$this->_aliases['civicrm_activity_last']} ON ( {$this->_aliases['civicrm_activity_last']}.id = ( SELECT max(activity_id) FROM civicrm_case_activity WHERE case_id = {$case}.id) )";
396 }
397
398 // Include clause for last completed activity of the case
399 if ($this->_activityLastCompleted) {
400 $this->_from .= " LEFT JOIN civicrm_activity {$this->_aliases['civicrm_activity_last_completed']} ON ( {$this->_aliases['civicrm_activity_last_completed']}.id = ( SELECT max(activity_id) FROM civicrm_case_activity cca, civicrm_activity ca WHERE ca.id = cca.activity_id AND cca.case_id = {$case}.id AND ca.status_id = 2 ) )";
401 }
5e851416 402
0f880d50 403 if ($this->isTableSelected('civicrm_case_type')) {
5e851416 404 $this->_from .= "
0f880d50 405 LEFT JOIN civicrm_case_type {$this->_aliases['civicrm_case_type']}
406 ON {$this->_aliases['civicrm_case']}.case_type_id = {$this->_aliases['civicrm_case_type']}.id
5e851416
BS
407 ";
408 }
6a488035
TO
409 }
410
00be9182 411 public function where() {
f519cbaa 412 $clauses = [];
6a488035
TO
413 $this->_having = '';
414 foreach ($this->_columns as $tableName => $table) {
415 if (array_key_exists('filters', $table)) {
416 foreach ($table['filters'] as $fieldName => $field) {
417 $clause = NULL;
418
419 if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
9c1bc317
CW
420 $relative = $this->_params["{$fieldName}_relative"] ?? NULL;
421 $from = $this->_params["{$fieldName}_from"] ?? NULL;
422 $to = $this->_params["{$fieldName}_to"] ?? NULL;
6a488035
TO
423
424 $clause = $this->dateClause($field['dbAlias'], $relative, $from, $to, $field['type']);
425 }
426 else {
427
9c1bc317 428 $op = $this->_params["{$fieldName}_op"] ?? NULL;
9d72cede
EM
429 if ($fieldName == 'case_type_id' &&
430 !empty($this->_params['case_type_id_value'])
431 ) {
6a488035 432 foreach ($this->_params['case_type_id_value'] as $key => $value) {
6d491668 433 $this->_params['case_type_id_value'][$key] = $value;
6a488035
TO
434 }
435 }
436
437 if ($op) {
438 $clause = $this->whereClause($field,
439 $op,
440 CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
441 CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
442 CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
443 );
444 }
445 }
446
447 if (!empty($clause)) {
448 $clauses[] = $clause;
449 }
450 }
451 }
452 }
453
454 if (isset($this->_params['options']['my_cases'])) {
9d72cede
EM
455 $session = CRM_Core_Session::singleton();
456 $userID = $session->get('userID');
6a488035
TO
457 $clauses[] = "{$this->_aliases['civicrm_contact']}.id = {$userID}";
458 }
459
460 if (empty($clauses)) {
461 $this->_where = 'WHERE ( 1 ) ';
462 }
463 else {
464 $this->_where = 'WHERE ' . implode(' AND ', $clauses);
465 }
466 }
467
00be9182 468 public function groupBy() {
b708c08d 469 $this->_groupBy = CRM_Contact_BAO_Query::getGroupByFromSelectColumns($this->_selectClauses, "{$this->_aliases['civicrm_case']}.id");
6a488035
TO
470 }
471
74cf4551
EM
472 /**
473 * @param $rows
474 *
475 * @return array
476 */
00be9182 477 public function statistics(&$rows) {
6a488035
TO
478 $statistics = parent::statistics($rows);
479
9d72cede
EM
480 $select = "select COUNT( DISTINCT( {$this->_aliases['civicrm_address']}.country_id))";
481 $sql = "{$select} {$this->_from} {$this->_where}";
6a488035
TO
482 $countryCount = CRM_Core_DAO::singleValueQuery($sql);
483
f519cbaa 484 $statistics['counts']['case'] = [
6a488035
TO
485 'title' => ts('Total Number of Cases '),
486 'value' => isset($statistics['counts']['rowsFound']) ? $statistics['counts']['rowsFound']['value'] : count($rows),
f519cbaa 487 ];
488 $statistics['counts']['country'] = [
6a488035
TO
489 'title' => ts('Total Number of Countries '),
490 'value' => $countryCount,
f519cbaa 491 ];
6a488035
TO
492
493 return $statistics;
494 }
495
00be9182 496 public function caseDetailSpecialColumnProcess() {
6a488035
TO
497 if (!$this->_includeCaseDetailExtra) {
498 return;
499 }
500
f519cbaa 501 $from = $select = [];
6a488035
TO
502 $case = $this->_aliases['civicrm_case'];
503
504 if ($activityType = CRM_Utils_Array::value('case_activity_all_dates', $this->_params['case_detail_extra'])) {
505 $select[] = "GROUP_CONCAT(DISTINCT(civireport_activity_all_{$activityType}.{$this->_caseDetailExtra['case_activity_all_dates']['name']}) ORDER BY civireport_activity_all_{$activityType}.{$this->_caseDetailExtra['case_activity_all_dates']['name']}) as case_activity_all_dates";
506
2f4c2f5d 507 $from[] = " LEFT JOIN civicrm_case_activity civireport_case_activity_all_{$activityType} ON ( civireport_case_activity_all_{$activityType}.case_id = {$case}.id)
6a488035
TO
508 LEFT JOIN civicrm_activity civireport_activity_all_{$activityType} ON ( civireport_activity_all_{$activityType}.id = civireport_case_activity_all_{$activityType}.activity_id AND civireport_activity_all_{$activityType}.activity_type_id = {$activityType})";
509
f519cbaa 510 $this->_columnHeaders['case_activity_all_dates'] = [
795492f3 511 'title' => $this->_caseDetailExtra['case_activity_all_dates']['title'] . ": {$this->caseActivityTypes[$activityType]}",
6b409353 512 'type' => $this->_caseDetailExtra['case_activity_all_dates']['type'] ?? NULL,
f519cbaa 513 ];
6a488035
TO
514 }
515
516 $this->_select .= ', ' . implode(', ', $select) . ' ';
517 $this->_from .= ' ' . implode(' ', $from) . ' ';
518 }
519
00be9182 520 public function postProcess() {
6a488035
TO
521
522 $this->beginPostProcess();
523
524 $this->checkEnabledFields();
525
526 $this->buildQuery(TRUE);
527
528 $this->caseDetailSpecialColumnProcess();
529
530 $sql = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy} {$this->_limit}";
531
f519cbaa 532 $rows = $graphRows = [];
6a488035
TO
533 $this->buildRows($sql, $rows);
534
535 $this->formatDisplay($rows);
536
537 $this->doTemplateAssignment($rows);
538 $this->endPostProcess($rows);
539 }
540
00be9182 541 public function checkEnabledFields() {
742749c5
AP
542 if ((isset($this->_params['case_role_value'])
543 && !empty($this->_params['case_role_value'])) ||
f519cbaa 544 (isset($this->_params['is_active_value']))
6a488035
TO
545 ) {
546 $this->_relField = TRUE;
547 }
548
34463fa9
DH
549 if (!empty($this->_params['last_completed_date_time_relative']) ||
550 !empty($this->_params['last_completed_date_time_from']) ||
b99f3e96 551 !empty($this->_params['last_completed_date_time_to'])
34463fa9
DH
552 ) {
553 $this->_activityLastCompleted = TRUE;
554 }
555
d578c527
DH
556 if (!empty($this->_params['last_activity_date_time_relative']) ||
557 !empty($this->_params['last_activity_date_time_from']) ||
b99f3e96 558 !empty($this->_params['last_activity_date_time_to'])
6a488035
TO
559 ) {
560 $this->_activityLast = TRUE;
561 }
562
563 foreach (array_keys($this->_caseDetailExtra) as $field) {
a7488080 564 if (!empty($this->_params['case_detail_extra'][$field])) {
6a488035
TO
565 $this->_includeCaseDetailExtra = TRUE;
566 break;
567 }
568 }
569 }
570
74cf4551 571 /**
4b62bc4f
EM
572 * Alter display of rows.
573 *
574 * Iterate through the rows retrieved via SQL and make changes for display purposes,
575 * such as rendering contacts as links.
576 *
577 * @param array $rows
578 * Rows generated by SQL, with an array for each row.
74cf4551 579 */
00be9182 580 public function alterDisplay(&$rows) {
6a488035
TO
581 $entryFound = FALSE;
582 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE);
583
584 foreach ($rows as $rowNum => $row) {
585 if (array_key_exists('civicrm_case_status_id', $row)) {
586 if ($value = $row['civicrm_case_status_id']) {
587 $rows[$rowNum]['civicrm_case_status_id'] = $this->case_statuses[$value];
588
589 $entryFound = TRUE;
590 }
591 }
592 if (array_key_exists('civicrm_case_case_type_id', $row)) {
593 if ($value = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, '', $row['civicrm_case_case_type_id'])) {
594 $rows[$rowNum]['civicrm_case_case_type_id'] = $this->case_types[$value];
595
596 $entryFound = TRUE;
597 }
598 }
599 if (array_key_exists('civicrm_case_subject', $row)) {
600 if ($value = $row['civicrm_case_subject']) {
76bec9f7
CW
601 $url = CRM_Utils_System::url("civicrm/case/ajax/details",
602 "caseId={$row['civicrm_case_id']}&contactId={$row['civicrm_contact_id']}",
603 $this->_absoluteUrl
604 );
605 $rows[$rowNum]['civicrm_case_subject'] = "<a class=\"crm-popup\" href=\"$url\">$value</a>";
6a488035
TO
606 $rows[$rowNum]['civicrm_case_subject_hover'] = ts('View Details of Case.');
607
608 $entryFound = TRUE;
609 }
610 }
611 if (array_key_exists('civicrm_relationship_case_role', $row)) {
612 if ($value = $row['civicrm_relationship_case_role']) {
613 $caseRoles = explode(',', $value);
614 foreach ($caseRoles as $num => $caseRole) {
615 $caseRoles[$num] = $this->rel_types[$caseRole];
616 }
617 $rows[$rowNum]['civicrm_relationship_case_role'] = implode('; ', $caseRoles);
618 }
619 $entryFound = TRUE;
620 }
34463fa9
DH
621 if (array_key_exists('civicrm_activity_last_last_activity_activity_subject', $row) &&
622 empty($row['civicrm_activity_last_last_activity_activity_subject'])
623 ) {
624 $rows[$rowNum]['civicrm_activity_last_last_activity_activity_subject'] = ts('(no subject)');
625 $entryFound = TRUE;
626 }
9d72cede
EM
627 if (array_key_exists('civicrm_activity_last_completed_last_completed_activity_subject', $row) &&
628 empty($row['civicrm_activity_last_completed_last_completed_activity_subject'])
629 ) {
2f186e81 630 $rows[$rowNum]['civicrm_activity_last_completed_last_completed_activity_subject'] = ts('(no subject)');
6a488035
TO
631 $entryFound = TRUE;
632 }
633 if (array_key_exists('civicrm_contact_client_sort_name', $row) &&
634 array_key_exists('civicrm_contact_id', $row)
635 ) {
636 $url = CRM_Utils_System::url("civicrm/contact/view",
637 'reset=1&cid=' . $row['civicrm_contact_id'],
638 $this->_absoluteUrl
639 );
640 $rows[$rowNum]['civicrm_contact_client_sort_name_link'] = $url;
641 $rows[$rowNum]['civicrm_contact_client_sort_name_hover'] = ts("View Contact Summary for this Contact");
642 $entryFound = TRUE;
643 }
34463fa9
DH
644 if (array_key_exists('civicrm_activity_last_last_activity_activity_type', $row)) {
645 if ($value = $row['civicrm_activity_last_last_activity_activity_type']) {
646 $rows[$rowNum]['civicrm_activity_last_last_activity_activity_type'] = $activityTypes[$value];
647 }
648 $entryFound = TRUE;
649 }
6a488035
TO
650 if (array_key_exists('civicrm_activity_last_completed_last_completed_activity_type', $row)) {
651 if ($value = $row['civicrm_activity_last_completed_last_completed_activity_type']) {
652 $rows[$rowNum]['civicrm_activity_last_completed_last_completed_activity_type'] = $activityTypes[$value];
653 }
654 $entryFound = TRUE;
655 }
656
657 if (array_key_exists('case_activity_all_dates', $row)) {
658 if ($value = $row['case_activity_all_dates']) {
659 $activityDates = explode(',', $value);
660 foreach ($activityDates as $num => $activityDate) {
661 $activityDates[$num] = CRM_Utils_Date::customFormat($activityDate);
662 }
663 $rows[$rowNum]['case_activity_all_dates'] = implode('; ', $activityDates);
664 }
665 $entryFound = TRUE;
666 }
667
e3665bb8 668 $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, NULL, NULL) ? TRUE : $entryFound;
6a488035
TO
669 if (!$entryFound) {
670 break;
671 }
672 }
673 }
96025800 674
6a488035 675}