3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 class CRM_Report_Form_ActivitySummary
extends CRM_Report_Form
{
37 protected $_emailField = FALSE;
38 protected $_phoneField = FALSE;
39 protected $_tempTableName;
40 protected $_tempDurationSumTableName;
46 public function __construct() {
47 $this->_columns
= array(
48 'civicrm_contact' => array(
49 'dao' => 'CRM_Contact_DAO_Contact',
56 'title' => ts('Contact Name'),
62 'title' => ts('Contact Name'),
68 'title' => ts('Contact'),
73 'title' => ts('Contact Name'),
76 'grouping' => 'contact-fields',
78 'civicrm_email' => array(
79 'dao' => 'CRM_Core_DAO_Email',
87 'title' => ts('Email'),
90 'grouping' => 'contact-fields',
92 'civicrm_phone' => array(
93 'dao' => 'CRM_Core_DAO_Email',
99 'grouping' => 'contact-fields',
101 'civicrm_activity' => array(
102 'dao' => 'CRM_Activity_DAO_Activity',
104 'activity_type_id' => array(
105 'title' => ts('Activity Type'),
107 'type' => CRM_Utils_Type
::T_STRING
,
109 'status_id' => array(
110 'title' => ts('Activity Status'),
112 'type' => CRM_Utils_Type
::T_STRING
,
115 'title' => ts('Duration'),
119 'title' => ts('Total Activities'),
121 'statistics' => array(
122 'count' => ts('Count'),
127 'activity_date_time' => array(
128 'operatorType' => CRM_Report_Form
::OP_DATE
,
130 'activity_type_id' => array(
131 'title' => ts('Activity Type'),
133 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
134 'options' => CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'label', TRUE),
136 'status_id' => array(
137 'title' => ts('Activity Status'),
138 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
139 'options' => CRM_Core_PseudoConstant
::activityStatus(),
141 'priority_id' => array(
142 'title' => ts('Priority'),
143 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
144 'options' => CRM_Core_PseudoConstant
::get('CRM_Activity_DAO_Activity', 'priority_id'),
147 'group_bys' => array(
148 'activity_date_time' => array(
149 'title' => ts('Activity Date'),
152 'activity_type_id' => array(
153 'title' => ts('Activity Type'),
156 'status_id' => array(
157 'title' => ts('Activity Status'),
161 'order_bys' => array(
162 'activity_date_time' => array(
163 'title' => ts('Activity Date'),
165 'activity_type_id' => array(
166 'title' => ts('Activity Type'),
169 'grouping' => 'activity-fields',
170 'alias' => 'activity',
173 $this->_groupFilter
= TRUE;
175 parent
::__construct();
178 public function select() {
180 $this->_columnHeaders
= array();
181 foreach ($this->_columns
as $tableName => $table) {
182 if (array_key_exists('group_bys', $table)) {
183 foreach ($table['group_bys'] as $fieldName => $field) {
184 if (!empty($this->_params
['group_bys'][$fieldName])) {
185 //include column in report when selected in group by but not in column section.
186 if (empty($this->_params
['fields'][$fieldName])) {
187 $this->_params
['fields'][$fieldName] = TRUE;
189 if (isset($this->_params
['group_bys_freq']) && !empty($this->_params
['group_bys_freq'][$fieldName])) {
190 switch ($this->_params
['group_bys_freq'][$fieldName]) {
192 $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL WEEKDAY({$field['dbAlias']}) DAY) AS {$tableName}_{$fieldName}_start";
194 $select[] = "YEARWEEK({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
195 $select[] = "WEEKOFYEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
196 $field['title'] = 'Week';
200 $select[] = "MAKEDATE(YEAR({$field['dbAlias']}), 1) AS {$tableName}_{$fieldName}_start";
201 $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
202 $select[] = "YEAR({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
203 $field['title'] = 'Year';
207 $select[] = "DATE_SUB({$field['dbAlias']}, INTERVAL (DAYOFMONTH({$field['dbAlias']})-1) DAY) as {$tableName}_{$fieldName}_start";
208 $select[] = "MONTH({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
209 $select[] = "MONTHNAME({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
210 $field['title'] = 'Month';
214 $select[] = "STR_TO_DATE(CONCAT( 3 * QUARTER( {$field['dbAlias']} ) -2 , '/', '1', '/', YEAR( {$field['dbAlias']} ) ), '%m/%d/%Y') AS {$tableName}_{$fieldName}_start";
215 $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_subtotal";
216 $select[] = "QUARTER({$field['dbAlias']}) AS {$tableName}_{$fieldName}_interval";
217 $field['title'] = 'Quarter';
220 $this->_interval
= $field['title'];
221 $this->_columnHeaders
["{$tableName}_{$fieldName}_start"]['title'] = $field['title'] . ' Beginning';
222 $this->_columnHeaders
["{$tableName}_{$fieldName}_start"]['type'] = $field['type'];
223 $this->_columnHeaders
["{$tableName}_{$fieldName}_start"]['group_by'] = $this->_params
['group_bys_freq'][$fieldName];
225 // just to make sure these values are transferred to rows.
226 // since we need that for calculation purpose,
227 // e.g making subtotals look nicer or graphs
228 $this->_columnHeaders
["{$tableName}_{$fieldName}_interval"] = array('no_display' => TRUE);
229 $this->_columnHeaders
["{$tableName}_{$fieldName}_subtotal"] = array('no_display' => TRUE);
234 if (array_key_exists('fields', $table)) {
235 foreach ($table['fields'] as $fieldName => $field) {
236 if (!empty($field['required']) ||
!empty($this->_params
['fields'][$fieldName])) {
237 if ($tableName == 'civicrm_email') {
238 $this->_emailField
= TRUE;
240 if ($tableName == 'civicrm_phone') {
241 $this->_phoneField
= TRUE;
243 if (!empty($field['statistics'])) {
244 foreach ($field['statistics'] as $stat => $label) {
245 switch (strtolower($stat)) {
247 $select[] = "COUNT(DISTINCT({$field['dbAlias']})) as {$tableName}_{$fieldName}_{$stat}";
248 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type
::T_INT
;
249 $this->_columnHeaders
["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
250 $this->_statFields
[] = "{$tableName}_{$fieldName}_{$stat}";
255 elseif ($fieldName == 'activity_type_id') {
256 if (empty($this->_params
['group_bys']['activity_type_id'])) {
257 $select[] = "GROUP_CONCAT(DISTINCT {$field['dbAlias']} ORDER BY {$field['dbAlias']} ) as {$tableName}_{$fieldName}";
260 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
262 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
263 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
264 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
267 $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
268 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array
::value('type', $field);
269 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array
::value('title', $field);
270 $this->_columnHeaders
["{$tableName}_{$fieldName}"]['no_display'] = CRM_Utils_Array
::value('no_display', $field);
277 $this->_select
= "SELECT " . implode(', ', $select) . " ";
281 * Generate from clause.
283 * @param bool|FALSE $durationMode
285 public function from($durationMode = FALSE) {
286 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
287 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
288 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
289 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
291 if (!$durationMode) {
293 FROM civicrm_activity {$this->_aliases['civicrm_activity']}
295 LEFT JOIN civicrm_activity_contact target_activity
296 ON {$this->_aliases['civicrm_activity']}.id = target_activity.activity_id AND
297 target_activity.record_type_id = {$targetID}
298 LEFT JOIN civicrm_activity_contact assignment_activity
299 ON {$this->_aliases['civicrm_activity']}.id = assignment_activity.activity_id AND
300 assignment_activity.record_type_id = {$assigneeID}
301 LEFT JOIN civicrm_activity_contact source_activity
302 ON {$this->_aliases['civicrm_activity']}.id = source_activity.activity_id AND
303 source_activity.record_type_id = {$sourceID}
304 LEFT JOIN civicrm_contact contact_civireport
305 ON target_activity.contact_id = contact_civireport.id
306 LEFT JOIN civicrm_contact civicrm_contact_assignee
307 ON assignment_activity.contact_id = civicrm_contact_assignee.id
308 LEFT JOIN civicrm_contact civicrm_contact_source
309 ON source_activity.contact_id = civicrm_contact_source.id
311 LEFT JOIN civicrm_option_value
312 ON ( {$this->_aliases['civicrm_activity']}.activity_type_id = civicrm_option_value.value )
313 LEFT JOIN civicrm_option_group
314 ON civicrm_option_group.id = civicrm_option_value.option_group_id
315 LEFT JOIN civicrm_case_activity
316 ON civicrm_case_activity.activity_id = {$this->_aliases['civicrm_activity']}.id
317 LEFT JOIN civicrm_case
318 ON civicrm_case_activity.case_id = civicrm_case.id
319 LEFT JOIN civicrm_case_contact
320 ON civicrm_case_contact.case_id = civicrm_case.id ";
322 if ($this->_emailField
) {
324 LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']}
325 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
326 {$this->_aliases['civicrm_email']}.is_primary = 1 ";
329 if ($this->_phoneField
) {
331 LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']}
332 ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND
333 {$this->_aliases['civicrm_phone']}.is_primary = 1 ";
338 FROM civicrm_activity {$this->_aliases['civicrm_activity']} {$this->_aclFrom} ";
343 * Generate where clause.
345 * @param bool|FALSE $durationMode
347 public function where($durationMode = FALSE) {
348 $optionGroupClause = '';
349 if (!$durationMode) {
350 $optionGroupClause = 'civicrm_option_group.name = "activity_type" AND ';
352 $this->_where
= " WHERE {$optionGroupClause}
353 {$this->_aliases['civicrm_activity']}.is_test = 0 AND
354 {$this->_aliases['civicrm_activity']}.is_deleted = 0 AND
355 {$this->_aliases['civicrm_activity']}.is_current_revision = 1";
358 foreach ($this->_columns
as $tableName => $table) {
359 if (array_key_exists('filters', $table)) {
361 foreach ($table['filters'] as $fieldName => $field) {
363 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
364 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
365 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
366 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
368 $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
371 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
373 $clause = $this->whereClause($field,
375 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
376 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
377 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
382 if (!empty($clause)) {
383 $clauses[] = $clause;
389 if (empty($clauses)) {
390 $this->_where
.= " ";
393 $this->_where
.= " AND " . implode(' AND ', $clauses);
396 if ($this->_aclWhere
&& !$durationMode) {
397 $this->_where
.= " AND ({$this->_aclWhere} OR civicrm_contact_source.is_deleted=0 OR civicrm_contact_assignee.is_deleted=0)";
401 public function groupBy() {
402 $this->_groupBy
= array();
403 if (!empty($this->_params
['group_bys']) &&
404 is_array($this->_params
['group_bys'])) {
405 foreach ($this->_columns
as $tableName => $table) {
406 if (array_key_exists('group_bys', $table)) {
407 foreach ($table['group_bys'] as $fieldName => $field) {
408 if (!empty($this->_params
['group_bys'][$fieldName])) {
409 if (!empty($field['chart'])) {
410 $this->assign('chartSupported', TRUE);
412 if (!empty($table['group_bys'][$fieldName]['frequency']) &&
413 !empty($this->_params
['group_bys_freq'][$fieldName])
416 $append = "YEAR({$field['dbAlias']}),";
417 if (in_array(strtolower($this->_params
['group_bys_freq'][$fieldName]),
422 $this->_groupBy
[] = "$append {$this->_params['group_bys_freq'][$fieldName]}({$field['dbAlias']})";
426 $this->_groupBy
[] = $field['dbAlias'];
433 $this->_groupBy
= "GROUP BY " . implode(', ', $this->_groupBy
);
436 $this->_groupBy
= "GROUP BY {$this->_aliases['civicrm_activity']}.id ";
447 public static function formRule($fields, $files, $self) {
449 $contactFields = array('sort_name', 'email', 'phone');
450 if (!empty($fields['group_bys'])) {
451 if (!empty($fields['group_bys']['activity_date_time'])) {
452 if (!empty($fields['group_bys']['sort_name'])) {
453 $errors['fields'] = ts("Please do not select GroupBy 'Activity Date' with GroupBy 'Contact'");
456 foreach ($fields['fields'] as $fieldName => $val) {
457 if (in_array($fieldName, $contactFields)) {
458 $errors['fields'] = ts("Please do not select any Contact Fields with GroupBy 'Activity Date'");
466 // don't allow add to group action unless contact fields are selected.
467 if (isset($fields['_qf_ActivitySummary_submit_group'])) {
468 $contactFieldSelected = FALSE;
469 foreach ($fields['fields'] as $fieldName => $val) {
470 if (in_array($fieldName, $contactFields)) {
471 $contactFieldSelected = TRUE;
476 if (!$contactFieldSelected) {
477 $errors['fields'] = ts('You cannot use "Add Contacts to Group" action unless contacts fields are selected.');
483 public function postProcess() {
484 // get the acl clauses built before we assemble the query
485 $this->buildACLClause($this->_aliases
['civicrm_contact']);
487 // get ready with post process params
488 $this->beginPostProcess();
491 $sql = $this->buildQuery();
493 // main sql statement
496 $this->customDataFrom();
501 // order_by columns not selected for display need to be included in SELECT
502 $unselectedSectionColumns = $this->unselectedSectionColumns();
503 foreach ($unselectedSectionColumns as $alias => $section) {
504 $this->_select
.= ", {$section['dbAlias']} as {$alias}";
507 if (!empty($applyLimit) && empty($this->_params
['charts'])) {
510 CRM_Utils_Hook
::alterReportVar('sql', $this, $this);
512 // store the duration count in temp table
513 $this->_tempTableName
= CRM_Core_DAO
::createTempTableName('civicrm_activity');
515 // build temporary table column names base on column headers of result
516 $dbColumns = array();
517 foreach ($this->_columnHeaders
as $fieldName => $dontCare) {
518 $dbColumns[] = $fieldName . ' VARCHAR(128)';
521 // create temp table to store main result
522 $tempQuery = "CREATE TEMPORARY TABLE {$this->_tempTableName} (
523 id int unsigned NOT NULL AUTO_INCREMENT, " . implode(', ', $dbColumns) . ' , PRIMARY KEY (id))';
524 CRM_Core_DAO
::executeQuery($tempQuery);
526 // build main report query
527 $sql = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy} {$this->_limit}";
529 // store the result in temporary table
531 $insertQuery = "INSERT INTO {$this->_tempTableName} ( " . implode(',', array_keys($this->_columnHeaders
)) . " )
533 CRM_Core_DAO
::executeQuery($insertQuery);
535 // now build the query for duration sum
539 // build the query to calulate duration sum
540 $sql = "SELECT SUM(activity_civireport.duration) as civicrm_activity_duration_total {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy} {$this->_limit}";
542 // create temp table to store duration
543 $this->_tempDurationSumTableName
= CRM_Core_DAO
::createTempTableName('civicrm_activity');
544 $tempQuery = "CREATE TEMPORARY TABLE {$this->_tempDurationSumTableName} (
545 id int unsigned NOT NULL AUTO_INCREMENT, civicrm_activity_duration_total VARCHAR(128), PRIMARY KEY (id))";
546 CRM_Core_DAO
::executeQuery($tempQuery);
548 // store the result in temporary table
549 $insertQuery = "INSERT INTO {$this->_tempDurationSumTableName} (civicrm_activity_duration_total)
551 CRM_Core_DAO
::executeQuery($insertQuery);
553 // build array of result based on column headers. This method also allows
554 // modifying column headers before using it to build result set i.e $rows.
556 $query = "SELECT {$this->_tempTableName}.*, {$this->_tempDurationSumTableName}.civicrm_activity_duration_total
557 FROM {$this->_tempTableName} INNER JOIN {$this->_tempDurationSumTableName}
558 ON ({$this->_tempTableName}.id = {$this->_tempDurationSumTableName}.id)";
560 // finally add duration total to column headers
561 $this->_columnHeaders
['civicrm_activity_duration_total'] = array('no_display' => 1);
563 $this->buildRows($query, $rows);
565 // format result set.
566 $this->formatDisplay($rows);
568 // assign variables to templates
569 $this->doTemplateAssignment($rows);
571 //reset the sql building to default, which is used / called during other actions like "add to group"
572 // now build the query for duration sum
576 // do print / pdf / instance stuff if needed
577 $this->endPostProcess($rows);
585 public function statistics(&$rows) {
586 $statistics = parent
::statistics($rows);
587 $totalType = $totalActivity = $totalDuration = 0;
589 $query = "SELECT {$this->_tempTableName}.civicrm_activity_activity_type_id,
590 {$this->_tempTableName}.civicrm_activity_id_count,
591 {$this->_tempDurationSumTableName}.civicrm_activity_duration_total
592 FROM {$this->_tempTableName} INNER JOIN {$this->_tempDurationSumTableName}
593 ON ({$this->_tempTableName}.id = {$this->_tempDurationSumTableName}.id)";
595 $actDAO = CRM_Core_DAO
::executeQuery($query);
597 $activityTypesCount = array();
598 while ($actDAO->fetch()) {
599 if (!in_array($actDAO->civicrm_activity_activity_type_id
, $activityTypesCount)) {
600 $activityTypesCount[] = $actDAO->civicrm_activity_activity_type_id
;
603 $totalActivity +
= $actDAO->civicrm_activity_id_count
;
604 $totalDuration +
= $actDAO->civicrm_activity_duration_total
;
607 $totalType = count($activityTypesCount);
609 $statistics['counts']['type'] = array(
610 'title' => ts('Total Types'),
611 'value' => $totalType,
613 $statistics['counts']['activities'] = array(
614 'title' => ts('Total Number of Activities'),
615 'value' => $totalActivity,
617 $statistics['counts']['duration'] = array(
618 'title' => ts('Total Duration (in Minutes)'),
619 'value' => $totalDuration,
624 public function modifyColumnHeaders() {
625 //CRM-16719 modify name of column
626 if (!empty($this->_columnHeaders
['civicrm_activity_status_id'])) {
627 $this->_columnHeaders
['civicrm_activity_status_id']['title'] = "Status";
632 * Alter display of rows.
634 * Iterate through the rows retrieved via SQL and make changes for display purposes,
635 * such as rendering contacts as links.
638 * Rows generated by SQL, with an array for each row.
640 public function alterDisplay(&$rows) {
642 $activityType = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
643 $activityStatus = CRM_Core_PseudoConstant
::activityStatus();
645 $onHover = ts('View Contact Summary for this Contact');
646 foreach ($rows as $rowNum => $row) {
647 // make count columns point to activity detail report
648 if (!empty($row['civicrm_activity_id_count'])) {
650 $urlParams = array('activity_type_id', 'gid', 'status_id', 'contact_id');
651 foreach ($urlParams as $field) {
652 if (!empty($row['civicrm_activity_' . $field])) {
653 $url[] = "{$field}_op=in&{$field}_value={$row['civicrm_activity_'.$field]}";
655 elseif (!empty($this->_params
[$field . '_value'])) {
656 $val = implode(",", $this->_params
[$field . '_value']);
657 $url[] = "{$field}_op=in&{$field}_value={$val}";
660 $date_suffixes = array('relative', 'from', 'to');
661 while (list(, $suffix) = each($date_suffixes)) {
662 if (!empty($this->_params
['activity_date_time_' . $suffix])) {
665 CRM_Utils_Array
::value("activity_date_time_relative", $this->_params
),
666 CRM_Utils_Array
::value("activity_date_time_from", $this->_params
),
667 CRM_Utils_Array
::value("activity_date_time_to", $this->_params
)
669 $url[] = "activity_date_time_from={$from}&activity_date_time_to={$to}";
673 $url = implode('&', $url);
674 $url = CRM_Report_Utils_Report
::getNextUrl('activity', "reset=1&force=1&{$url}",
677 $this->_drilldownReport
);
678 $rows[$rowNum]['civicrm_activity_id_count_link'] = $url;
679 $rows[$rowNum]['civicrm_activity_id_count_hover'] = ts('List all activity(s) for this row.');
683 if (array_key_exists('civicrm_contact_sort_name', $row) && $this->_outputMode
!= 'csv') {
684 if ($value = $row['civicrm_contact_id']) {
687 $priviousContact = $value;
690 if ($priviousContact == $value) {
692 $priviousContact = $value;
696 $priviousContact = $value;
700 if ($flagContact == 1) {
701 $rows[$rowNum]['civicrm_contact_sort_name'] = "";
703 if (array_key_exists('civicrm_email_email', $row)) {
704 $rows[$rowNum]['civicrm_email_email'] = "";
706 if (array_key_exists('civicrm_phone_phone', $row)) {
707 $rows[$rowNum]['civicrm_phone_phone'] = "";
711 $url = CRM_Utils_System
::url('civicrm/contact/view',
712 'reset=1&cid=' . $value,
716 $rows[$rowNum]['civicrm_contact_sort_name'] = "<a href='$url'>" . $row['civicrm_contact_sort_name'] .
723 if (array_key_exists('civicrm_activity_activity_type_id', $row)) {
724 if ($value = $row['civicrm_activity_activity_type_id']) {
726 $value = explode(',', $value);
727 foreach ($value as $key => $id) {
728 $value[$key] = $activityType[$id];
731 $rows[$rowNum]['civicrm_activity_activity_type_id'] = implode(' , ', $value);
736 if (array_key_exists('civicrm_activity_status_id', $row)) {
737 if ($value = $row['civicrm_activity_status_id']) {
738 $rows[$rowNum]['civicrm_activity_status_id'] = $activityStatus[$value];
743 if (array_key_exists('civicrm_activity_duration', $row)) {
744 if ($value = $row['civicrm_activity_duration']) {
745 $rows[$rowNum]['civicrm_activity_duration'] = $rows[$rowNum]['civicrm_activity_duration_total'];