From f369c1ba5c7dfb6ddc87c0911c88d57cca4ee2b2 Mon Sep 17 00:00:00 2001 From: "Laryn - CEDC.org" Date: Wed, 13 Apr 2016 05:46:00 -0500 Subject: [PATCH] CRM-17361 - Fix Address fields when used in Contact get api (#8093) * 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 | 7 +++++++ CRM/Contact/BAO/Query.php | 3 +++ CRM/Core/BAO/Address.php | 2 ++ api/v3/Contact.php | 21 +++++++++++++++++++++ api/v3/utils.php | 3 +++ 5 files changed, 36 insertions(+) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 0f8ba6291b..b890989ce3 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -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); } diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 2830d31bfc..93a8dd35e7 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -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; diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index 49397fc8dc..708794b252 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -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); diff --git a/api/v3/Contact.php b/api/v3/Contact.php index 5bd3d1e0ca..7142453d30 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -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', diff --git a/api/v3/utils.php b/api/v3/utils.php index 911419489e..7532146024 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -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; } -- 2.25.1