From: eileen Date: Sat, 17 Nov 2018 02:24:54 +0000 (+1300) Subject: Remove silly manipulateHeaderRows function X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5359d42b964b540926551cc40c053677befc6fb6;p=civicrm-core.git Remove silly manipulateHeaderRows function Export code cleanup - Extend testing so we can get rid of silly manipulate fn --- diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 4182efbf9b..e67f1c54d7 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -1130,21 +1130,6 @@ LIMIT $offset, $limit } } - /** - * 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 @@ WHERE {$whereClause}"; 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 @@ WHERE {$whereClause}"; $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 5e0a8ac156..547dc90cf2 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -462,6 +462,13 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { $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); } /**