);
foreach ($fields as $key => $value) {
- $phoneTypeId = $imProviderId = $relationField = NULL;
+ $relationField = NULL;
$relationshipTypes = $fieldName = CRM_Utils_Array::value(1, $value);
if (!$fieldName) {
continue;
}
- // get phoneType id and IM service provider id separately
- if ($fieldName == 'phone') {
- $phoneTypeId = CRM_Utils_Array::value(3, $value);
- }
- elseif ($fieldName == 'im') {
- $imProviderId = CRM_Utils_Array::value(3, $value);
- }
- if (array_key_exists($relationshipTypes, $contactRelationshipTypes)) {
+ if (array_key_exists($relationshipTypes, $contactRelationshipTypes) && (!empty($value[2]) || empty($value[4]))) {
+ $relPhoneTypeId = $relIMProviderId = NULL;
if (!empty($value[2])) {
$relationField = CRM_Utils_Array::value(2, $value);
if (trim(CRM_Utils_Array::value(3, $value))) {
$relIMProviderId = CRM_Utils_Array::value(6, $value);
}
}
- }
-
- $locTypeId = CRM_Utils_Array::value(2, $value);
-
- if ($relationField) {
if (in_array($relationField, $locationTypeFields) && is_numeric($relLocTypeId)) {
if ($relPhoneTypeId) {
$returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]]['phone-' . $relPhoneTypeId] = 1;
else {
$returnProperties[$relationshipTypes]['location'][$locationTypes[$relLocTypeId]][$relationField] = 1;
}
- $relPhoneTypeId = $relIMProviderId = NULL;
}
else {
$returnProperties[$relationshipTypes][$relationField] = 1;
}
}
- elseif (is_numeric($locTypeId)) {
- if ($phoneTypeId) {
- $returnProperties['location'][$locationTypes[$locTypeId]]['phone-' . $phoneTypeId] = 1;
+
+ if ($relationField) {
+ // already handled.
+ }
+ elseif (is_numeric(CRM_Utils_Array::value(2, $value))) {
+ $locTypeId = $value[2];
+ if ($fieldName == 'phone') {
+ $returnProperties['location'][$locationTypes[$locTypeId]]['phone-' . CRM_Utils_Array::value(3, $value)] = 1;
}
- elseif ($imProviderId) {
- $returnProperties['location'][$locationTypes[$locTypeId]]['im-' . $imProviderId] = 1;
+ elseif ($fieldName == 'im') {
+ $returnProperties['location'][$locationTypes[$locTypeId]]['im-' . CRM_Utils_Array::value(3, $value)] = 1;
}
else {
$returnProperties['location'][$locationTypes[$locTypeId]][$fieldName] = 1;
$this->assertEquals('Big campaign,', CRM_Core_DAO::singleValueQuery("SELECT GROUP_CONCAT(contribution_campaign_title) FROM {$tableName}"));
}
+ /**
+ * Test exporting relationships.
+ *
+ * This is to ensure that CRM-13995 remains fixed.
+ */
+ public function testExportRelationshipsMergeToHousehold() {
+ $this->setUpContactExportData();
+ $householdID = $this->householdCreate(['city' => 'Portland', 'state_province_id' => 'Oregan']);
+
+ $relationshipTypes = $this->callAPISuccess('RelationshipType', 'get', [])['values'];
+ $houseHoldTypeID = NULL;
+ foreach ($relationshipTypes as $id => $relationshipType) {
+ if ($relationshipType['name_a_b'] === 'Household Member of') {
+ $houseHoldTypeID = $relationshipType['id'];
+ }
+ }
+ $this->callAPISuccess('Relationship', 'create', [
+ 'contact_id_a' => $this->contactIDs[0],
+ 'contact_id_b' => $householdID,
+ 'relationship_type_id' => $houseHoldTypeID,
+ ]);
+ $this->callAPISuccess('Relationship', 'create', [
+ 'contact_id_a' => $this->contactIDs[1],
+ 'contact_id_b' => $householdID,
+ 'relationship_type_id' => $houseHoldTypeID,
+ ]);
+
+ $selectedFields = [
+ ['Individual', $houseHoldTypeID . '_a_b', 'state_province', ''],
+ ['Individual', $houseHoldTypeID . '_a_b', 'city', ''],
+ ['Individual', 'city', ''],
+ ['Individual', 'state_province', ''],
+ ];
+ list($tableName) = CRM_Export_BAO_Export::exportComponents(
+ FALSE,
+ $this->contactIDs,
+ [],
+ NULL,
+ $selectedFields,
+ NULL,
+ CRM_Export_Form_Select::CONTACT_EXPORT,
+ "contact_a.id IN (" . implode(",", $this->contactIDs) . ")",
+ NULL,
+ FALSE,
+ TRUE,
+ [
+ 'exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT,
+ 'suppress_csv_for_testing' => TRUE,
+ ]
+ );
+ $dao = CRM_Core_DAO::executeQuery("SELECT * FROM {$tableName}");
+ while ($dao->fetch()) {
+ // Do some checks here
+ // $this->assertEquals('Portland', $dao->city);
+ // $this->assertEquals('Oregan', $dao0>state_province);
+ }
+
+ }
+
/**
* Test master_address_id field.
*/