3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
33 class CRM_Report_Form_ActivitySummary
extends CRM_Report_Form
{
35 protected $_emailField = FALSE;
36 protected $_phoneField = FALSE;
37 protected $_tempTableName;
38 protected $_tempDurationSumTableName;
41 * This report has not been optimised for group filtering.
43 * The functionality for group filtering has been improved but not
44 * all reports have been adjusted to take care of it. This report has not
45 * and will run an inefficient query until fixed.
51 protected $groupFilterNotOptimised = TRUE;
56 public function __construct() {
58 'civicrm_contact' => [
59 'dao' => 'CRM_Contact_DAO_Contact',
66 'title' => ts('Contact Name'),
72 'title' => ts('Contact Name'),
78 'title' => ts('Contact'),
83 'title' => ts('Contact Name'),
86 'grouping' => 'contact-fields',
89 'dao' => 'CRM_Core_DAO_Email',
92 'title' => ts('Email'),
97 'title' => ts('Email'),
100 'grouping' => 'contact-fields',
103 'dao' => 'CRM_Core_DAO_Email',
106 'title' => ts('Phone'),
109 'grouping' => 'contact-fields',
111 'civicrm_activity' => [
112 'dao' => 'CRM_Activity_DAO_Activity',
114 'activity_type_id' => [
115 'title' => ts('Activity Type'),
117 'type' => CRM_Utils_Type
::T_STRING
,
120 'title' => ts('Activity Status'),
122 'type' => CRM_Utils_Type
::T_STRING
,
125 'title' => ts('Duration'),
129 'title' => ts('Priority'),
131 'type' => CRM_Utils_Type
::T_STRING
,
134 'title' => ts('Total Activities'),
137 'count' => ts('Count'),
142 'activity_date_time' => [
143 'operatorType' => CRM_Report_Form
::OP_DATE
,
145 'activity_type_id' => [
146 'title' => ts('Activity Type'),
148 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
149 'options' => CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'label', TRUE),
152 'title' => ts('Activity Status'),
153 'type' => CRM_Utils_Type
::T_STRING
,
154 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
155 'options' => CRM_Core_PseudoConstant
::activityStatus(),
158 'title' => ts('Activity Priority'),
159 'type' => CRM_Utils_Type
::T_INT
,
160 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
161 'options' => CRM_Core_PseudoConstant
::get('CRM_Activity_DAO_Activity', 'priority_id'),
165 'activity_date_time' => [
166 'title' => ts('Activity Date'),
169 'activity_type_id' => [
170 'title' => ts('Activity Type'),
174 'title' => ts('Activity Status'),
179 'activity_date_time' => [
180 'title' => ts('Activity Date'),
182 'activity_type_id' => [
183 'title' => ts('Activity Type'),
186 'grouping' => 'activity-fields',
187 'alias' => 'activity',
190 $this->_groupFilter
= TRUE;
192 parent
::__construct();
195 public function select() {
197 $this->_columnHeaders
= [];
198 foreach ($this->_columns
as $tableName => $table) {
199 if (array_key_exists('group_bys', $table)) {
200 foreach ($table['group_bys'] as $fieldName => $field) {
201 if (!empty($this->_params
['group_bys'][$fieldName])) {
202 //include column in report when selected in group by but not in column section.
203 if (empty($this->_params
['fields'][$fieldName])) {
204 $this->_params
['fields'][$fieldName] = TRUE;
206 if (isset($this->_params
['group_bys_freq']) && !empty($this->_params
['group_bys_freq'][$fieldName])) {
207 switch ($this->_params
['group_bys_freq'][$fieldName]) {
209 $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL WEEKDAY({$field['dbAlias']}) DAY) AS {$tableName}_{$fieldName}_start";
211 $select[] = "YEARWEEK({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
212 $select[] = "WEEKOFYEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
213 $field['title'] = 'Week';
217 $select[] = "MAKEDATE(YEAR({$field['dbAlias']}), 1) AS {$tableName}_{$fieldName}_start";
218 $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
219 $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
220 $field['title'] = 'Year';
224 $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL (DAYOFMONTH({$field['dbAlias']})-1) DAY) as {$tableName}_{$fieldName}_start";
225 $select[] = "MONTH({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
226 $select[] = "MONTHNAME({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
227 $field['title'] = 'Month';
231 $select[] = "STR_TO_DATE(CONCAT( 3 * QUARTER( {$field['dbAlias']} ) -2 , '/', '1', '/', YEAR( {$field['dbAlias']} ) ), '%m/%d/%Y') AS {$tableName}_{$fieldName}_start";
232 $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
233 $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
234 $field['title'] = 'Quarter';
237 $this->_interval
= $field['title'];
238 $this->_columnHeaders
["{$tableName}_{$fieldName}_start"]['title'] = $field['title'] . ' Beginning';
239 $this->_columnHeaders
["{$tableName}_{$fieldName}_start"]['type'] = $field['type'];
240 $this->_columnHeaders
["{$tableName}_{$fieldName}_start"]['group_by'] = $this->_params
['group_bys_freq'][$fieldName];
242 // just to make sure these values are transferred to rows.
243 // since we need that for calculation purpose,
244 // e.g making subtotals look nicer or graphs
245 $this->_columnHeaders
["{$tableName}_{$fieldName}_interval"] = ['no_display' => TRUE];
246 $this->_columnHeaders
["{$tableName}_{$fieldName}_subtotal"] = ['no_display' => TRUE];
251 if (array_key_exists('fields', $table)) {
252 foreach ($table['fields'] as $fieldName => $field) {
253 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
254 if ($tableName == 'civicrm_email' ||
in_array('email', CRM_Utils_Array
::collect('column', $this->_params
['order_bys']))) {
255 $this->_emailField
= TRUE;
257 if ($tableName == 'civicrm_phone') {
258 $this->_phoneField
= TRUE;
260 if (!empty($field['statistics'])) {
261 foreach ($field['statistics'] as $stat => $label) {
262 switch (strtolower($stat)) {
264 $select[] = "COUNT(DISTINCT({$field['dbAlias']})) as {$tableName}_{$fieldName}_{$stat}";
265 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_INT
;
266 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
267 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
272 elseif ($fieldName == 'activity_type_id') {
273 if (empty($this->_params
['group_bys']['activity_type_id'])) {
274 $select[] = "GROUP_CONCAT(DISTINCT {$field['dbAlias']} ORDER BY {$field['dbAlias']} ) as {$tableName}_{$fieldName}";
277 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
279 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
280 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
281 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
284 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
285 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
286 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
287 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
293 $this->_selectClauses
= $select;
295 $this->_select
= "SELECT " . implode(', ', $select) . " ";
299 * Generate from clause.
301 public function from() {
302 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
303 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
304 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
305 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
308 FROM civicrm_activity {$this->_aliases['civicrm_activity']}
310 LEFT JOIN civicrm_activity_contact target_activity
311 ON {$this->_aliases['civicrm_activity']}.id = target_activity.activity_id AND
312 target_activity.record_type_id = {$targetID}
313 LEFT JOIN civicrm_activity_contact assignment_activity
314 ON {$this->_aliases['civicrm_activity']}.id = assignment_activity.activity_id AND
315 assignment_activity.record_type_id = {$assigneeID}
316 LEFT JOIN civicrm_activity_contact source_activity
317 ON {$this->_aliases['civicrm_activity']}.id = source_activity.activity_id AND
318 source_activity.record_type_id = {$sourceID}
319 LEFT JOIN civicrm_contact contact_civireport
320 ON target_activity.contact_id = contact_civireport.id
321 LEFT JOIN civicrm_contact civicrm_contact_assignee
322 ON assignment_activity.contact_id = civicrm_contact_assignee.id
323 LEFT JOIN civicrm_contact civicrm_contact_source
324 ON source_activity.contact_id = civicrm_contact_source.id
326 LEFT JOIN civicrm_option_value
327 ON ( {$this->_aliases['civicrm_activity']}.activity_type_id = civicrm_option_value.value )
328 LEFT JOIN civicrm_option_group
329 ON civicrm_option_group.id = civicrm_option_value.option_group_id
330 LEFT JOIN civicrm_case_activity
331 ON civicrm_case_activity.activity_id = {$this->_aliases['civicrm_activity']}.id
332 LEFT JOIN civicrm_case
333 ON civicrm_case_activity.case_id = civicrm_case.id
334 LEFT JOIN civicrm_case_contact
335 ON civicrm_case_contact.case_id = civicrm_case.id ";
337 $this->joinPhoneFromContact();
339 $this->joinEmailFromContact();
343 * Generate from clause for when calculating activity durations.
345 public function activityDurationFrom() {
346 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
347 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
349 FROM civicrm_activity {$this->_aliases['civicrm_activity']}
350 LEFT JOIN civicrm_activity_contact target_activity
351 ON {$this->_aliases['civicrm_activity']}.id = target_activity.activity_id AND
352 target_activity.record_type_id = {$targetID}
353 LEFT JOIN civicrm_contact contact_civireport
354 ON target_activity.contact_id = contact_civireport.id
357 // Email table is needed if sorting by Email.
358 $this->joinEmailFromContact();
362 * Generate where clause.
364 * @param bool $durationMode
366 public function where($durationMode = FALSE) {
367 $optionGroupClause = '';
368 if (!$durationMode) {
369 $optionGroupClause = 'civicrm_option_group.name = "activity_type" AND ';
371 $this->_where
= " WHERE {$optionGroupClause}
372 {$this->_aliases['civicrm_activity']}.is_test = 0 AND
373 {$this->_aliases['civicrm_activity']}.is_deleted = 0 AND
374 {$this->_aliases['civicrm_activity']}.is_current_revision = 1";
377 foreach ($this->_columns
as $tableName => $table) {
378 if (array_key_exists('filters', $table)) {
380 foreach ($table['filters'] as $fieldName => $field) {
382 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
383 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
384 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
385 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
387 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
390 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
392 $clause = $this->whereClause($field,
394 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
395 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
396 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
401 if (!empty($clause)) {
402 $clauses[] = $clause;
408 if (empty($clauses)) {
409 $this->_where
.= " ";
412 $this->_where
.= " AND " . implode(' AND ', $clauses);
415 if ($this->_aclWhere
&& !$durationMode) {
416 $this->_where
.= " AND ({$this->_aclWhere} OR civicrm_contact_source.is_deleted=0 OR civicrm_contact_assignee.is_deleted=0)";
421 * Build the report query.
423 * @param bool $applyLimit
427 public function buildQuery($applyLimit = TRUE) {
428 $this->buildGroupTempTable();
431 $this->customDataFrom();
432 $this->buildPermissionClause();
437 // Order by & Section columns not selected for display need to be included in SELECT.
438 $unselectedColumns = array_merge($this->unselectedOrderByColumns(), $this->unselectedSectionColumns());
439 foreach ($unselectedColumns as $alias => $field) {
440 $clause = $this->getSelectClauseWithGroupConcatIfNotGroupedBy($field['table_name'], $field['name'], $field);
442 $clause = "{$field['dbAlias']} as {$alias}";
444 $this->_select
.= ", $clause ";
447 if ($applyLimit && empty($this->_params
['charts'])) {
450 CRM_Utils_Hook
::alterReportVar('sql', $this, $this);
452 // build temporary table column names base on column headers of result
454 foreach ($this->_columnHeaders
as $fieldName => $dontCare) {
455 $dbColumns[] = $fieldName . ' VARCHAR(128)';
458 // Order by & Section columns not selected for display need to be included in temp table.
459 foreach ($unselectedColumns as $alias => $section) {
460 $dbColumns[] = $alias . ' VARCHAR(128)';
463 // create temp table to store main result
464 $this->_tempTableName
= $this->createTemporaryTable('tempTable', "
465 id int unsigned NOT NULL AUTO_INCREMENT, " . implode(', ', $dbColumns) . ' , PRIMARY KEY (id)',
468 // build main report query
469 $sql = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy} {$this->_limit}";
470 $this->addToDeveloperTab($sql);
472 // store the result in temporary table
474 $insertQuery = "INSERT INTO {$this->_tempTableName} ( " . implode(',', array_merge(array_keys($this->_columnHeaders
), array_keys($unselectedColumns))) . " )
476 CRM_Core_DAO
::executeQuery($insertQuery);
478 // now build the query for duration sum
479 $this->activityDurationFrom();
481 $this->groupBy(FALSE);
483 // build the query to calulate duration sum
484 $sql = "SELECT SUM(activity_civireport.duration) as civicrm_activity_duration_total {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy} {$this->_limit}";
486 // create temp table to store duration
487 $this->_tempDurationSumTableName
= $this->createTemporaryTable('tempDurationSumTable', "
488 id int unsigned NOT NULL AUTO_INCREMENT, civicrm_activity_duration_total VARCHAR(128), PRIMARY KEY (id)",
491 // store the result in temporary table
492 $insertQuery = "INSERT INTO {$this->_tempDurationSumTableName} (civicrm_activity_duration_total)
494 CRM_Core_DAO
::disableFullGroupByMode();
495 CRM_Core_DAO
::executeQuery($insertQuery);
496 CRM_Core_DAO
::reenableFullGroupByMode();
498 $sql = "SELECT {$this->_tempTableName}.*, {$this->_tempDurationSumTableName}.civicrm_activity_duration_total
499 FROM {$this->_tempTableName} INNER JOIN {$this->_tempDurationSumTableName}
500 ON ({$this->_tempTableName}.id = {$this->_tempDurationSumTableName}.id)";
502 // finally add duration total to column headers
503 $this->_columnHeaders
['civicrm_activity_duration_total'] = ['no_display' => 1];
505 // reset the sql building to default, which is used / called during other actions like "add to group"
515 * @param bool $includeSelectCol
517 public function groupBy($includeSelectCol = TRUE) {
518 $this->_groupBy
= [];
519 if (!empty($this->_params
['group_bys']) &&
520 is_array($this->_params
['group_bys'])) {
521 foreach ($this->_columns
as $tableName => $table) {
522 if (array_key_exists('group_bys', $table)) {
523 foreach ($table['group_bys'] as $fieldName => $field) {
524 if (!empty($this->_params
['group_bys'][$fieldName])) {
525 if (!empty($field['chart'])) {
526 $this->assign('chartSupported', TRUE);
528 if (!empty($table['group_bys'][$fieldName]['frequency']) &&
529 !empty($this->_params
['group_bys_freq'][$fieldName])
532 $append = "YEAR({$field['dbAlias']}),";
533 if (in_array(strtolower($this->_params
['group_bys_freq'][$fieldName]),
538 $this->_groupBy
[] = "$append {$this->_params['group_bys_freq'][$fieldName]}({$field['dbAlias']})";
542 $this->_groupBy
[] = $field['dbAlias'];
548 $groupBy = $this->_groupBy
;
549 $this->_groupBy
= "GROUP BY " . implode(', ', $this->_groupBy
);
552 $groupBy = "{$this->_aliases['civicrm_activity']}.id";
553 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_activity']}.id ";
555 if ($includeSelectCol) {
556 $this->_groupBy
= CRM_Contact_BAO_Query
::getGroupByFromSelectColumns($this->_selectClauses
, $groupBy);
567 public static function formRule($fields, $files, $self) {
569 $contactFields = ['sort_name', 'email', 'phone'];
570 if (!empty($fields['group_bys'])) {
571 if (!empty($fields['group_bys']['activity_date_time'])) {
572 if (!empty($fields['group_bys']['sort_name'])) {
573 $errors['fields'] = ts("Please do not select GroupBy 'Activity Date' with GroupBy 'Contact'");
576 foreach ($fields['fields'] as $fieldName => $val) {
577 if (in_array($fieldName, $contactFields)) {
578 $errors['fields'] = ts("Please do not select any Contact Fields with GroupBy 'Activity Date'");
586 // don't allow add to group action unless contact fields are selected.
587 if (isset($fields['_qf_ActivitySummary_submit_group'])) {
588 $contactFieldSelected = FALSE;
589 foreach ($fields['fields'] as $fieldName => $val) {
590 if (in_array($fieldName, $contactFields)) {
591 $contactFieldSelected = TRUE;
596 if (!$contactFieldSelected) {
597 $errors['fields'] = ts('You cannot use "Add Contacts to Group" action unless contacts fields are selected.');
608 public function statistics(&$rows) {
609 $statistics = parent
::statistics($rows);
610 $totalType = $totalActivity = $totalDuration = 0;
612 $query = "SELECT {$this->_tempTableName}.civicrm_activity_activity_type_id,
613 {$this->_tempTableName}.civicrm_activity_id_count,
614 {$this->_tempDurationSumTableName}.civicrm_activity_duration_total
615 FROM {$this->_tempTableName} INNER JOIN {$this->_tempDurationSumTableName}
616 ON ({$this->_tempTableName}.id = {$this->_tempDurationSumTableName}.id)";
618 $actDAO = CRM_Core_DAO
::executeQuery($query);
620 $activityTypesCount = [];
621 while ($actDAO->fetch()) {
622 if (!in_array($actDAO->civicrm_activity_activity_type_id
, $activityTypesCount)) {
623 $activityTypesCount[] = $actDAO->civicrm_activity_activity_type_id
;
626 $totalActivity +
= $actDAO->civicrm_activity_id_count
;
627 $totalDuration +
= $actDAO->civicrm_activity_duration_total
;
630 $totalType = count($activityTypesCount);
632 $statistics['counts']['type'] = [
633 'title' => ts('Total Types'),
634 'value' => $totalType,
636 $statistics['counts']['activities'] = [
637 'title' => ts('Total Number of Activities'),
638 'value' => $totalActivity,
640 $statistics['counts']['duration'] = [
641 'title' => ts('Total Duration (in Minutes)'),
642 'value' => $totalDuration,
647 public function modifyColumnHeaders() {
648 //CRM-16719 modify name of column
649 if (!empty($this->_columnHeaders
['civicrm_activity_status_id'])) {
650 $this->_columnHeaders
['civicrm_activity_status_id']['title'] = ts('Status');
655 * Alter display of rows.
657 * Iterate through the rows retrieved via SQL and make changes for display purposes,
658 * such as rendering contacts as links.
661 * Rows generated by SQL, with an array for each row.
663 public function alterDisplay(&$rows) {
665 $activityType = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
666 $activityStatus = CRM_Core_PseudoConstant
::activityStatus();
667 $priority = CRM_Core_PseudoConstant
::get('CRM_Activity_DAO_Activity', 'priority_id');
668 $onHover = ts('View Contact Summary for this Contact');
669 foreach ($rows as $rowNum => $row) {
670 // make count columns point to activity detail report
671 if (!empty($row['civicrm_activity_id_count'])) {
673 $urlParams = ['activity_type_id', 'gid', 'status_id', 'contact_id'];
674 foreach ($urlParams as $field) {
675 if (!empty($row['civicrm_activity_' . $field])) {
676 $url[] = "{$field}_op=in&{$field}_value={$row['civicrm_activity_'.$field]}";
678 elseif (!empty($this->_params
[$field . '_value'])) {
679 $val = implode(",", $this->_params
[$field . '_value']);
680 $url[] = "{$field}_op=in&{$field}_value={$val}";
683 $date_suffixes = ['relative', 'from', 'to'];
684 foreach ($date_suffixes as $suffix) {
685 if (!empty($this->_params
['activity_date_time_' . $suffix])) {
688 CRM_Utils_Array
::value("activity_date_time_relative", $this->_params
),
689 CRM_Utils_Array
::value("activity_date_time_from", $this->_params
),
690 CRM_Utils_Array
::value("activity_date_time_to", $this->_params
)
692 $url[] = "activity_date_time_from={$from}&activity_date_time_to={$to}";
696 // reset date filter on activity reports.
697 $url[] = "resetDateFilter=1";
698 $url = implode('&', $url);
699 $url = CRM_Report_Utils_Report
::getNextUrl('activity', "reset=1&force=1&{$url}",
702 $this->_drilldownReport
);
703 $rows[$rowNum]['civicrm_activity_id_count_link'] = $url;
704 $rows[$rowNum]['civicrm_activity_id_count_hover'] = ts('List all activity(s) for this row.');
708 if (array_key_exists('civicrm_contact_sort_name', $row) && $this->_outputMode
!= 'csv') {
709 if ($value = $row['civicrm_contact_id']) {
711 // unset the name, email and phone fields if the contact is the same as the previous contact
712 if (isset($previousContact) && $previousContact == $value) {
713 $rows[$rowNum]['civicrm_contact_sort_name'] = "";
715 if (array_key_exists('civicrm_email_email', $row)) {
716 $rows[$rowNum]['civicrm_email_email'] = "";
718 if (array_key_exists('civicrm_phone_phone', $row)) {
719 $rows[$rowNum]['civicrm_phone_phone'] = "";
723 $url = CRM_Utils_System
::url('civicrm/contact/view',
724 'reset=1&cid=' . $value,
728 $rows[$rowNum]['civicrm_contact_sort_name'] = "<a href='$url'>" . $row['civicrm_contact_sort_name'] .
732 // store the contact ID of this contact
733 $previousContact = $value;
738 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
739 if ($value = $row['civicrm_activity_activity_type_id']) {
741 $value = explode(',', $value);
742 foreach ($value as $key => $id) {
743 $value[$key] = $activityType[$id];
746 $rows[$rowNum]['civicrm_activity_activity_type_id'] = implode(' , ', $value);
751 if (array_key_exists('civicrm_activity_status_id', $row)) {
752 if ($value = $row['civicrm_activity_status_id']) {
753 $rows[$rowNum]['civicrm_activity_status_id'] = $activityStatus[$value];
758 if (array_key_exists('civicrm_activity_priority_id', $row)) {
759 if ($value = $row['civicrm_activity_priority_id']) {
760 $rows[$rowNum]['civicrm_activity_priority_id'] = $priority[$value];
765 if (array_key_exists('civicrm_activity_duration', $row)) {
766 if ($value = $row['civicrm_activity_duration']) {
767 $rows[$rowNum]['civicrm_activity_duration'] = $rows[$rowNum]['civicrm_activity_duration_total'];