Skip to content

Commit

Permalink
Extract field wrangling to determineReturnProperties
Browse files Browse the repository at this point in the history
This encases the wrangling of the field format to it's own function
  • Loading branch information
eileenmcnaughton committed Jul 8, 2019
1 parent b054c7a commit a4270ab
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 46 deletions.
45 changes: 0 additions & 45 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,51 +180,6 @@ public static function exportComponents(
);

$processor = new CRM_Export_BAO_ExportProcessor($exportMode, $fields, $queryOperator, $mergeSameHousehold, $isPostalOnly);
$returnProperties = [];

if ($fields) {
foreach ($fields as $key => $value) {
$fieldName = CRM_Utils_Array::value(1, $value);
if (!$fieldName || $processor->isHouseholdMergeRelationshipTypeKey($fieldName)) {
continue;
}

if ($processor->isRelationshipTypeKey($fieldName) && (!empty($value[2]) || !empty($value[4]))) {
$returnProperties[$fieldName] = $processor->setRelationshipReturnProperties($value, $fieldName);
}
elseif (is_numeric(CRM_Utils_Array::value(2, $value))) {
$locationName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_Address', 'location_type_id', $value[2]);
if ($fieldName == 'phone') {
$returnProperties['location'][$locationName]['phone-' . CRM_Utils_Array::value(3, $value)] = 1;
}
elseif ($fieldName == 'im') {
$returnProperties['location'][$locationName]['im-' . CRM_Utils_Array::value(3, $value)] = 1;
}
else {
$returnProperties['location'][$locationName][$fieldName] = 1;
}
}
else {
//hack to fix component fields
//revert mix of event_id and title
if ($fieldName == 'event_id') {
$returnProperties['event_id'] = 1;
}
else {
$returnProperties[$fieldName] = 1;
}
}
}
$defaultExportMode = $processor->defaultReturnProperty();
if ($defaultExportMode) {
$returnProperties[$defaultExportMode] = 1;
}
}
else {
$returnProperties = $processor->getDefaultReturnProperties();
}
// @todo - we are working towards this being entirely a property of the processor
$processor->setReturnProperties($returnProperties);
$paymentTableId = $processor->getPaymentTableID();

if ($mergeSameAddress) {
Expand Down
54 changes: 53 additions & 1 deletion CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public function __construct($exportMode, $requestedFields, $queryOperator, $isMe
$this->setRequestedFields($requestedFields);
$this->setRelationshipTypes();
$this->setIsMergeSameHousehold($isMergeSameHousehold);
$this->setisPostalableOnly($isPostalableOnly);
$this->setIsPostalableOnly($isPostalableOnly);
$this->setReturnProperties($this->determineReturnProperties());
}

/**
Expand Down Expand Up @@ -1439,4 +1440,55 @@ public function defaultReturnProperty() {
return $property;
}

/**
* Determine the required return properties from the input parameters.
*
* @return array
*/
public function determineReturnProperties() {
if ($this->getRequestedFields()) {
$returnProperties = [];
foreach ($this->getRequestedFields() as $key => $value) {
$fieldName = CRM_Utils_Array::value(1, $value);
if (!$fieldName || $this->isHouseholdMergeRelationshipTypeKey($fieldName)) {
continue;
}

if ($this->isRelationshipTypeKey($fieldName) && (!empty($value[2]) || !empty($value[4]))) {
$returnProperties[$fieldName] = $this->setRelationshipReturnProperties($value, $fieldName);
}
elseif (is_numeric(CRM_Utils_Array::value(2, $value))) {
$locationName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_Address', 'location_type_id', $value[2]);
if ($fieldName == 'phone') {
$returnProperties['location'][$locationName]['phone-' . CRM_Utils_Array::value(3, $value)] = 1;
}
elseif ($fieldName == 'im') {
$returnProperties['location'][$locationName]['im-' . CRM_Utils_Array::value(3, $value)] = 1;
}
else {
$returnProperties['location'][$locationName][$fieldName] = 1;
}
}
else {
//hack to fix component fields
//revert mix of event_id and title
if ($fieldName == 'event_id') {
$returnProperties['event_id'] = 1;
}
else {
$returnProperties[$fieldName] = 1;
}
}
}
$defaultExportMode = $this->defaultReturnProperty();
if ($defaultExportMode) {
$returnProperties[$defaultExportMode] = 1;
}
}
else {
$returnProperties = $this->getDefaultReturnProperties();
}
return $returnProperties;
}

}

0 comments on commit a4270ab

Please sign in to comment.