From 40a60af68942c42ca032866896cb081a39d07a50 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 15 Aug 2013 00:46:16 +1200 Subject: [PATCH] CRM-13179 a few fixes lost in gitting re-instated --- api/v3/Profile.php | 34 +++++++++++++++++++++++----- templates/CRM/common/AutoComplete.js | 1 + 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/api/v3/Profile.php b/api/v3/Profile.php index d2a838dce0..4393a12657 100644 --- a/api/v3/Profile.php +++ b/api/v3/Profile.php @@ -52,10 +52,13 @@ require_once 'api/v3/utils.php'; * NOTE this api is not standard & since it is tested we need to honour that * but the correct behaviour is for it to return an id indexed array as this supports * multiple instances + * + * Note that if contact_id is empty an array of defaults is returned + * */ function civicrm_api3_profile_get($params) { $nonStandardLegacyBehaviour = is_numeric($params['profile_id']) ? TRUE : FALSE; - if(!empty($params['check_permissions']) && !1 === civicrm_api3('contact', 'getcount', array('contact_id' => 1, 'check_permissions' => 1))) { + if(!empty($params['check_permissions']) && !empty($params['contact_id']) && !1 === civicrm_api3('contact', 'getcount', array('contact_id' => $params['contact_id'], 'check_permissions' => 1))) { throw new API_Exception('permission denied'); } $profiles = (array) $params['profile_id']; @@ -116,9 +119,12 @@ function civicrm_api3_profile_get($params) { CRM_Core_BAO_UFGroup::setComponentDefaults($activityFields, $params['activity_id'], 'Activity', $values[$profileID], TRUE); } } - else { + elseif(!empty($params['contact_id'])) { CRM_Core_BAO_UFGroup::setProfileDefaults($params['contact_id'], $profileFields, $values[$profileID], TRUE); } + else{ + $values[$profileID] = array_fill_keys(array_keys($profileFields), ''); + } } if($nonStandardLegacyBehaviour) { $result = civicrm_api3_create_success(); @@ -132,8 +138,7 @@ function civicrm_api3_profile_get($params) { function _civicrm_api3_profile_get_spec(&$params) { $params['profile_id']['api.required'] = TRUE; - // does this mean we use a different call to get a 'blank' profile? - $params['contact_id']['api.required'] = TRUE; + $params['contact_id']['description'] = 'If no contact is specified an array of defaults will be returned'; } /** * Update Profile field values. @@ -338,12 +343,28 @@ function civicrm_api3_profile_getfields($params) { * It gets standard credit card address fields etc * Note this is 'better' that the inbuilt version as it will pull in fallback values * billing location -> is_billing -> primary + * + * Note that that since the existing code for deriving a blank profile is not easily accessible our + * interim solution is just to return an empty array */ function _civicrm_api3_profile_getbillingpseudoprofile(&$params) { $addressFields = array('street_address', 'city', 'state_province_id', 'country_id'); + $locations = civicrm_api3('address', 'getoptions', array('field' => 'location_type_id')); + $locationTypeID = array_search('Billing', $locations['values']); + + if(empty($params['contact_id'])) { + $blanks = array( + 'billing_first_name' => '', + 'billing_middle_name' => '', + 'billing_last_name' => '', + ); + foreach ($addressFields as $field) { + $blanks['billing_' . $field . '_' . $locationTypeID] = ''; + } + return $blanks; + } $result = civicrm_api3('contact', 'getsingle', array( 'id' => $params['contact_id'], - 'api.address.getoptions' => array('field' => 'location_type_id',), 'api.address.get.1' => array('location_type_id' => 'Billing', 'return' => $addressFields), // getting the is_billing required or not is an extra db call but probably cheap enough as this isn't an import api 'api.address.get.2' => array('is_billing' => True, 'return' => $addressFields), @@ -352,7 +373,6 @@ function _civicrm_api3_profile_getbillingpseudoprofile(&$params) { 'return' => 'api.email.get, api.address.get, api.address.getoptions, email, first_name, last_name, middle_name,' . implode($addressFields, ','), ) ); - $locationTypeID = array_search('Billing', $result['api.address.getoptions']['values']); $values = array( 'billing_first_name' => $result['first_name'], @@ -385,5 +405,7 @@ function _civicrm_api3_profile_getbillingpseudoprofile(&$params) { else{ $values['billing-email'. '-' . $locationTypeID] = $result['email']; } + // return both variants of email to reflect inconsistencies in form layer + $values['email'. '-' . $locationTypeID] = $values['billing-email'. '-' . $locationTypeID]; return $values; } diff --git a/templates/CRM/common/AutoComplete.js b/templates/CRM/common/AutoComplete.js index 0077542d35..1439b22e2d 100644 --- a/templates/CRM/common/AutoComplete.js +++ b/templates/CRM/common/AutoComplete.js @@ -114,6 +114,7 @@ cj(function ($) { else{ $('#crm-contact-toggle-text-' + id_field).text(hidden_text); $('#' + id_field).val(''); + $('#' + name_field).val(''); CRM.api('profile', 'get', {'profile_id' : profileids}, { success: function(result) { $.each(result.values, function (id, values){ -- 2.25.1