MDL-20204 using url_select

This commit is contained in:
Petr Skoda 2010-02-10 10:55:51 +00:00
parent ab08be9839
commit f1a3e072fa
3 changed files with 27 additions and 81 deletions

View file

@ -332,7 +332,7 @@ function print_graded_users_selector($course, $actionpage, $userid=0, $groupid=0
*
* @return nothing or string if $return true
*/
function print_grade_plugin_selector($plugin_info, $return=false) {
function print_grade_plugin_selector($plugin_info, $active_type, $active_plugin, $return=false) {
global $CFG, $OUTPUT, $PAGE;
$menu = array();
@ -346,25 +346,33 @@ function print_grade_plugin_selector($plugin_info, $return=false) {
$first_plugin = reset($plugins);
$menu[$first_plugin->link.'&'] = '--'.$plugin_info['strings'][$plugin_type];
$sectionname = $plugin_info['strings'][$plugin_type];
$section = array();
if (empty($plugins->id)) {
foreach ($plugins as $plugin) {
$menu[$plugin->link] = $plugin->string;
$count++;
foreach ($plugins as $plugin) {
// TODO: this is messy, fix plugin_info instead...
$link = str_replace($CFG->wwwroot, '', $plugin->link);
$link = str_replace('&', '&', $link);
$section[$link] = $plugin->string;
$count++;
if ($plugin_type === $active_type and $plugin->id === $active_plugin) {
$active = $link;
}
}
if ($section) {
$menu[] = array($sectionname=>$section);
}
}
// finally print/return the popup form
if ($count > 1) {
$select = html_select::make_popup_form('', '', $menu, 'choosepluginreport', '');
$select->override_option_values($menu);
$select = new url_select($menu, $active, null, 'choosepluginreport');
if ($return) {
return $OUTPUT->select($select);
return $OUTPUT->render($select);
} else {
echo $OUTPUT->select($select);
echo $OUTPUT->render($select);
}
} else {
// only one option - no plugin selector needed
@ -865,7 +873,7 @@ function print_grade_page_head($courseid, $active_type, $active_plugin=null,
}
if ($CFG->grade_navmethod == GRADE_NAVMETHOD_COMBO || $CFG->grade_navmethod == GRADE_NAVMETHOD_DROPDOWN) {
$returnval .= print_grade_plugin_selector($plugin_info, $return);
$returnval .= print_grade_plugin_selector($plugin_info, $active_type, $active_plugin, $return);
}
$returnval .= $OUTPUT->heading($heading);

View file

@ -1498,50 +1498,6 @@ class html_select extends labelled_html_component {
return $select;
}
/**
* Override the URLs of the default popup_form, which only supports one base URL
* @param array $options value=>label pairs representing select options
* @return void
*/
public function override_option_values($options) {
// TODO: this is ugly hack because components shoudl never touch global $PAGE with the exception in prepare(),
// in any case this methods needs to be revisited because it does not make much sense to use the same $menu in
// html_select::make_popup_form() and then again in this method!
global $PAGE; //TODO: remove
$originalcount = count($options);
$this->initialise_options();
$newcount = count($this->options);
$first = true;
reset($options);
foreach ($this->options as $optkey => $optgroup) {
if ($optgroup instanceof html_select_optgroup) {
foreach ($optgroup->options as $key => $option) {
next($options);
$this->options[$optkey]->options[$key]->value = key($options);
$optionurl = new moodle_url(key($options));
if ($optionurl->compare($PAGE->url, URL_MATCH_PARAMS)) {
$this->options[$optkey]->options[$key]->selected = 'selected';
}
}
next($options);
} else if ($optgroup instanceof html_select_option && !($first && $originalcount < $newcount)) {
$this->options[$optkey]->value = key($options);
$optionurl = new moodle_url(key($options));
if ($optionurl->compare($PAGE->url, URL_MATCH_PARAMS)) {
$this->options[$optkey]->selected = 'selected';
}
next($options);
}
$first = false;
}
}
/**
* Adds a help icon next to the select menu.
*

View file

@ -230,7 +230,6 @@
} else {
$strsection = get_string("topic");
}
$section = -1;
$forummenu = array();
foreach ($modinfo->instances['forum'] as $forumcm) {
if (!$forumcm->uservisible || !has_capability('mod/forum:startdiscussion',
@ -238,37 +237,20 @@
continue;
}
if (!empty($forumcm->sectionnum) and $section != $forumcm->sectionnum) {
$forummenu[] = "-------------- $strsection $forumcm->sectionnum --------------";
}
$section = $forumcm->sectionnum;
if (empty($forummenu[$section])) {
$forummenu[$section] = array("$strsection $section" => array());
}
if ($forumcm->instance != $forum->id) {
$url = $CFG->wwwroot . "/mod/forum/discuss.php?d=$discussion->id&move=$forumcm->instance&sesskey=".sesskey();
$forummenu[$url] = format_string($forumcm->name);
$url = "/mod/forum/discuss.php?d=$discussion->id&move=$forumcm->instance&sesskey=".sesskey();
$forummenu[$section]["$strsection $section"][$url] = format_string($forumcm->name);
}
}
if (!empty($forummenu)) {
// Check for empty groups... This can occur if there is the forum we are in is
// the only forum within its course section.
foreach ($forummenu as $key=>$item) {
// If this option is a group and the next option is a group OR it is
// the last item in the array then remove it... or we get an exception
if (strpos($item, '--------------')===0 && (!array_key_exists($key+1, $forummenu) || strpos($forummenu[$key+1], '--------------')===0)) {
// Remember foreach acts on a copy of the array so things
// will not get out of order
unset($forummenu[$key]);
}
}
echo "<div style=\"float:right;\">";
$select = html_select::make_popup_form('', '', $forummenu, 'forummenu');
$select->nothinglabel = get_string("movethisdiscussionto", "forum");
$select->form->button->text = get_string('move');
$select->override_option_values($forummenu);
echo $OUTPUT->select($select);
$select = new url_select($forummenu, '', array(''=>get_string("movethisdiscussionto", "forum")), 'forummenu');
echo $OUTPUT->render($select);
echo "</div>";
}
}