Merge branch 'MDL-57090-master' of git://github.com/ankitagarwal/moodle

This commit is contained in:
David Monllao 2016-11-30 10:43:16 +08:00
commit c5a5f26ce2
3 changed files with 9 additions and 47 deletions

View 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 = "  " . $option;
} else if ($keylength == 12) {
$option = "    " . $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();

View 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 = "  " . $option;
} else if ($keylength == 12) {
$option = "    " . $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');

View 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;
}
}
?>