MDL-22015 improved country lists
authorPetr Skoda <skodak@moodle.org>
Wed, 14 Apr 2010 12:42:48 +0000 (12:42 +0000)
committerPetr Skoda <skodak@moodle.org>
Wed, 14 Apr 2010 12:42:48 +0000 (12:42 +0000)
lang/en/admin.php
lib/moodlelib.php

index f363c93..6a1fa39 100755 (executable)
@@ -111,7 +111,7 @@ $string['componentinstalled'] = 'Component Installed';
 $string['computedfromlogs'] = 'Computed from logs since {$a}.';
 $string['condifmodeditdefaults'] = 'The values you set here define the default values that are used in the activity settings form when you create a new activity. You can also configure which activity settings are considered advanced.';
 $string['confeditorhidebuttons'] = 'Select the buttons that should be hidden in the HTML editor.';
 $string['computedfromlogs'] = 'Computed from logs since {$a}.';
 $string['condifmodeditdefaults'] = 'The values you set here define the default values that are used in the activity settings form when you create a new activity. You can also configure which activity settings are considered advanced.';
 $string['confeditorhidebuttons'] = 'Select the buttons that should be hidden in the HTML editor.';
-$string['configallcountrycodes'] = 'This is the list of countries that may be selected in various places, for example in a user\'s profile. If blank (the default) the list in countries.php in the standard English language pack is used. That is the list from ISO 3166-1. Otherwise, you can specify a comma-separated list of codes, for example \'GB,FR,ES\'. If you add new, non-standard codes here, you will need to add them to countries.php in your language pack.';
+$string['configallcountrycodes'] = 'This is the list of countries that may be selected in various places, for example in a user\'s profile. If blank (the default) the list in countries.php in the standard English language pack is used. That is the list from ISO 3166-1. Otherwise, you can specify a comma-separated list of codes, for example \'GB,FR,ES\'. If you add new, non-standard codes here, you will need to add them to countries.php in \'en\' and your language pack.';
 $string['configallowassign'] = 'You can allow people who have the roles on the left side to assign some of the column roles to other people';
 $string['configallowblockstodock'] = 'If enabled and supported by the selected theme users can choose to move blocks to a special dock.';
 $string['configallowcategorythemes'] = 'If you enable this, then themes can be set at the category level. This will affect all child categories and courses unless they have specifically set their own theme. WARNING: Enabling category themes may affect performance.';
 $string['configallowassign'] = 'You can allow people who have the roles on the left side to assign some of the column roles to other people';
 $string['configallowblockstodock'] = 'If enabled and supported by the selected theme users can choose to move blocks to a special dock.';
 $string['configallowcategorythemes'] = 'If you enable this, then themes can be set at the category level. This will affect all child categories and courses unless they have specifically set their own theme. WARNING: Enabling category themes may affect performance.';
index dc05d35..7a8da84 100644 (file)
@@ -5716,10 +5716,12 @@ interface string_manager {
     public function string_exists($identifier, $component);
 
     /**
     public function string_exists($identifier, $component);
 
     /**
-     * Returns a localised list of all country names
+     * Returns a localised list of all country names, sorted by country keys.
+     * @param bool $returnall return all or just enabled
+     * @param string $lang moodle translation language, NULL means use current
      * @return array two-letter country code => translated name.
      */
      * @return array two-letter country code => translated name.
      */
-    public function get_list_of_countries();
+    public function get_list_of_countries($returnall = false, $lang = NULL);
 
     /**
      * Returns a localised list of languages, sorted by code keys.
 
     /**
      * Returns a localised list of languages, sorted by code keys.
@@ -5997,12 +5999,34 @@ class core_string_manager implements string_manager {
     }
 
     /**
     }
 
     /**
-     * Returns a localised list of all country names
+     * Returns a localised list of all country names, sorted by country keys.
+     *
+     * @param bool $returnall return all or just enabled
+     * @param string $lang moodle translation language, NULL means use current
      * @return array two-letter country code => translated name.
      */
      * @return array two-letter country code => translated name.
      */
-    public function get_list_of_countries() {
-        $lang = current_language();
-        return $this->load_component_strings('countries', $lang);
+    public function get_list_of_countries($returnall = false, $lang = NULL) {
+        global $CFG;
+
+        if ($lang === NULL) {
+            $lang = current_language();
+        }
+
+        $countries = $this->load_component_strings('core_countries', $lang);
+        ksort($countries);
+
+        if (!$returnall and !empty($CFG->allcountrycodes)) {
+            $enabled = explode(',', $CFG->allcountrycodes);
+            $return = array();
+            foreach ($enabled as $c) {
+                if (isset($countries[$c])) {
+                    $return[$c] = $countries[$c];
+                }
+            }
+            return $return;
+        }
+
+        return $countries;
     }
 
     /**
     }
 
     /**
@@ -6019,7 +6043,7 @@ class core_string_manager implements string_manager {
         }
         if ($standard === 'iso6392') {
             $langs = $this->load_component_strings('core_iso6392', $lang);
         }
         if ($standard === 'iso6392') {
             $langs = $this->load_component_strings('core_iso6392', $lang);
-            $lang = ksort($langs);
+            ksort($langs);
             return $langs;
         } else {
             debugging('Unsupported $standard parameter in get_list_of_languages() method: '.$standard);
             return $langs;
         } else {
             debugging('Unsupported $standard parameter in get_list_of_languages() method: '.$standard);
@@ -6214,10 +6238,13 @@ class install_string_manager implements string_manager {
     }
 
     /**
     }
 
     /**
-     * Returns a localised list of all country names
+     * Returns a localised list of all country names, sorted by country keys.
+     *
+     * @param bool $returnall return all or just enabled
+     * @param string $lang moodle translation language, NULL means use current
      * @return array two-letter country code => translated name.
      */
      * @return array two-letter country code => translated name.
      */
-    public function get_list_of_countries() {
+    public function get_list_of_countries($returnall = false, $lang = NULL) {
         //not used in installer
         return array();
     }
         //not used in installer
         return array();
     }
@@ -6415,11 +6442,11 @@ function get_list_of_charsets() {
 }
 
 /**
 }
 
 /**
- * Returns a list of country names in the current language
+ * Returns a list of all enabled country names in the current translation
  * @return array two-letter country code => translated name.
  */
 function get_list_of_countries() {
  * @return array two-letter country code => translated name.
  */
 function get_list_of_countries() {
-    return get_string_manager()->get_list_of_countries();
+    return get_string_manager()->get_list_of_countries(false);
 }
 
 /**
 }
 
 /**