From 66ad82d6506d72583106dcdaa6c5c0f684612aac Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Thu, 8 Feb 2018 19:40:44 +0530 Subject: [PATCH] CRM-21754: Duplicate rows in Activity Details report when address fields are displayed --- CRM/Report/Form.php | 83 ++++++++++++++---------------------- CRM/Report/Form/Activity.php | 7 +-- 2 files changed, 36 insertions(+), 54 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 6b83d4ff0d..7615c3dfbd 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -4166,70 +4166,51 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a /** * Do AlterDisplay processing on Address Fields. + * If there are multiple address field values then + * on basis of provided separator the code values are translated into respective labels * * @param array $row * @param array $rows * @param int $rowNum * @param string $baseUrl * @param string $linkText + * @param string $separator * * @return bool */ - public function alterDisplayAddressFields(&$row, &$rows, &$rowNum, $baseUrl, $linkText) { + public function alterDisplayAddressFields(&$row, &$rows, &$rowNum, $baseUrl, $linkText, $separator = ',') { $criteriaQueryParams = CRM_Report_Utils_Report::getPreviewCriteriaQueryParams($this->_defaults, $this->_params); $entryFound = FALSE; - // handle country - if (array_key_exists('civicrm_address_country_id', $row)) { - if ($value = $row['civicrm_address_country_id']) { - $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant::country($value, FALSE); - if ($baseUrl) { - $url = CRM_Report_Utils_Report::getNextUrl($baseUrl, - "reset=1&force=1&{$criteriaQueryParams}&" . - "country_id_op=in&country_id_value={$value}", - $this->_absoluteUrl, $this->_id - ); - $rows[$rowNum]['civicrm_address_country_id_link'] = $url; - $rows[$rowNum]['civicrm_address_country_id_hover'] = ts("%1 for this country.", - array(1 => $linkText) - ); - } - } - - $entryFound = TRUE; - } - if (array_key_exists('civicrm_address_county_id', $row)) { - if ($value = $row['civicrm_address_county_id']) { - $rows[$rowNum]['civicrm_address_county_id'] = CRM_Core_PseudoConstant::county($value, FALSE); - if ($baseUrl) { - $url = CRM_Report_Utils_Report::getNextUrl($baseUrl, - "reset=1&force=1&{$criteriaQueryParams}&" . - "county_id_op=in&county_id_value={$value}", - $this->_absoluteUrl, $this->_id - ); - $rows[$rowNum]['civicrm_address_county_id_link'] = $url; - $rows[$rowNum]['civicrm_address_county_id_hover'] = ts("%1 for this county.", - array(1 => $linkText) - ); - } - } - $entryFound = TRUE; - } - // handle state province - if (array_key_exists('civicrm_address_state_province_id', $row)) { - if ($value = $row['civicrm_address_state_province_id']) { - $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant::stateProvince($value, FALSE); - if ($baseUrl) { - $url = CRM_Report_Utils_Report::getNextUrl($baseUrl, - "reset=1&force=1&{$criteriaQueryParams}&state_province_id_op=in&state_province_id_value={$value}", - $this->_absoluteUrl, $this->_id - ); - $rows[$rowNum]['civicrm_address_state_province_id_link'] = $url; - $rows[$rowNum]['civicrm_address_state_province_id_hover'] = ts("%1 for this state.", - array(1 => $linkText) - ); + $columnMap = array( + 'civicrm_address_country_id' => 'country', + 'civicrm_address_county_id' => 'county', + 'civicrm_address_state_province_id' => 'stateProvince', + ); + foreach ($columnMap as $fieldName => $fnName) { + if (array_key_exists($fieldName, $row)) { + if ($values = $row[$fieldName]) { + $values = (array) explode($separator, $values); + $rows[$rowNum][$fieldName] = []; + $addressField = $fnName == 'stateProvince' ? 'state' : $fnName; + foreach ($values as $value) { + $rows[$rowNum][$fieldName][] = CRM_Core_PseudoConstant::$fnName($value); + } + $rows[$rowNum][$fieldName] = implode($separator, $rows[$rowNum][$fieldName]); + if ($baseUrl) { + $url = CRM_Report_Utils_Report::getNextUrl($baseUrl, + sprintf("reset=1&force=1&%s&%s_op=in&%s_value=%s", + $criteriaQueryParams, + str_replace('civicrm_address_', '', $fieldName), + str_replace('civicrm_address_', '', $fieldName), + implode(',', $values) + ), $this->_absoluteUrl, $this->_id + ); + $rows[$rowNum]["{$fieldName}_link"] = $url; + $rows[$rowNum]["{$fieldName}_hover"] = ts("%1 for this %2.", array(1 => $linkText, 2 => $addressField)); + } + $entryFound = TRUE; } } - $entryFound = TRUE; } return $entryFound; diff --git a/CRM/Report/Form/Activity.php b/CRM/Report/Form/Activity.php index e024ba937e..e3d4d3b0db 100644 --- a/CRM/Report/Form/Activity.php +++ b/CRM/Report/Form/Activity.php @@ -468,9 +468,10 @@ class CRM_Report_Form_Activity extends CRM_Report_Form { strstr($clause, 'civicrm_email_contact_source_email') || strstr($clause, 'civicrm_email_contact_assignee_email') || strstr($clause, 'civicrm_email_contact_target_email') || - strstr($clause, 'civicrm_phone_contact_target_phone') + strstr($clause, 'civicrm_phone_contact_target_phone') || + strstr($clause, 'civicrm_address_') ) { - $this->_selectClauses[$key] = "GROUP_CONCAT($clause SEPARATOR ';') as $clause"; + $this->_selectClauses[$key] = "GROUP_CONCAT(DISTINCT $clause SEPARATOR ';') as $clause"; } } } @@ -1088,7 +1089,7 @@ GROUP BY civicrm_activity_id $having {$this->_orderBy}"; } } - $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'activity', 'List all activities for this ') ? TRUE : $entryFound; + $entryFound = $this->alterDisplayAddressFields($row, $rows, $rowNum, 'activity', 'List all activities for this', ';') ? TRUE : $entryFound; if (!$entryFound) { break; -- 2.25.1