Comments & e-notice fixes
[civicrm-core.git] / CRM / Core / BAO / Address.php
index 40785fcb7883d6ecaa4c9dda2b549b02e8a63a18..1769269e0a46609d2b35140d4aebed56088a3233 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -41,15 +41,17 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
   /**
    * takes an associative array and creates a address
    *
-   * @param array  $params (reference ) an assoc array of name/value pairs
-   * @param boolean  $fixAddress   true if you need to fix (format) address values
+   * @param array $params (reference ) an assoc array of name/value pairs
+   * @param boolean $fixAddress true if you need to fix (format) address values
    *                               before inserting in db
    *
+   * @param null $entity
+   *
    * @return array $blocks array of created address
    * @access public
    * @static
    */
-  static function create(&$params, $fixAddress, $entity = NULL) {
+  static function create(&$params, $fixAddress = TRUE, $entity = NULL) {
     if (!isset($params['address']) || !is_array($params['address'])) {
       return;
     }
@@ -80,7 +82,7 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
       }
 
       $addressExists = self::dataExists($value);
-      if ( !CRM_Utils_Array::value('id', $value) ) {
+      if (empty($value['id'])) {
         if ($updateBlankLocInfo) {
           if ((!empty($addresses) || !$addressExists) && array_key_exists($key, $addresses)) {
             $value['id'] = $addresses[$key];
@@ -105,21 +107,21 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
         continue;
       }
 
-      if ($isPrimary && CRM_Utils_Array::value('is_primary', $value)) {
+      if ($isPrimary && !empty($value['is_primary'])) {
         $isPrimary = FALSE;
       }
       else {
         $value['is_primary'] = 0;
       }
 
-      if ($isBilling && CRM_Utils_Array::value('is_billing', $value)) {
+      if ($isBilling && !empty($value['is_billing'])) {
         $isBilling = FALSE;
       }
       else {
         $value['is_billing'] = 0;
       }
 
-      if (!CRM_Utils_Array::value('manual_geo_code', $value)) {
+      if (empty($value['manual_geo_code'])) {
         $value['manual_geo_code'] = 0;
       }
       $value['contact_id'] = $contactId;
@@ -203,7 +205,7 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
    * @static
    */
   static function fixAddress(&$params) {
-    if (CRM_Utils_Array::value('billing_street_address', $params)) {
+    if (!empty($params['billing_street_address'])) {
       //Check address is comming from online contribution / registration page
       //Fixed :CRM-5076
       $billing = array(
@@ -218,7 +220,7 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
 
       foreach ($billing as $key => $val) {
         if ($value = CRM_Utils_Array::value($val, $params)) {
-          if (CRM_Utils_Array::value($key, $params)) {
+          if (!empty($params[$key])) {
             unset($params[$val]);
           }
           else {
@@ -231,7 +233,7 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
     }
 
     /* Split the zip and +4, if it's in US format */
-    if (CRM_Utils_Array::value('postal_code', $params) &&
+    if (!empty($params['postal_code']) &&
       preg_match('/^(\d{4,5})[+-](\d{4})$/',
         $params['postal_code'],
         $match
@@ -453,9 +455,9 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
    * Given the list of params in the params array, fetch the object
    * and store the values in the values array
    *
-   * @param array   $entityBlock   associated array of fields
-   * @param boolean $microformat   if microformat output is required
-   * @param int     $fieldName     conditional field name
+   * @param array $entityBlock associated array of fields
+   * @param boolean $microformat if microformat output is required
+   * @param int|string $fieldName conditional field name
    *
    * @return array  $addresses     array with address fields
    * @access public
@@ -468,7 +470,7 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address {
     $addresses = array();
     $address = new CRM_Core_BAO_Address();
 
-    if (!CRM_Utils_Array::value('entity_table', $entityBlock)) {
+    if (empty($entityBlock['entity_table'])) {
       $address->$fieldName = CRM_Utils_Array::value($fieldName, $entityBlock);
     }
     else {
@@ -967,7 +969,7 @@ SELECT is_primary,
       $nameVal = explode('-', $values['name']);
       $fldName = CRM_Utils_Array::value(0, $nameVal);
       $locType = CRM_Utils_Array::value(1, $nameVal);
-      if (CRM_Utils_Array::value('location_type_id', $values)) {
+      if (!empty($values['location_type_id'])) {
         $locType = $values['location_type_id'];
       }
 
@@ -1195,7 +1197,11 @@ SELECT is_primary,
           $params['condition'] = 'state_province_id IN (' . implode(',', (array) $props['state_province_id']) . ')';
         }
         break;
+      // 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);
   }
-}
\ No newline at end of file
+}