$params['address'] = array();
}
- $addressCnt = 1;
- foreach ($params['address'] as $cnt => $addressBlock) {
- if (CRM_Utils_Array::value('location_type_id', $values) ==
- CRM_Utils_Array::value('location_type_id', $addressBlock)
- ) {
- $addressCnt = $cnt;
- break;
- }
- $addressCnt++;
- }
-
if (!array_key_exists('Address', $fields)) {
$fields['Address'] = CRM_Core_DAO_Address::fields();
}
$values = $newValues;
}
- _civicrm_api3_store_values($fields['Address'], $values, $params['address'][$addressCnt]);
+ _civicrm_api3_store_values($fields['Address'], $values, $params['address'][$values['location_type_id']]);
$addressFields = array(
'county',
if (!array_key_exists('address', $params)) {
$params['address'] = array();
}
- $params['address'][$addressCnt][$field] = $values[$field];
+ $params['address'][$values['location_type_id']][$field] = $values[$field];
}
}
$primary = civicrm_api3('Address', 'get', array('return' => 'location_type_id', 'contact_id' => $params['id'], 'is_primary' => 1, 'sequential' => 1));
}
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
- $params['address'][$addressCnt]['location_type_id'] = (isset($primary) && $primary['count']) ? $primary['values'][0]['location_type_id'] : $defaultLocationType->id;
- $params['address'][$addressCnt]['is_primary'] = 1;
-
- }
-
- if ($addressCnt == 1) {
+ $params['address'][$values['location_type_id']]['location_type_id'] = (isset($primary) && $primary['count']) ? $primary['values'][0]['location_type_id'] : $defaultLocationType->id;
+ $params['address'][$values['location_type_id']]['is_primary'] = 1;
- $params['address'][$addressCnt]['is_primary'] = TRUE;
}
return TRUE;
}
$this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary'));
$address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion'));
$this->assertEquals(1, $address['location_type_id']);
+ $this->assertEquals(1, $address['is_primary']);
$phone = $this->callAPISuccessGetSingle('Phone', array('phone' => '12334'));
$this->assertEquals(1, $phone['location_type_id']);
$contactValues['nick_name'] = 'Old Bill';
$contactValues['external_identifier'] = 'android';
$contactValues['street_address'] = 'Big Mansion';
+ $contactValues['city'] = 'Big City';
$contactID = $this->callAPISuccessGetValue('Contact', array('external_identifier' => 'android', 'return' => 'id'));
$originalAddress = $this->callAPISuccess('Address', 'create', array('location_type_id' => 2, 'street_address' => 'small house', 'contact_id' => $contactID));
- $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary'));
+ $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary'));
$address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion'));
$this->assertEquals(2, $address['location_type_id']);
$this->assertEquals($originalAddress['id'], $address['id']);
+ $this->assertEquals('Big City', $address['city']);
$this->callAPISuccessGetSingle('Contact', $contactValues);
}