| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
/**
- * Takes an associative array and creates a address
+ * Takes an associative array and creates a address.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @param null $entity
*
- * @return array
+ * @return array|NULL
* array of created address
- * @static
*/
public static function create(&$params, $fixAddress = TRUE, $entity = NULL) {
if (!isset($params['address']) || !is_array($params['address'])) {
- return;
+ return NULL;
}
CRM_Core_BAO_Block::sortPrimaryFirst($params['address']);
$addresses = array();
}
/**
- * Takes an associative array and adds address
+ * Takes an associative array and adds address.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* True if you need to fix (format) address values.
* before inserting in db
*
- * @return object
- * CRM_Core_BAO_Address object on success, null otherwise
- * @static
+ * @return CRM_Core_BAO_Address|null
*/
public static function add(&$params, $fixAddress) {
static $customFields = NULL;
}
/**
- * Format the address params to have reasonable values
+ * Format the address params to have reasonable values.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @return void
- * @static
*/
public static function fixAddress(&$params) {
if (!empty($params['billing_street_address'])) {
CRM_Utils_Address_USPS::checkAddress($params);
// do street parsing again if enabled, since street address might have changed
- $parseStreetAddress =
- CRM_Utils_Array::value(
- 'street_address_parsing',
- CRM_Core_BAO_Setting::valueOptions(
- CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
- 'address_options'
- ),
- FALSE
- );
+ $parseStreetAddress = CRM_Utils_Array::value(
+ 'street_address_parsing',
+ CRM_Core_BAO_Setting::valueOptions(
+ CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
+ 'address_options'
+ ),
+ FALSE
+ );
if ($parseStreetAddress && !empty($params['street_address'])) {
foreach (array(
'street_number',
'street_name',
'street_unit',
- 'street_number_suffix'
+ 'street_number_suffix',
) as $fld) {
unset($params[$fld]);
}
}
/**
- * Check if there is data to create the object
+ * Check if there is data to create the object.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
- * @return boolean
- *
- * @static
+ * @return bool
*/
public static function dataExists(&$params) {
//check if location type is set if not return false
'contact_id',
'is_billing',
'display',
- 'master_id'
+ 'master_id',
))) {
continue;
}
*
* @return array
* array with address fields
- * @static
*/
public static function &getValues($entityBlock, $microformat = FALSE, $fieldName = 'contact_id') {
if (empty($entityBlock)) {
$address->find();
+ $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$count = 1;
while ($address->fetch()) {
// deprecate reference.
'state',
'state_name',
'country',
- 'world_region'
+ 'world_region',
) as $fld) {
if (isset($address->$fld)) {
unset($address->$fld);
CRM_Core_DAO::storeValues($address, $values);
// add state and country information: CRM-369
+ if (!empty($address->location_type_id)) {
+ $values['location_type'] = CRM_Utils_Array::value($address->location_type_id, $locationTypes);
+ }
if (!empty($address->state_province_id)) {
$address->state = CRM_Core_PseudoConstant::stateProvinceAbbreviation($address->state_province_id, FALSE);
$address->state_name = CRM_Core_PseudoConstant::stateProvince($address->state_province_id, FALSE);
*
* @return array
* the array of adrress data
- * @static
*/
public static function allAddress($id, $updateBlankLocInfo = FALSE) {
if (!$id) {
*
* @param array $entityElements
* The array containing entity_id and.
- * entity_table name
+ * entity_table name
*
* @return array
* the array of adrress data
- * @static
*/
public static function allEntityAddress(&$entityElements) {
$addresses = array();
}
/**
- * Get address sequence
+ * Get address sequence.
*
* @return array
- * of address sequence.
+ * Array of address sequence.
*/
public static function addressSequence() {
$config = CRM_Core_Config::singleton();
* NB: civic street formats for en_CA and fr_CA used by default if those locales are active
* otherwise en_US format is default action
*
- * @param string Street address including number and apt
- * @param string Locale - to set locale used to parse address
+ * @param string $streetAddress
+ * Street address including number and apt.
+ * @param string $locale
+ * Locale used to parse address.
*
* @return array
* parsed fields values.
- * @static
*/
public static function parseStreetAddress($streetAddress, $locale = NULL) {
$config = CRM_Core_Config::singleton();
$matches = array();
if (in_array($locale, array(
'en_CA',
- 'fr_CA'
+ 'fr_CA',
)) && preg_match('/^([A-Za-z0-9]+)[ ]*\-[ ]*/', $streetAddress, $matches)
) {
$parseFields['street_unit'] = $matches[1];
// overwriting $streetUnitFormats for 'en_CA' and 'fr_CA' locale
if (in_array($locale, array(
'en_CA',
- 'fr_CA'
+ 'fr_CA',
))) {
$streetUnitFormats = array('APT', 'APP', 'SUITE', 'BUREAU', 'UNIT');
}
}
/**
- * Validate the address fields based on the address options enabled
+ * Validate the address fields based on the address options enabled.
* in the Address Settings
*
* @param array $fields
*
* @return array
* an array of contact fields and only the enabled address options
- * @static
*/
public static function validateAddressOptions($fields) {
static $addressOptions = NULL;
if (!$addressOptions) {
- $addressOptions =
- CRM_Core_BAO_Setting::valueOptions(
- CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
- 'address_options'
- );
+ $addressOptions = CRM_Core_BAO_Setting::valueOptions(
+ CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
+ 'address_options'
+ );
}
if (is_array($fields) && !empty($fields)) {
}
/**
- * Check if current address is used by any other contacts
+ * Check if current address is used by any other contacts.
*
* @param int $addressId
* Address id.
*
* @return int
* count of contacts that use this shared address
- * @static
*/
public static function checkContactSharedAddress($addressId) {
$query = 'SELECT count(id) FROM civicrm_address WHERE master_id = %1';
}
/**
- * Check if current address fields are shared with any other address
+ * Check if current address fields are shared with any other address.
*
* @param array $fields
* Address fields in profile.
* @param int $contactId
* Contact id.
*
- * @static
*/
public static function checkContactSharedAddressFields(&$fields, $contactId) {
if (!$contactId || !is_array($fields) || empty($fields)) {
}
/**
- * Update the shared addresses if master address is modified
+ * Update the shared addresses if master address is modified.
*
* @param int $addressId
* Address id.
* Associated array of address params.
*
* @return void
- * @static
*/
public static function processSharedAddress($addressId, $params) {
$query = 'SELECT id FROM civicrm_address WHERE master_id = %1';
}
/**
- * Merge contacts with the Same address to get one shared label
+ * Merge contacts with the Same address to get one shared label.
* @param array $rows
* Array[contact_id][contactDetails].
*/
$uniqueAddress = array();
foreach (array_keys($rows) as $rowID) {
// load complete address as array key
- $address =
- trim($rows[$rowID]['street_address']) . trim($rows[$rowID]['city']) . trim($rows[$rowID]['state_province']) . trim($rows[$rowID]['postal_code']) . trim($rows[$rowID]['country']);
+ $address = trim($rows[$rowID]['street_address'])
+ . trim($rows[$rowID]['city'])
+ . trim($rows[$rowID]['state_province'])
+ . trim($rows[$rowID]['postal_code'])
+ . trim($rows[$rowID]['country']);
if (isset($rows[$rowID]['last_name'])) {
$name = $rows[$rowID]['last_name'];
}
}
/**
- * Create relationship between contacts who share an address
+ * Create relationship between contacts who share an address.
*
* Note that currently we create relationship only for Individual contacts
* Individual + Household and Individual + Orgnization
* Associated array of submitted values.
*
* @return void
- * @static
*/
public static function processSharedAddressRelationship($masterAddressId, $params) {
if (!$masterAddressId) {
CRM_Core_Error::fatal(ts("You seem to have deleted the relationship type '%1'", array(1 => $relationshipType)));
}
- // create relationship
- $relationshipParams = array(
- 'is_active' => TRUE,
- 'relationship_type_id' => $relTypeId . '_a_b',
- 'contact_check' => array($sharedContactId => TRUE),
- );
-
- list($valid, $invalid, $duplicate,
- $saved, $relationshipIds
- ) = CRM_Contact_BAO_Relationship::createMultiple($relationshipParams, $cid);
+ try {
+ // create relationship
+ civicrm_api3('relationship', 'create', array(
+ 'is_active' => TRUE,
+ 'relationship_type_id' => $relTypeId,
+ 'contact_id_a' => $cid,
+ 'contact_id_b' => $sharedContactId,
+ ));
+ }
+ catch (CiviCRM_API3_Exception $e) {
+ // We catch and ignore here because this has historically been a best-effort relationship create call.
+ // presumably it could refuse due to duplication or similar and we would ignore that.
+ }
}
/**
- * Check and set the status for shared address delete
+ * Check and set the status for shared address delete.
*
* @param int $addressId
* Address id.
* By default false.
*
* @return string
- * @static
*/
public static function setSharedAddressDeleteStatus($addressId = NULL, $contactId = NULL, $returnStatus = FALSE) {
// check if address that is being deleted has any shared
}
/**
- * Call common delete function
+ * Call common delete function.
*/
public static function del($id) {
return CRM_Contact_BAO_Contact::deleteObjectWithPrimary('Address', $id);
*
* @param string $fieldName
* @param string $context
- * : @see CRM_Core_DAO::buildOptionsContext.
+ * @see CRM_Core_DAO::buildOptionsContext
* @param array $props
- * : whatever is known about this dao object.
+ * whatever is known about this dao object.
*
- * @return Array|bool
+ * @return array|bool
*/
public static function buildOptions($fieldName, $context = NULL, $props = array()) {
$params = array();
// Not a real field in this entity
case 'world_region':
return CRM_Core_PseudoConstant::worldRegion();
-
- break;
}
return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
}
+
}