MDL-22015 deprecated get_list_of_currencies() method - improved string_manager encapsulation

This commit is contained in:
Petr Skoda 2010-04-14 14:04:21 +00:00
parent f6907ba954
commit 97b7d149b6
4 changed files with 53 additions and 43 deletions

View File

@ -344,7 +344,7 @@ class course_edit_form extends moodleform {
// If the print_entry method exists and the course enrol method isn't manual (both set or inherited from site), show cost
if (method_exists(enrolment_factory::factory($enrol_object->enrol), 'print_entry') && !($enrol_object->enrol == 'manual' || (empty($enrol_object->enrol) && $CFG->enrol == 'manual'))) {
$costgroup=array();
$currencies = get_list_of_currencies();
$currencies = get_string_manager()->get_list_of_currencies();
$costgroup[]= &MoodleQuickForm::createElement('text','cost', '', 'maxlength="6" size="6"');
$costgroup[]= &MoodleQuickForm::createElement('select', 'currency', '', $currencies);
$mform->addGroup($costgroup, 'costgrp', get_string('cost'), ' ', false);

View File

@ -65,7 +65,7 @@ if (!isset($frm->acceptechecktypes)) {
<tr valign="top">
<td align="right">enrol_currency:</td>
<td><?php
echo html_writer::select(get_list_of_currencies(), "enrol_currency", $frm->enrol_currency, false);
echo html_writer::select(get_string_manager()->get_list_of_currencies(), "enrol_currency", $frm->enrol_currency, false);
?>
<br />
<?php print_string("currency") ?>

View File

@ -48,12 +48,24 @@ function auth_get_plugin_title($authtype) {
* @return array An associative array with contents in the form of LanguageCode => LanguageName
*/
function get_list_of_languages($refreshcache=false, $returnall=false) {
debugging('get_list_of_languages() is deprecated, please use get_string_manager()->get_list_of_translations() instead.');
if ($refreshcache) {
// TODO: reset lang cache
}
return get_string_manager()->get_list_of_translations($returnall);
}
/**
* Returns a list of currencies in the current language
* @deprecated
* @return array
*/
function get_list_of_currencies() {
debugging('get_list_of_currencies() is deprecated, please use get_string_manager()->get_list_of_currencies() instead.');
return get_string_manager()->get_list_of_currencies();
}
/**
* @deprecated
*/

View File

@ -5748,6 +5748,14 @@ interface string_manager {
*/
public function get_list_of_translations($returnall = false);
/**
* Returns localised list of currencies.
*
* @param string $lang moodle translation language, NULL means use current
* @return array currency code => localised currency name
*/
public function get_list_of_currencies($lang = NULL);
/**
* Load all strings for one component
* @param string $component The module the string is associated with
@ -6087,7 +6095,7 @@ class core_string_manager implements string_manager {
// part of distribution
return true;
}
return file_exists("$this->otherroot/$lang/longconfig.php");
return file_exists("$this->otherroot/$lang/longconfig.php");
}
/**
@ -6149,6 +6157,23 @@ class core_string_manager implements string_manager {
return $languages;
}
/**
* Returns localised list of currencies.
*
* @param string $lang moodle translation language, NULL means use current
* @return array currency code => localised currency name
*/
public function get_list_of_currencies($lang = NULL) {
if ($lang === NULL) {
$lang = current_language();
}
$currencies = $this->load_component_strings('core_currencies', $lang);
asort($currencies);
return $currencies;
}
}
@ -6220,7 +6245,7 @@ class install_string_manager implements string_manager {
if ($lang === NULL) {
$lang = current_language();
}
//get parent lang
$parent = '';
if ($lang !== 'en' and $identifier !== 'parentlanguage' and $component !== 'langconfig') {
@ -6314,7 +6339,7 @@ class install_string_manager implements string_manager {
* @return boot true if exists
*/
public function translation_exists($lang, $includeall = true) {
return file_exists($this->installroot.'/'.$lang.'/langconfig.php');
return file_exists($this->installroot.'/'.$lang.'/langconfig.php');
}
/**
@ -6341,6 +6366,17 @@ class install_string_manager implements string_manager {
// Return array
return $languages;
}
/**
* Returns localised list of currencies.
*
* @param string $lang moodle translation language, NULL means use current
* @return array currency code => localised currency name
*/
public function get_list_of_currencies($lang = NULL) {
// not used in installer
return array();
}
}
@ -6612,44 +6648,6 @@ function get_list_of_timezones() {
return $timezones;
}
/**
* Returns a list of currencies in the current language
*
* @global object
* @global object
* @return array
*/
function get_list_of_currencies() {
global $CFG, $USER;
$lang = current_language();
if (!file_exists($CFG->dataroot .'/lang/'. $lang .'/currencies.php')) {
if ($parentlang = get_parent_language()) {
if (file_exists($CFG->dataroot .'/lang/'. $parentlang .'/currencies.php')) {
$lang = $parentlang;
} else {
$lang = 'en'; // currencies.php must exist in this pack
}
} else {
$lang = 'en'; // currencies.php must exist in this pack
}
}
if (file_exists($CFG->dataroot .'/lang/'. $lang .'/currencies.php')) {
include_once($CFG->dataroot .'/lang/'. $lang .'/currencies.php');
} else { //if en is not installed in dataroot
include_once($CFG->dirroot .'/lang/'. $lang .'/currencies.php');
}
if (!empty($string)) {
asort($string);
}
return $string;
}
/// ENCRYPTION ////////////////////////////////////////////////
/**