From 50153877a92fe4f137ef9376cd7e7b937a815a98 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 17 Nov 2018 15:19:33 +1300 Subject: [PATCH 1/2] Remove header handling that I think is unreachable --- CRM/Export/BAO/Export.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index c530add01eb8..4182efbf9b26 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -1307,17 +1307,6 @@ public static function getExportStructureArrays($returnProperties, $processor) { // Do not add to header row if we are only generating for merge reasons. $headerRows[] = $headerName; } - - 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); } elseif (is_array($relationValue) && $relationField == 'location') { From 5359d42b964b540926551cc40c053677befc6fb6 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 17 Nov 2018 15:24:54 +1300 Subject: [PATCH 2/2] Remove silly manipulateHeaderRows function Export code cleanup - Extend testing so we can get rid of silly manipulate fn --- CRM/Export/BAO/Export.php | 27 +++------------------ tests/phpunit/CRM/Export/BAO/ExportTest.php | 7 ++++++ 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 4182efbf9b26..e67f1c54d737 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -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 @@ -1301,13 +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); + self::sqlColumnDefn($processor, $sqlColumns, $field . '-' . $relationField); } elseif (is_array($relationValue) && $relationField == 'location') { // fix header for location type case @@ -1325,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) { diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 5e0a8ac156a7..547dc90cf21d 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -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); } /**