From 29fbb90ad76ec8cc66f4ddac430eadc7d8074e1c Mon Sep 17 00:00:00 2001 From: Eileen Date: Wed, 25 Sep 2013 12:16:07 +1200 Subject: [PATCH] CRM-13234 amend previous commit (commit hooks crash when I try to do a commit --amend) ---------------------------------------- * CRM-13234: facilitate data-entry-entities via api http://issues.civicrm.org/jira/browse/CRM-13234 --- api/v3/Profile.php | 17 ++++++++++++----- api/v3/examples/ProfileGetFields.php | 23 +++++++++++++++-------- api/v3/examples/ProfileSubmit.php | 1 + tests/phpunit/api/v3/ProfileTest.php | 5 +++-- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/api/v3/Profile.php b/api/v3/Profile.php index e869d38985..d49d794585 100644 --- a/api/v3/Profile.php +++ b/api/v3/Profile.php @@ -519,14 +519,24 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour = $entityGetFieldsResult = _civicrm_api3_profile_appendaliases($result['values'], $entity); foreach ($entityFields as $entityfield => $realName) { $fieldName = strtolower($entityfield); - if(!stristr('-', $fieldName) && realName != $fieldName) { + if(!strstr($fieldName, '-')) { + if(strtolower($realName) != $fieldName) { // we want to keep the '-' pattern for locations but otherwise // we are going to make the api-standard field the main / preferred name but support the db name // in future naming the fields in the DB to reflect the way the rest of the api / BAO / metadata works would // reduce code - $fieldName = $realName; + $fieldName = strtolower($realName); + } + if(isset($entityGetFieldsResult[$realName]['uniqueName'])) { + // we won't alias the field name on here are we are using uniqueNames for the possibility of needing to differentiate + // which entity 'status_id' belongs to + $fieldName = $entityGetFieldsResult[$realName]['uniqueName']; + } } $profileFields[$profileID][$fieldName] = array_merge($profileFields[$profileID][$entityfield], $entityGetFieldsResult[$realName]); + if(!isset($profileFields[$profileID][$fieldName]['api.aliases'])) { + $profileFields[$profileID][$fieldName]['api.aliases'] = array(); + } if($optionsBehaviour && !empty($entityGetFieldsResult[$realName]['pseudoconstant'])) { if($optionsBehaviour > 1 || !in_array($realName, array('state_province_id', 'county_id', 'country_id'))) { $options = civicrm_api3($entity, 'getoptions', array('field' => $realName)); @@ -539,9 +549,6 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour = unset($profileFields[$profileID][$entityfield]); } // we will make the mixed case version (e.g. of 'Primary') an alias - if(!isset($profileFields[$profileID][$fieldName]['api.aliases'])) { - $profileFields[$profileID][$fieldName]['api.aliases'] = array(); - } $profileFields[$profileID][$fieldName]['api.aliases'][] = $entityfield; } /** diff --git a/api/v3/examples/ProfileGetFields.php b/api/v3/examples/ProfileGetFields.php index b7984ab8d3..eff419870a 100644 --- a/api/v3/examples/ProfileGetFields.php +++ b/api/v3/examples/ProfileGetFields.php @@ -38,7 +38,7 @@ function profile_getfields_expectedresult(){ 'title' => 'First Name', 'help_pre' => '', 'help_post' => '', - 'entity' => 'Contact', + 'entity' => 'contact', 'name' => 'first_name', 'type' => 2, 'maxlength' => 64, @@ -48,13 +48,14 @@ function profile_getfields_expectedresult(){ 'headerPattern' => '/^first|(f(irst\s)?name)$/i', 'dataPattern' => '/^\w+$/', 'export' => true, + 'api.aliases' => array(), ), 'last_name' => array( 'api.required' => '1', 'title' => 'Last Name', 'help_pre' => '', 'help_post' => '', - 'entity' => 'Contact', + 'entity' => 'contact', 'name' => 'last_name', 'type' => 2, 'maxlength' => 64, @@ -64,13 +65,14 @@ function profile_getfields_expectedresult(){ 'headerPattern' => '/^last|(l(ast\s)?name)$/i', 'dataPattern' => '/^\w+(\s\w+)?+$/', 'export' => true, + 'api.aliases' => array(), ), 'email-primary' => array( 'api.required' => 1, 'title' => 'Email', 'help_pre' => '', 'help_post' => '', - 'entity' => 'Email', + 'entity' => 'email', 'api.aliases' => array( '0' => 'email-Primary', ), @@ -90,7 +92,7 @@ function profile_getfields_expectedresult(){ 'title' => 'Phone', 'help_pre' => '', 'help_post' => '', - 'entity' => 'Phone', + 'entity' => 'phone', 'name' => 'phone', 'type' => 2, 'maxlength' => 32, @@ -100,13 +102,14 @@ function profile_getfields_expectedresult(){ 'headerPattern' => '/phone/i', 'dataPattern' => '/^[\d\(\)\-\.\s]+$/', 'export' => true, + 'api.aliases' => array(), ), 'country-1' => array( 'api.required' => '1', 'title' => 'Country', 'help_pre' => '', 'help_post' => '', - 'entity' => 'Address', + 'entity' => 'address', 'name' => 'country_id', 'type' => 1, 'FKClassName' => 'CRM_Core_DAO_Country', @@ -116,13 +119,14 @@ function profile_getfields_expectedresult(){ 'labelColumn' => 'name', 'nameColumn' => 'iso_code', ), + 'api.aliases' => array(), ), 'state_province-1' => array( 'api.required' => '1', 'title' => 'State', 'help_pre' => '', 'help_post' => '', - 'entity' => 'Address', + 'entity' => 'address', 'name' => 'state_province_id', 'type' => 1, 'FKClassName' => 'CRM_Core_DAO_StateProvince', @@ -131,13 +135,14 @@ function profile_getfields_expectedresult(){ 'keyColumn' => 'id', 'labelColumn' => 'name', ), + 'api.aliases' => array(), ), 'postal_code-1' => array( 'api.required' => 0, 'title' => 'Postal Code', 'help_pre' => '', 'help_post' => '', - 'entity' => 'Address', + 'entity' => 'address', 'name' => 'postal_code', 'type' => 2, 'maxlength' => 12, @@ -147,13 +152,14 @@ function profile_getfields_expectedresult(){ 'headerPattern' => '/postal|zip/i', 'dataPattern' => '/\d?\d{4}(-\d{4})?/', 'export' => true, + 'api.aliases' => array(), ), 'custom_1' => array( 'api.required' => '1', 'title' => 'first_name', 'help_pre' => '', 'help_post' => '', - 'entity' => 'Contact', + 'entity' => 'contact', 'label' => '_addCustomFieldToProfile', 'groupTitle' => '_addCustomFie', 'data_type' => 'String', @@ -173,6 +179,7 @@ function profile_getfields_expectedresult(){ 'time_format' => '', 'name' => 'custom_1', 'type' => 2, + 'api.aliases' => array(), ), 'profile_id' => array( 'api.required' => true, diff --git a/api/v3/examples/ProfileSubmit.php b/api/v3/examples/ProfileSubmit.php index 156ac6552b..3d27cde182 100644 --- a/api/v3/examples/ProfileSubmit.php +++ b/api/v3/examples/ProfileSubmit.php @@ -65,6 +65,7 @@ function profile_submit_expectedresult(){ 'first_name' => 'abc2', 'middle_name' => 'J.', 'last_name' => 'xyz2', + 'prefix_id' => '3', 'suffix_id' => '3', 'email_greeting_id' => '1', 'email_greeting_custom' => '', diff --git a/tests/phpunit/api/v3/ProfileTest.php b/tests/phpunit/api/v3/ProfileTest.php index 9ac44e7f17..109380b938 100644 --- a/tests/phpunit/api/v3/ProfileTest.php +++ b/tests/phpunit/api/v3/ProfileTest.php @@ -324,8 +324,9 @@ class api_v3_ProfileTest extends CiviUnitTestCase { 'profile_id' => 'participant_status', 'get_options' => 'all') ); - $this->assertTrue(array_key_exists('participant_status', $result['values'])); - $this->assertEquals('Attended', $result['values']['participant_status']['options'][2]); + $this->assertTrue(array_key_exists('participant_status_id', $result['values'])); + $this->assertEquals('Attended', $result['values']['participant_status_id']['options'][2]); + $this->assertEquals(array('participant_status'), $result['values']['participant_status_id']['api.aliases']); } /** -- 2.25.1