diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index fb966a055006..ddf2190eed18 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -287,6 +287,7 @@ public static function exportComponents( if (!array_key_exists($column, $returnProperties)) { $returnProperties[$column] = 1; $column = $column == 'id' ? 'civicrm_primary_id' : $column; + $processor->setColumnAsCalculationOnly($column); $exportParams['merge_same_address']['temp_columns'][$column] = 1; } } @@ -319,6 +320,7 @@ public static function exportComponents( if (!array_key_exists($column, $returnProperties)) { $returnProperties[$column] = 1; $exportParams['postal_mailing_export']['temp_columns'][$column] = 1; + $processor->setColumnAsCalculationOnly($column); } } } @@ -493,12 +495,12 @@ public static function exportComponents( if (isset($exportParams['postal_mailing_export']['postal_mailing_export']) && $exportParams['postal_mailing_export']['postal_mailing_export'] == 1 ) { - self::postalMailingFormat($exportTempTable, $headerRows, $sqlColumns, $exportMode); + self::postalMailingFormat($exportTempTable, $sqlColumns, $exportMode); } // do merge same address and merge same household processing if ($mergeSameAddress) { - self::mergeSameAddress($exportTempTable, $headerRows, $sqlColumns, $exportParams); + self::mergeSameAddress($exportTempTable, $sqlColumns, $exportParams); } // merge the records if they have corresponding households @@ -726,11 +728,10 @@ public static function createTempTable($sqlColumns) { /** * @param string $tableName - * @param $headerRows * @param $sqlColumns * @param array $exportParams */ - public static function mergeSameAddress($tableName, &$headerRows, &$sqlColumns, $exportParams) { + public static function mergeSameAddress($tableName, &$sqlColumns, $exportParams) { // check if any records are present based on if they have used shared address feature, // and not based on if city / state .. matches. $sql = " @@ -827,7 +828,7 @@ public static function mergeSameAddress($tableName, &$headerRows, &$sqlColumns, $unsetKeys = array_keys($sqlColumns); foreach ($unsetKeys as $headerKey => $sqlColKey) { if (array_key_exists($sqlColKey, $exportParams['merge_same_address']['temp_columns'])) { - unset($sqlColumns[$sqlColKey], $headerRows[$headerKey]); + unset($sqlColumns[$sqlColKey]); } } } @@ -1132,11 +1133,10 @@ public static function writeCSVFromTable($exportTempTable, $headerRows, $sqlColu * Exclude contacts who are deceased, have "Do not mail" privacy setting, * or have no street address * @param $exportTempTable - * @param $headerRows * @param $sqlColumns * @param $exportParams */ - public static function postalMailingFormat($exportTempTable, &$headerRows, &$sqlColumns, $exportParams) { + public static function postalMailingFormat($exportTempTable, &$sqlColumns, $exportParams) { $whereClause = array(); if (array_key_exists('is_deceased', $sqlColumns)) { @@ -1179,7 +1179,7 @@ public static function postalMailingFormat($exportTempTable, &$headerRows, &$sql $unsetKeys = array_keys($sqlColumns); foreach ($unsetKeys as $headerKey => $sqlColKey) { if (array_key_exists($sqlColKey, $exportParams['postal_mailing_export']['temp_columns'])) { - unset($sqlColumns[$sqlColKey], $headerRows[$headerKey]); + unset($sqlColumns[$sqlColKey]); } } } diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 39de1b09f8bc..c87b8dc99a01 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -452,9 +452,18 @@ public function addOutputSpecification($key, $label, $relationshipType = NULL) { if ($relationshipType) { $labelPrefix = $this->getRelationshipTypes()[$relationshipType] . '-'; } - $this->outputSpecification[$key] = [ - 'header' => $labelPrefix . $label - ]; + $this->outputSpecification[$key]['header'] = $labelPrefix . $label; + } + + /** + * Mark a column as only required for calculations. + * + * Do not include the row with headers. + * + * @param string $column + */ + public function setColumnAsCalculationOnly($column) { + $this->outputSpecification[$column]['do_not_output_to_csv'] = TRUE; } /** @@ -463,7 +472,9 @@ public function addOutputSpecification($key, $label, $relationshipType = NULL) { public function getHeaderRows() { $headerRows = []; foreach ($this->outputSpecification as $key => $spec) { - $headerRows[] = $spec['header']; + if (empty($spec['do_not_output_to_csv'])) { + $headerRows[] = $spec['header']; + } } return $headerRows; }