Skip to content

Commit

Permalink
Stop setting header rows only to unset them
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 20, 2018
1 parent 28254dc commit de6ff50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
16 changes: 8 additions & 8 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = "
Expand Down Expand Up @@ -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]);
}
}
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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]);
}
}
}
Expand Down
19 changes: 15 additions & 4 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}
Expand Down

0 comments on commit de6ff50

Please sign in to comment.