Skip to content

Commit

Permalink
Export Move relationship type definition to processor class
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jul 19, 2018
1 parent b849cfd commit 97bb8d1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
18 changes: 5 additions & 13 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,7 @@ public static function exportComponents(
// Warning - this imProviders var is used in a somewhat fragile way - don't rename it
// without manually testing the export of IM provider still works.
$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
self::$relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(
NULL,
NULL,
NULL,
NULL,
TRUE,
'name',
FALSE
);
self::$relationshipTypes = $processor->getRelationshipTypes();
//also merge Head of Household
self::$memberOfHouseholdRelationshipKey = CRM_Utils_Array::key('Household Member of', self::$relationshipTypes);
self::$headOfHouseholdRelationshipKey = CRM_Utils_Array::key('Head of Household for', self::$relationshipTypes);
Expand Down Expand Up @@ -357,7 +349,7 @@ public static function exportComponents(
continue;
}

if (array_key_exists($fieldName, self::$relationshipTypes) && (!empty($value[2]) || !empty($value[4]))) {
if ($processor->isRelationshipTypeKey($fieldName) && (!empty($value[2]) || !empty($value[4]))) {
self::setRelationshipReturnProperties($value, $locationTypeFields, $fieldName);
// @todo we can later not add this to this array but maintain a separate array.
$returnProperties = array_merge($returnProperties, self::$relationshipReturnProperties);
Expand Down Expand Up @@ -471,7 +463,7 @@ public static function exportComponents(
}

foreach ($returnProperties as $key => $value) {
if (!array_key_exists($key, self::$relationshipTypes)) {
if (!$processor->isRelationshipTypeKey($key)) {
$returnProperties[self::$memberOfHouseholdRelationshipKey][$key] = $value;
$returnProperties[self::$headOfHouseholdRelationshipKey][$key] = $value;
}
Expand Down Expand Up @@ -631,7 +623,7 @@ public static function exportComponents(
}
}

if (array_key_exists($field, self::$relationshipTypes)) {
if ($processor->isRelationshipTypeKey($field)) {
$relDAO = CRM_Utils_Array::value($iterationDAO->contact_id, $allRelContactArray[$field]);
$relationQuery[$field]->convertToPseudoNames($relDAO);
self::fetchRelationshipDetails($relDAO, $value, $field, $row);
Expand Down Expand Up @@ -1638,7 +1630,7 @@ public static function setHeaderRows($field, $headerRows, $sqlColumns, $processo
elseif ($field == 'provider_id') {
$headerRows[] = ts('IM Service Provider');
}
elseif (array_key_exists($field, self::$relationshipTypes)) {
elseif ($processor->isRelationshipTypeKey($field)) {
foreach ($value as $relationField => $relationValue) {
// below block is same as primary block (duplicate)
if (isset($relationQuery[$field]->_fields[$relationField]['title'])) {
Expand Down
40 changes: 40 additions & 0 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ class CRM_Export_BAO_ExportProcessor {
*/
protected $requestedFields;

/**
* Key representing the head of household in the relationship array.
*
* e.g. ['8_b_a' => 'Household Member Is', '8_a_b = 'Household Member Of'.....]
*
* @var
*/
protected $relationshipTypes = [];

/**
* CRM_Export_BAO_ExportProcessor constructor.
*
Expand All @@ -84,6 +93,7 @@ public function __construct($exportMode, $requestedFields, $queryOperator) {
$this->setQueryMode();
$this->setQueryOperator($queryOperator);
$this->setRequestedFields($requestedFields);
$this->setRelationshipTypes();
}

/**
Expand All @@ -100,6 +110,36 @@ public function setRequestedFields($requestedFields) {
$this->requestedFields = $requestedFields;
}

/**
* @return array
*/
public function getRelationshipTypes() {
return $this->relationshipTypes;
}

/**
*/
public function setRelationshipTypes() {
$this->relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(
NULL,
NULL,
NULL,
NULL,
TRUE,
'name',
FALSE
);
}


/**
* @param $fieldName
* @return bool
*/
public function isRelationshipTypeKey($fieldName) {
return array_key_exists($fieldName, $this->relationshipTypes);
}

/**
* @return string
*/
Expand Down

0 comments on commit 97bb8d1

Please sign in to comment.