+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018 |
+ | Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
* Address Utilities
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
*/
class CRM_Utils_Address {
}
// make sure that some of the fields do have values
- $emptyFields = array(
+ $emptyFields = [
'supplemental_address_1',
'supplemental_address_2',
'supplemental_address_3',
'state_province_name',
'county',
- );
+ ];
foreach ($emptyFields as $f) {
if (!isset($fields[$f])) {
$fields[$f] = NULL;
if ($mailing && !empty($fields['country'])) {
if (Civi::settings()->get('hideCountryMailingLabels')) {
$domain = CRM_Core_BAO_Domain::getDomain();
- $domainLocation = CRM_Core_BAO_Location::getValues(array('contact_id' => $domain->contact_id));
+ $domainLocation = CRM_Core_BAO_Location::getValues(['contact_id' => $domain->contact_id]);
$domainAddress = $domainLocation['address'][1];
$domainCountryId = $domainAddress['country_id'];
if ($fields['country'] == CRM_Core_PseudoConstant::country($domainCountryId)) {
if (!$microformat) {
// replacements in case of Individual Name Format
- $replacements = array(
+ $replacements = [
'contact.display_name' => CRM_Utils_Array::value('display_name', $fields),
'contact.individual_prefix' => CRM_Utils_Array::value('individual_prefix', $fields),
'contact.formal_title' => CRM_Utils_Array::value('formal_title', $fields),
'contact.addressee' => CRM_Utils_Array::value('addressee_display', $fields),
'contact.email_greeting' => CRM_Utils_Array::value('email_greeting_display', $fields),
'contact.postal_greeting' => CRM_Utils_Array::value('postal_greeting_display', $fields),
- );
+ ];
}
else {
- $replacements = array(
+ $replacements = [
'contact.address_name' => "<span class=\"address-name\">" . $fields['address_name'] . "</span>",
'contact.street_address' => "<span class=\"street-address\">" . $fields['street_address'] . "</span>",
'contact.supplemental_address_1' => "<span class=\"extended-address\">" . $fields['supplemental_address_1'] . "</span>",
'contact.postal_code' => "<span class=\"postal-code\">" . $fullPostalCode . "</span>",
'contact.country' => "<span class=\"country-name\">" . $fields['country'] . "</span>",
'contact.world_region' => "<span class=\"region\">" . $fields['world_region'] . "</span>",
- );
+ ];
// erase all empty ones, so we dont get blank lines
foreach (array_keys($replacements) as $key) {
$formatted = preg_replace('/{([^{}]*)}({[^{}]*})+/u', '\1', $formatted);
// drop any remaining curly braces leaving their contents
- $formatted = str_replace(array('{', '}'), '', $formatted);
+ $formatted = str_replace(['{', '}'], '', $formatted);
// drop any empty lines left after the replacements
$formatted = preg_replace('/^[ \t]*[\r\n]+/m', '', $formatted);
else {
// remove \n from each line and only add at the end
// this hack solves formatting issue, when we convert nl2br
- $lines = array();
+ $lines = [];
$count = 1;
$finalFormatted = NULL;
$formattedArray = explode("\n", $formatted);
*/
public static function sequence($format) {
// also compute and store the address sequence
- $addressSequence = array(
+ $addressSequence = [
'address_name',
'street_address',
'supplemental_address_1',
'state_province',
'postal_code',
'country',
- );
+ ];
// get the field sequence from the format
- $newSequence = array();
+ $newSequence = [];
foreach ($addressSequence as $field) {
if (substr_count($format, $field)) {
$newSequence[strpos($format, $field)] = $field;
* @return string
*/
public static function getFormattedBillingAddressFieldsFromParameters($params, $billingLocationTypeID) {
- $addressParts = array(
+ $addressParts = [
"street_address" => "billing_street_address-{$billingLocationTypeID}",
"city" => "billing_city-{$billingLocationTypeID}",
"postal_code" => "billing_postal_code-{$billingLocationTypeID}",
"state_province" => "state_province-{$billingLocationTypeID}",
"country" => "country-{$billingLocationTypeID}",
- );
+ ];
- $addressFields = array();
+ $addressFields = [];
foreach ($addressParts as $name => $field) {
$value = CRM_Utils_Array::value($field, $params);
$alternateName = 'billing_' . $name . '_id-' . $billingLocationTypeID;
$alternateName = $alternate2;
}
//Include values which prepend 'billing_' to country and state_province.
- if (CRM_Utils_Array::value($alternateName, $params)) {
+ if (!empty($params[$alternateName])) {
if (empty($value) || !is_numeric($value)) {
$value = $params[$alternateName];
}