예제 #1
0
 /**
  * Tests getLocalizedLabel() method.
  */
 public function testGetLocalizedLabel()
 {
     // Test existing case
     $this->assertEquals('viewer_x', MantisEnum::getLocalizedLabel(MantisEnumTest::ACCESS_LEVELS_ENUM, MantisEnumTest::ACCESS_LEVELS_LOCALIZED_ENUM, 10));
     // Test unknown case
     $this->assertEquals('@5@', MantisEnum::getLocalizedLabel(MantisEnumTest::ACCESS_LEVELS_ENUM, MantisEnumTest::ACCESS_LEVELS_LOCALIZED_ENUM, 5));
     // Test the case where the value is in the localized enum but not the standard one.  In this case it should be treated
     // as unknown.
     $this->assertEquals('@95@', MantisEnum::getLocalizedLabel(MantisEnumTest::ACCESS_LEVELS_ENUM, MantisEnumTest::ACCESS_LEVELS_LOCALIZED_ENUM, 95));
 }
예제 #2
0
 /**
  * Tests getLocalizedLabel() method.
  * @return void
  */
 public function testGetLocalizedLabel()
 {
     # Test existing case
     $this->assertEquals('viewer_x', MantisEnum::getLocalizedLabel(MantisEnumTest::ACCESS_LEVELS_ENUM, MantisEnumTest::ACCESS_LEVELS_LOCALIZED_ENUM, 10));
     # Test unknown case
     $this->assertEquals('@5@', MantisEnum::getLocalizedLabel(MantisEnumTest::ACCESS_LEVELS_ENUM, MantisEnumTest::ACCESS_LEVELS_LOCALIZED_ENUM, 5));
     # Test the case where the value is in the localized enumeration but not the standard one.
     # In this case it should be treated as unknown.
     $this->assertEquals('@95@', MantisEnum::getLocalizedLabel(MantisEnumTest::ACCESS_LEVELS_ENUM, MantisEnumTest::ACCESS_LEVELS_LOCALIZED_ENUM, 95));
     # Test the case where the value is in the standard enumeration but not in the localized one.
     # In this case we should fall back to the standard enumeration (as we do with language strings)
     # as the value is a known good value - just that it has not yet been localized.
     $this->assertEquals('missing', MantisEnum::getLocalizedLabel(MantisEnumTest::ACCESS_LEVELS_ENUM_EXTRA, MantisEnumTest::ACCESS_LEVELS_LOCALIZED_ENUM, 100));
 }
예제 #3
0
/**
 * Explode a configuration enumeration name into an array structure that can
 * be safely converted into an ObjectRef structure.
 * 
 * @param string $p_enumeration_name  The name of the enumeration to convert
 * @return Array  The converted enumeration
 */
function mci_explode_to_objectref($p_enumeration_name)
{
    $t_config_var_name = $p_enumeration_name . '_enum_string';
    $t_config_var_value = config_get($t_config_var_name);
    $t_translated_values = lang_get($t_config_var_name, mci_get_user_lang(auth_get_current_user_id()));
    $t_enum_values = MantisEnum::getValues($t_config_var_value);
    $t_result = array();
    foreach ($t_enum_values as $t_key) {
        $t_translated = MantisEnum::getLocalizedLabel($t_config_var_value, $t_translated_values, $t_key);
        $t_result[] = array('id' => $t_key, 'name' => $t_translated);
    }
    return $t_result;
}
예제 #4
0
/**
 * 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);
}
예제 #5
0
/**
 * Given a enum string and num, return the appropriate string for the
 * specified user/project
 * @param string $p_enum_name
 * @param int $p_val
 * @param int|null $p_user user id, defaults to null (all users)
 * @param int|null $p_project project id, defaults to null (all projects)
 * @return string
 */
function get_enum_element($p_enum_name, $p_val, $p_user = null, $p_project = null)
{
    $config_var = config_get($p_enum_name . '_enum_string', null, $p_user, $p_project);
    $string_var = lang_get($p_enum_name . '_enum_string');
    return MantisEnum::getLocalizedLabel($config_var, $string_var, $p_val);
}