From af17bedfb0f508861e02228a6de06992efcca526 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 19 Nov 2018 12:56:47 +1300 Subject: [PATCH] Make getHeaderRows more sensible --- CRM/Export/BAO/Export.php | 36 ++---------------------------- CRM/Export/BAO/ExportProcessor.php | 27 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 7e5ce95302..93cbd23df3 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -1206,38 +1206,6 @@ WHERE {$whereClause}"; return $componentPaymentFields; } - /** - * Set the definition for the header rows and sql columns based on the field to output. - * - * @param string $field - * @param array $headerRows - * @param \CRM_Export_BAO_ExportProcessor $processor - * - * @return array - */ - public static function setHeaderRows($field, $headerRows, $processor) { - - $queryFields = $processor->getQueryFields(); - if (substr($field, -11) == 'campaign_id') { - // @todo - set this correctly in the xml rather than here. - $headerRows[] = ts('Campaign ID'); - } - elseif ($processor->isMergeSameHousehold() && $field === 'id') { - $headerRows[] = ts('Household ID'); - } - elseif (isset($queryFields[$field]['title'])) { - $headerRows[] = $queryFields[$field]['title']; - } - elseif ($processor->isExportPaymentFields() && array_key_exists($field, $processor->getcomponentPaymentFields())) { - $headerRows[] = CRM_Utils_Array::value($field, $processor->getcomponentPaymentFields()); - } - else { - $headerRows[] = $field; - } - - return $headerRows; - } - /** * Get the various arrays that we use to structure our output. * @@ -1274,7 +1242,7 @@ WHERE {$whereClause}"; foreach ($returnProperties as $key => $value) { if (($key != 'location' || !is_array($value)) && !$processor->isRelationshipTypeKey($key)) { $outputColumns[$key] = $value; - $headerRows = self::setHeaderRows($key, $headerRows, $processor); + $headerRows[] = $processor->getHeaderForRow($key); self::sqlColumnDefn($processor, $sqlColumns, $key); } elseif ($processor->isRelationshipTypeKey($key)) { @@ -1335,7 +1303,7 @@ WHERE {$whereClause}"; $metadata[$daoFieldName]['pseudoconstant']['var'] = 'imProviders'; } self::sqlColumnDefn($processor, $sqlColumns, $outputFieldName); - $headerRows = self::setHeaderRows($outputFieldName, $headerRows, $processor); + $headerRows[] = $processor->getHeaderForRow($outputFieldName); self::sqlColumnDefn($processor, $sqlColumns, $outputFieldName); if ($actualDBFieldName == 'country' || $actualDBFieldName == 'world_region') { $metadata[$daoFieldName] = array('context' => 'country'); diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 2a0225e504..0bfd27f456 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -389,6 +389,33 @@ class CRM_Export_BAO_ExportProcessor { } } + /** + * Get the label for the header row based on the field to output. + * + * @param string $field + * + * @return string + */ + public function getHeaderForRow($field) { + if (substr($field, -11) == 'campaign_id') { + // @todo - set this correctly in the xml rather than here. + // This will require a generalised handling cleanup + return ts('Campaign ID'); + } + if ($this->isMergeSameHousehold() && $field === 'id') { + return ts('Household ID'); + } + elseif (isset($this->getQueryFields()[$field]['title'])) { + return $this->getQueryFields()[$field]['title']; + } + elseif ($this->isExportPaymentFields() && array_key_exists($field, $this->getcomponentPaymentFields())) { + return CRM_Utils_Array::value($field, $this->getcomponentPaymentFields()); + } + else { + return $field; + } + } + /** * @param $params * @param $order -- 2.25.1