Skip to content

Commit

Permalink
Move household relationship types to the processor
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jul 28, 2018
1 parent 9ebfb6f commit 7387f54
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 32 deletions.
40 changes: 9 additions & 31 deletions CRM/Export/BAO/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,6 @@ class CRM_Export_BAO_Export {
// CRM-7675
const EXPORT_ROW_COUNT = 100000;

/**
* Key representing the head of household in the relationship array.
*
* e.g. 8_a_b.
*
* @var string
*/
protected static $headOfHouseholdRelationshipKey;

/**
* Key representing the head of household in the relationship array.
*
* e.g. 8_a_b.
*
* @var string
*/
protected static $memberOfHouseholdRelationshipKey;

/**
* Key representing the head of household in the relationship array.
*
Expand Down Expand Up @@ -244,7 +226,7 @@ public static function exportComponents(
$queryOperator = 'AND'
) {

$processor = new CRM_Export_BAO_ExportProcessor($exportMode, $fields, $queryOperator);
$processor = new CRM_Export_BAO_ExportProcessor($exportMode, $fields, $queryOperator, $mergeSameHousehold);
$returnProperties = array();
$selectedPaymentFields = FALSE;
// @todo - this variable is overwritten later - it should be wholly definable in the processor fn.
Expand All @@ -255,9 +237,6 @@ public static function exportComponents(
// without manually testing the export of IM provider still works.
$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
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);

$queryMode = $processor->getQueryMode();

Expand Down Expand Up @@ -384,15 +363,13 @@ public static function exportComponents(

foreach ($returnProperties as $key => $value) {
if (!$processor->isRelationshipTypeKey($key)) {
$returnProperties[self::$memberOfHouseholdRelationshipKey][$key] = $value;
$returnProperties[self::$headOfHouseholdRelationshipKey][$key] = $value;
foreach ($processor->getHouseholdRelationshipTypes() as $householdRelationshipType) {
if (!in_array($key, ['location_type', 'im_provider'])) {
$returnProperties[$householdRelationshipType][$key] = $value;
}
}
}
}

unset($returnProperties[self::$memberOfHouseholdRelationshipKey]['location_type']);
unset($returnProperties[self::$memberOfHouseholdRelationshipKey]['im_provider']);
unset($returnProperties[self::$headOfHouseholdRelationshipKey]['location_type']);
unset($returnProperties[self::$headOfHouseholdRelationshipKey]['im_provider']);
}

list($relationQuery, $allRelContactArray) = self::buildRelatedContactArray($selectAll, $ids, $exportMode, $componentTable, $returnProperties, $queryMode);
Expand Down Expand Up @@ -628,8 +605,9 @@ public static function exportComponents(

// merge the records if they have corresponding households
if ($mergeSameHousehold) {
self::mergeSameHousehold($exportTempTable, $headerRows, $sqlColumns, self::$memberOfHouseholdRelationshipKey);
self::mergeSameHousehold($exportTempTable, $headerRows, $sqlColumns, self::$headOfHouseholdRelationshipKey);
foreach ($processor->getHouseholdRelationshipTypes() as $householdRelationshipType) {
self::mergeSameHousehold($exportTempTable, $headerRows, $sqlColumns, $householdRelationshipType);
}
}

// call export hook
Expand Down
47 changes: 46 additions & 1 deletion CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ class CRM_Export_BAO_ExportProcessor {
*/
protected $requestedFields;

/**
* Is the contact being merged into a single household.
*
* @var bool
*/
protected $isMergeSameHousehold;

/**
* Key representing the head of household in the relationship array.
*
Expand All @@ -94,8 +101,9 @@ class CRM_Export_BAO_ExportProcessor {
* @param int $exportMode
* @param array|NULL $requestedFields
* @param string $queryOperator
* @param bool $isMergeSameHousehold
*/
public function __construct($exportMode, $requestedFields, $queryOperator) {
public function __construct($exportMode, $requestedFields, $queryOperator, $isMergeSameHousehold) {
$this->setExportMode($exportMode);
$this->setQueryMode();
$this->setQueryOperator($queryOperator);
Expand Down Expand Up @@ -138,6 +146,34 @@ public function setRelationshipTypes() {
);
}

/**
* @return bool
*/
public function isMergeSameHousehold() {
return $this->isMergeSameHousehold;
}

/**
* @param bool $isMergeSameHousehold
*/
public function setIsMergeSameHousehold($isMergeSameHousehold) {
$this->isMergeSameHousehold = $isMergeSameHousehold;
}

/**
* Return relationship types for household merge.
*
* @return mixed
*/
public function getHouseholdRelationshipTypes() {
if (!$this->isMergeSameHousehold()) {
return [];
}
return [
CRM_Utils_Array::key('Household Member of', $this->getRelationshipTypes()),
CRM_Utils_Array::key('Head of Household for', $this->getRelationshipTypes()),
];
}

/**
* @param $fieldName
Expand All @@ -147,6 +183,15 @@ public function isRelationshipTypeKey($fieldName) {
return array_key_exists($fieldName, $this->relationshipTypes);
}


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

/**
* @return string
*/
Expand Down

0 comments on commit 7387f54

Please sign in to comment.