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