| 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 $blocks array of created address
- * @static
+ * @return array|NULL
+ * array of created address
*/
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') as $fld) {
+ 'street_number',
+ 'street_name',
+ 'street_unit',
+ 'street_number_suffix',
+ ) as $fld) {
unset($params[$fld]);
}
// main parse string.
}
/**
- * 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
$config = CRM_Core_Config::singleton();
foreach ($params as $name => $value) {
if (in_array($name, array(
- 'is_primary', 'location_type_id', 'id', 'contact_id', 'is_billing', 'display', 'master_id'))) {
+ 'is_primary',
+ 'location_type_id',
+ 'id',
+ 'contact_id',
+ 'is_billing',
+ 'display',
+ 'master_id',
+ ))) {
continue;
}
elseif (!CRM_Utils_System::isNull($value)) {
* If microformat output is required.
* @param int|string $fieldName conditional field name
*
- * @return array $addresses array with address fields
- * @static
+ * @return array
+ * array with address fields
*/
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.
if ($count > 1) {
foreach (array(
- 'state', 'state_name', 'country', 'world_region') as $fld) {
+ 'state',
+ 'state_name',
+ 'country',
+ '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);
*
* @param bool $updateBlankLocInfo
*
- * @return array the array of adrress data
- * @static
+ * @return array
+ * the array of adrress data
*/
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
+ * @return array
+ * the array of adrress data
*/
public static function allEntityAddress(&$entityElements) {
$addresses = array();
}
/**
- * Get address sequence
+ * Get address sequence.
*
- * @return array of address sequence.
+ * @return array
+ * Array of address sequence.
*/
public static function addressSequence() {
$config = CRM_Core_Config::singleton();
$addressSequence[$key] = 'city_postal_code';
}
elseif (
- in_array($field, array('country', 'state_province', 'city', 'postal_code'))
+ in_array($field, array('country', 'state_province', 'city', 'postal_code'))
) {
unset($addressSequence[$key]);
}
* 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 $parseFields parsed fields values.
- * @static
+ * @return array
+ * parsed fields values.
*/
public static function parseStreetAddress($streetAddress, $locale = NULL) {
$config = CRM_Core_Config::singleton();
$matches = array();
if (in_array($locale, array(
- 'en_CA', 'fr_CA')) && preg_match('/^([A-Za-z0-9]+)[ ]*\-[ ]*/', $streetAddress, $matches)) {
+ 'en_CA',
+ 'fr_CA',
+ )) && preg_match('/^([A-Za-z0-9]+)[ ]*\-[ ]*/', $streetAddress, $matches)
+ ) {
$parseFields['street_unit'] = $matches[1];
// unset from rest of street address
$streetAddress = preg_replace('/^([A-Za-z0-9]+)[ ]*\-[ ]*/', '', $streetAddress);
// now get the street unit.
// supportable street unit formats.
$streetUnitFormats = array(
- 'APT', 'APARTMENT', 'BSMT', 'BASEMENT', 'BLDG', 'BUILDING',
- 'DEPT', 'DEPARTMENT', 'FL', 'FLOOR', 'FRNT', 'FRONT',
- 'HNGR', 'HANGER', 'LBBY', 'LOBBY', 'LOWR', 'LOWER',
- 'OFC', 'OFFICE', 'PH', 'PENTHOUSE', 'TRLR', 'TRAILER',
- 'UPPR', 'RM', 'ROOM', 'SIDE', 'SLIP', 'KEY',
- 'LOT', 'PIER', 'REAR', 'SPC', 'SPACE',
- 'STOP', 'STE', 'SUITE', 'UNIT', '#',
+ 'APT',
+ 'APARTMENT',
+ 'BSMT',
+ 'BASEMENT',
+ 'BLDG',
+ 'BUILDING',
+ 'DEPT',
+ 'DEPARTMENT',
+ 'FL',
+ 'FLOOR',
+ 'FRNT',
+ 'FRONT',
+ 'HNGR',
+ 'HANGER',
+ 'LBBY',
+ 'LOBBY',
+ 'LOWR',
+ 'LOWER',
+ 'OFC',
+ 'OFFICE',
+ 'PH',
+ 'PENTHOUSE',
+ 'TRLR',
+ 'TRAILER',
+ 'UPPR',
+ 'RM',
+ 'ROOM',
+ 'SIDE',
+ 'SLIP',
+ 'KEY',
+ 'LOT',
+ 'PIER',
+ 'REAR',
+ 'SPC',
+ 'SPACE',
+ 'STOP',
+ 'STE',
+ 'SUITE',
+ 'UNIT',
+ '#',
);
// overwriting $streetUnitFormats for 'en_CA' and 'fr_CA' locale
if (in_array($locale, array(
- 'en_CA', 'fr_CA'))) {
+ 'en_CA',
+ 'fr_CA',
+ ))) {
$streetUnitFormats = array('APT', 'APP', 'SUITE', 'BUREAU', 'UNIT');
}
//@todo per CRM-14459 this regex picks up words with the string in them - e.g APT picks up
}
/**
- * 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
* An array of importable/exportable contact fields.
*
- * @return array $fields an array of contact fields and only the enabled address options
- * @static
+ * @return array
+ * an array of contact fields and only the enabled address options
*/
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 count of contacts that use this shared address
- * @static
+ * @return int
+ * count of contacts that use this shared address
*/
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'];
}
// CRM-15120
$formatted = array(
'first_name' => $rows[$rowID]['first_name'],
- 'individual_prefix' => $rows[$rowID]['individual_prefix']
+ 'individual_prefix' => $rows[$rowID]['individual_prefix'],
);
$format = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'display_name_format');
$firstNameWithPrefix = CRM_Utils_Address::format($formatted, $format, FALSE, FALSE, TRUE);
}
/**
- * 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.
* @param bool $returnStatus
* By default false.
*
- * @return string $statusMessage
- * @static
+ * @return string
*/
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);
}
+
}