Skip to content

Commit

Permalink
Move construction of headers to ExportProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 20, 2018
1 parent de6ff50 commit ae5d4ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
8 changes: 4 additions & 4 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ public static function getExportStructureArrays($returnProperties, $processor) {
foreach ($returnProperties as $key => $value) {
if (($key != 'location' || !is_array($value)) && !$processor->isRelationshipTypeKey($key)) {
$outputColumns[$key] = $value;
$processor->addOutputSpecification($key, $processor->getHeaderForRow($key));
$processor->addOutputSpecification($key);
self::sqlColumnDefn($processor, $sqlColumns, $key);
}
elseif ($processor->isRelationshipTypeKey($key)) {
Expand All @@ -1254,7 +1254,7 @@ public static function getExportStructureArrays($returnProperties, $processor) {
if (isset($queryFields[$relationField]['title'])) {
if (!$processor->isHouseholdMergeRelationshipTypeKey($field)) {
// Do not add to header row if we are only generating for merge reasons.
$processor->addOutputSpecification($relationField, $processor->getHeaderForRow($relationField), $key);
$processor->addOutputSpecification($relationField, $key);
}
self::sqlColumnDefn($processor, $sqlColumns, $field . '-' . $relationField);
}
Expand All @@ -1274,7 +1274,7 @@ public static function getExportStructureArrays($returnProperties, $processor) {
$hdr .= "-" . CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_IM', 'provider_id', $type[1]);
}
}
$processor->addOutputSpecification($field, $hdr, $key);
$processor->addOutputSpecification($field, $key, $ltype, CRM_Utils_Array::value(1, $type));
self::sqlColumnDefn($processor, $sqlColumns, $field . '-' . $hdr);
}
}
Expand Down Expand Up @@ -1304,7 +1304,7 @@ public static function getExportStructureArrays($returnProperties, $processor) {
$metadata[$daoFieldName]['pseudoconstant']['var'] = 'imProviders';
}
self::sqlColumnDefn($processor, $sqlColumns, $outputFieldName);
$processor->addOutputSpecification($outputFieldName, $processor->getHeaderForRow($outputFieldName));
$processor->addOutputSpecification($outputFieldName, NULL, $locationType, CRM_Utils_Array::value(1, $type));
self::sqlColumnDefn($processor, $sqlColumns, $outputFieldName);
if ($actualDBFieldName == 'country' || $actualDBFieldName == 'world_region') {
$metadata[$daoFieldName] = array('context' => 'country');
Expand Down
27 changes: 22 additions & 5 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,33 @@ public function runQuery($params, $order, $returnProperties) {

/**
* Add a row to the specification for how to output data.
*
* @param string $key
* @param string $label
* @param string $relationshipType
* @param string $locationType
* @param int $entityTypeID phone_type_id or provider_id for phone or im fields.
*/
public function addOutputSpecification($key, $label, $relationshipType = NULL) {
$labelPrefix = '';
public function addOutputSpecification($key, $relationshipType = NULL, $locationType = NULL, $entityTypeID = NULL) {
$label = $this->getHeaderForRow($key);
$labelPrefix = $fieldPrefix = [];
if ($relationshipType) {
$labelPrefix = $this->getRelationshipTypes()[$relationshipType] . '-';
$labelPrefix[] = $this->getRelationshipTypes()[$relationshipType];
$fieldPrefix[] = $relationshipType;
}
if ($locationType) {
$labelPrefix[] = $fieldPrefix[] = $locationType;
}
if ($entityTypeID) {
if ($key === 'phone') {
$labelPrefix[] = $fieldPrefix[] = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_Phone', 'phone_type_id', $entityTypeID);
}
if ($key === 'im') {
$labelPrefix[] = $fieldPrefix[] = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_IM', 'provider_id', $entityTypeID);
}
}
$this->outputSpecification[$key]['header'] = $labelPrefix . $label;
$index = ($fieldPrefix ? (implode('-', $fieldPrefix) . '-') : '') . $key;
$this->outputSpecification[$index]['header'] = ($labelPrefix ? (implode('-', $labelPrefix) . '-') : '') . $label;

}

/**
Expand Down

0 comments on commit ae5d4ca

Please sign in to comment.