CRM-17361 - Fix Address fields when used in Contact get api (#8093)
authorLaryn - CEDC.org <laryn@cedc.org>
Wed, 13 Apr 2016 10:46:00 +0000 (05:46 -0500)
committerEileen McNaughton <eileen@mcnaughty.com>
Wed, 13 Apr 2016 10:46:00 +0000 (22:46 +1200)
* CRM-17361 -- Extend Contact getoptions to include Address fields

* CRM-17361 -- Extend Contact getoptions to include Address fields

* CRM-17361 -- Extend Contact getoptions to include Address fields

* CRM-17361 -- Extend Contact getoptions to include Address fields

* CRM-17361 -- Extend Contact getoptions to include Address fields

CRM/Contact/BAO/Contact.php
CRM/Contact/BAO/Query.php
CRM/Core/BAO/Address.php
api/v3/Contact.php
api/v3/utils.php

index 0f8ba6291bda515e4981857749e3bc3707ec6d5c..b890989ce39f267ac0bef0bb91611e1f3d30e0bc 100644 (file)
@@ -3370,6 +3370,13 @@ LEFT JOIN civicrm_address add2 ON ( add1.master_id = add2.id )
         $props['entity_table'] = 'civicrm_contact';
         return CRM_Core_BAO_EntityTag::buildOptions('tag_id', $context, $props);
 
+      case 'state_province_id':
+      case 'country_id':
+      case 'county_id':
+      case 'worldregion':
+      case 'worldregion_id':
+        return CRM_Core_BAO_Address::buildOptions($fieldName, 'get', $props);
+
     }
     return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
   }
index 2830d31bfc1e896ac93af69588539af0b0a14f6c..93a8dd35e7c0701612a1a1c19f57fc3dda635909 100644 (file)
@@ -1799,10 +1799,13 @@ class CRM_Contact_BAO_Query {
         return;
 
       case 'state_province':
+      case 'state_province_id':
+      case 'state_province_name':
         $this->stateProvince($values);
         return;
 
       case 'country':
+      case 'country_id':
         $this->country($values, FALSE);
         return;
 
index 49397fc8dc90e73faefcbadb1100c78cf7d62b76..708794b25298a3cfec1f25657bc0af659ec02f44 100644 (file)
@@ -1299,6 +1299,8 @@ SELECT is_primary,
 
       // Not a real field in this entity
       case 'world_region':
+      case 'worldregion':
+      case 'worldregion_id':
         return CRM_Core_PseudoConstant::worldRegion();
     }
     return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
index 5bd3d1e0ca98ae012d09132edf573076164d8ca7..7142453d30b954804f7bed437b4c916decce0747 100644 (file)
@@ -229,30 +229,51 @@ function _civicrm_api3_contact_get_spec(&$params) {
   $params['state_province_id'] = array(
     'title' => 'Primary Address State Province ID',
     'type' => CRM_Utils_Type::T_INT,
+    'pseudoconstant' => array(
+      'table' => 'civicrm_state_province',
+    ),
   );
   $params['state_province_name'] = array(
     'title' => 'Primary Address State Province Name',
     'type' => CRM_Utils_Type::T_STRING,
+    'pseudoconstant' => array(
+      'table' => 'civicrm_state_province',
+    ),
   );
   $params['state_province'] = array(
     'title' => 'Primary Address State Province',
     'type' => CRM_Utils_Type::T_STRING,
+    'pseudoconstant' => array(
+      'table' => 'civicrm_state_province',
+    ),
   );
   $params['country_id'] = array(
     'title' => 'Primary Address Country ID',
     'type' => CRM_Utils_Type::T_INT,
+    'pseudoconstant' => array(
+      'table' => 'civicrm_country',
+    ),
   );
   $params['country'] = array(
     'title' => 'Primary Address country',
     'type' => CRM_Utils_Type::T_STRING,
+    'pseudoconstant' => array(
+      'table' => 'civicrm_country',
+    ),
   );
   $params['worldregion_id'] = array(
     'title' => 'Primary Address World Region ID',
     'type' => CRM_Utils_Type::T_INT,
+    'pseudoconstant' => array(
+      'table' => 'civicrm_world_region',
+    ),
   );
   $params['worldregion'] = array(
     'title' => 'Primary Address World Region',
     'type' => CRM_Utils_Type::T_STRING,
+    'pseudoconstant' => array(
+      'table' => 'civicrm_world_region',
+    ),
   );
   $params['phone_id'] = array(
     'title' => 'Primary Phone ID',
index 911419489ed02550b6dcd2e7be97ab423e759733..753214602446e102e7f422b251d6f3931ac8ddec 100644 (file)
@@ -1798,6 +1798,9 @@ function _civicrm_api_get_fields($entity, $unique = FALSE, &$params = array()) {
     }
   }
   $fields += _civicrm_api_get_custom_fields($entity, $params);
+  if ($entity == 'Contact') {
+    $fields += _civicrm_api_get_fields('Address');
+  }
   return $fields;
 }