Skip to content

Commit

Permalink
Merge pull request #13122 from eileenmcnaughton/export_merge
Browse files Browse the repository at this point in the history
Export code cleanup - remove silly function
  • Loading branch information
eileenmcnaughton authored Nov 19, 2018
2 parents 0d18d79 + 5359d42 commit c167994
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 34 deletions.
38 changes: 4 additions & 34 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -1130,21 +1130,6 @@ public static function writeCSVFromTable($exportTempTable, $headerRows, $sqlColu
}
}

/**
* Manipulate header rows for relationship fields.
*
* @param $headerRows
*/
public static function manipulateHeaderRows(&$headerRows) {
foreach ($headerRows as & $header) {
$split = explode('-', $header);
if ($relationTypeName = CRM_Utils_Array::value($split[0], self::$relationshipTypes)) {
$split[0] = $relationTypeName;
$header = implode('-', $split);
}
}
}

/**
* Exclude contacts who are deceased, have "Do not mail" privacy setting,
* or have no street address
Expand Down Expand Up @@ -1301,24 +1286,11 @@ public static function getExportStructureArrays($returnProperties, $processor) {
foreach ($value as $relationField => $relationValue) {
// below block is same as primary block (duplicate)
if (isset($queryFields[$relationField]['title'])) {
$headerName = $field . '-' . $relationField;

if (!$processor->isHouseholdMergeRelationshipTypeKey($field)) {
// Do not add to header row if we are only generating for merge reasons.
$headerRows[] = $headerName;
$headerRows[] = $processor->getRelationshipTypes()[$key] . '-' . $queryFields[$relationField]['title'];
}

self::sqlColumnDefn($processor, $sqlColumns, $headerName);
}
elseif ($relationField == 'phone_type_id') {
$headerName = $field . '-' . 'Phone Type';
$headerRows[] = $headerName;
self::sqlColumnDefn($processor, $sqlColumns, $headerName);
}
elseif ($relationField == 'state_province_id') {
$headerName = $field . '-' . 'state_province_id';
$headerRows[] = $headerName;
self::sqlColumnDefn($processor, $sqlColumns, $headerName);
self::sqlColumnDefn($processor, $sqlColumns, $field . '-' . $relationField);
}
elseif (is_array($relationValue) && $relationField == 'location') {
// fix header for location type case
Expand All @@ -1336,14 +1308,12 @@ public static function getExportStructureArrays($returnProperties, $processor) {
$hdr .= "-" . CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_IM', 'provider_id', $type[1]);
}
}
$headerName = $field . '-' . $hdr;
$headerRows[] = $headerName;
self::sqlColumnDefn($processor, $sqlColumns, $headerName);
$headerRows[] = $processor->getRelationshipTypes()[$key] . $hdr;
self::sqlColumnDefn($processor, $sqlColumns, $field . '-' . $hdr);
}
}
}
}
self::manipulateHeaderRows($headerRows);
}
else {
foreach ($value as $locationType => $locationFields) {
Expand Down
7 changes: 7 additions & 0 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ public function testExportRelationships() {
$dao->fetch();
$this->assertEquals('Org 2', $dao->{$employerRelationshipTypeID . '_a_b_organization_name'});
$this->assertEquals('well dodgey', $dao->{$employerRelationshipTypeID . '_a_b_legal_name'});

$this->assertEquals([
0 => 'First Name',
1 => 'Employee of-Organization Name',
2 => 'Employee of-Legal Name',
3 => 'Employee of-Contact Source',
], $headerRows);
}

/**
Expand Down

0 comments on commit c167994

Please sign in to comment.