Merge branch 'MDL-57090-master' of git://github.com/ankitagarwal/moodle
authorDavid Monllao <davidm@moodle.com>
Wed, 30 Nov 2016 02:43:16 +0000 (10:43 +0800)
committerDavid Monllao <davidm@moodle.com>
Wed, 30 Nov 2016 02:43:16 +0000 (10:43 +0800)
blocks/community/forms.php
course/publish/forms.php
course/publish/lib.php

index 02b679e..c515911 100644 (file)
@@ -240,22 +240,11 @@ class community_hub_search_form extends moodleform {
 
             $publicationmanager = new course_publish_manager();
             $options = $publicationmanager->get_sorted_subjects();
-            foreach ($options as $key => &$option) {
-                $keylength = strlen($key);
-                if ($keylength == 10) {
-                    $option = "&nbsp;&nbsp;" . $option;
-                } else if ($keylength == 12) {
-                    $option = "&nbsp;&nbsp;&nbsp;&nbsp;" . $option;
-                }
-            }
-            $options = array_merge(array('all' => get_string('any')), $options);
-            $mform->addElement('select', 'subject', get_string('subject', 'block_community'),
+            $mform->addElement('searchableselector', 'subject', get_string('subject', 'block_community'),
                     $options, array('id' => 'communitysubject'));
             $mform->setDefault('subject', $subject);
             unset($options);
             $mform->addHelpButton('subject', 'subject', 'block_community');
-            $this->init_javascript_enhancement('subject', 'smartselect',
-                    array('selectablecategories' => true, 'mode' => 'compact'));
 
             require_once($CFG->libdir . "/licenselib.php");
             $licensemanager = new license_manager();
index 898c5ac..45ccbfb 100644 (file)
@@ -303,23 +303,12 @@ class course_publication_form extends moodleform {
 
         $options = $publicationmanager->get_sorted_subjects();
 
-        //prepare data for the smartselect
-        foreach ($options as $key => &$option) {
-            $keylength = strlen($key);
-            if ($keylength == 10) {
-                $option = "&nbsp;&nbsp;" . $option;
-            } else if ($keylength == 12) {
-                $option = "&nbsp;&nbsp;&nbsp;&nbsp;" . $option;
-            }
-        }
-
-        $options = array('none' => get_string('none', 'hub')) + $options;
-        $mform->addElement('select', 'subject', get_string('subject', 'hub'), $options);
+        $mform->addElement('searchableselector', 'subject',
+            get_string('subject', 'hub'), $options);
         unset($options);
         $mform->addHelpButton('subject', 'subject', 'hub');
         $mform->setDefault('subject', $defaultsubject);
         $mform->addRule('subject', $strrequired, 'required', null, 'client');
-        $this->init_javascript_enhancement('subject', 'smartselect', array('selectablecategories' => false, 'mode' => 'compact'));
 
         $options = array();
         $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub');
index fe13219..af0d596 100644 (file)
@@ -267,33 +267,17 @@ class course_publish_manager {
     public function get_sorted_subjects() {
         $subjects = get_string_manager()->load_component_strings('edufields', current_language());
 
-        //sort the subjects
+        // Sort the subjects.
+        $return  = [];
         asort($subjects);
         foreach ($subjects as $key => $option) {
             $keylength = strlen($key);
-            if ($keylength == 8) {
-                $toplevel[$key] = $option;
-            } else if ($keylength == 10) {
-                $sublevel[substr($key, 0, 8)][$key] = $option;
-            } else if ($keylength == 12) {
-                $subsublevel[substr($key, 0, 8)][substr($key, 0, 10)][$key] = $option;
+            if ($keylength == 12) {
+                $return[$key] = $option; // We want only selectable categories.
             }
         }
-
-        //recreate the initial structure returned by get_string_manager()
-        $subjects = array();
-        foreach ($toplevel as $key => $name) {
-            $subjects[$key] = $name;
-            foreach ($sublevel[$key] as $subkey => $subname) {
-                $subjects[$subkey] = $subname;
-                foreach ($subsublevel[$key][$subkey] as $subsubkey => $subsubname) {
-                    $subjects[$subsubkey] = $subsubname;
-                }
-            }
-        }
-
-        return $subjects;
+        return $return;
     }
 
 }
-?>
+