From 7982443f3d77ebf8ee4e5f98d3a9bd8beb5a0dc1 Mon Sep 17 00:00:00 2001 From: Victor Boctor Date: Sat, 22 Apr 2017 18:54:43 -0700 Subject: [PATCH] REST: enum localization fixes - Enum name should reflect english enum name. - Fix php error due to referencing enum by localized name. - Remove `mci_get_enum_element()` which is not needed. --- api/soap/mc_api.php | 14 -------------- api/soap/mc_enum_api.php | 14 +++++++++----- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/api/soap/mc_api.php b/api/soap/mc_api.php index e968fe6fc5..ca108eacbb 100644 --- a/api/soap/mc_api.php +++ b/api/soap/mc_api.php @@ -667,20 +667,6 @@ function mci_get_mantis_path() { return config_get( 'path' ); } -/** - * Given a enum string and num, return the appropriate localized string - * @param string $p_enum_name Enumeration name. - * @param string $p_val Enumeration value. - * @param string $p_lang Language string. - * @return string - */ -function mci_get_enum_element( $p_enum_name, $p_val, $p_lang ) { - $t_enum_string = config_get( $p_enum_name . '_enum_string' ); - $t_localized_enum_string = lang_get( $p_enum_name . '_enum_string', $p_lang ); - - return MantisEnum::getLocalizedLabel( $t_enum_string, $t_localized_enum_string, $p_val ); -} - /** * Gets the sub-projects that are accessible to the specified user / project. * @param integer $p_user_id User id. diff --git a/api/soap/mc_enum_api.php b/api/soap/mc_enum_api.php index 64cc493488..c1afed2fc7 100644 --- a/api/soap/mc_enum_api.php +++ b/api/soap/mc_enum_api.php @@ -280,13 +280,17 @@ function mci_validate_enum_access( $p_username, $p_password ) { function mci_enum_get_array_by_id( $p_enum_id, $p_enum_type, $p_lang ) { $t_result = array(); $t_result['id'] = (int)$p_enum_id; - $t_result['name'] = mci_get_enum_element( $p_enum_type, $p_enum_id, $p_lang ); - if( !ApiObjectFactory::$soap ) { - $t_enum_name = $p_enum_type . '_enum_string'; - $t_enum_string_value = config_get( $t_enum_name ); - $t_enum_localized_value = lang_get( $t_enum_name ); + $t_enum_name = $p_enum_type . '_enum_string'; + $t_enum_string_value = config_get( $t_enum_name ); + $t_enum_localized_value = lang_get( $t_enum_name, $p_lang ); + if( ApiObjectFactory::$soap ) { + # Soap API returns the localized label as the name + $t_result['name'] = MantisEnum::getLocalizedLabel( $t_enum_string_value, $t_enum_localized_value, $p_enum_id ); + } else { + $t_enum_array = MantisEnum::getAssocArrayIndexedByValues( $t_enum_string_value ); + $t_result['name'] = $t_enum_array[$p_enum_id]; $t_result['label'] = MantisEnum::getLocalizedLabel( $t_enum_string_value, $t_enum_localized_value, $p_enum_id ); if( $p_enum_type == 'status' ) {