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