MDL-72873 core_grades: Deprecate unused methods

The functions grade_print_tabs() and print_grade_plugin_selector()
can be deprecated as they are no longer used. These functions were
used to generate and output the tabs and dropdown box navigation
in gradebook which is now replaced with tertiary navigation.
This commit is contained in:
Mihail Geshoski 2021-10-27 12:00:52 +08:00
parent eb0b022bb7
commit 95b35652d3
3 changed files with 147 additions and 135 deletions

View File

@ -705,141 +705,6 @@ function print_natural_aggregation_upgrade_notice($courseid, $context, $thispage
}
}
/**
* Print grading plugin selection popup form.
*
* @param array $plugin_info An array of plugins containing information for the selector
* @param boolean $return return as string
*
* @return nothing or string if $return true
*/
function print_grade_plugin_selector($plugin_info, $active_type, $active_plugin, $return=false) {
global $CFG, $OUTPUT, $PAGE;
$menu = array();
$count = 0;
$active = '';
foreach ($plugin_info as $plugin_type => $plugins) {
if ($plugin_type == 'strings') {
continue;
}
$first_plugin = reset($plugins);
$sectionname = $plugin_info['strings'][$plugin_type];
$section = array();
foreach ($plugins as $plugin) {
$link = $plugin->link->out(false);
$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 = new url_select($menu, $active, null, 'choosepluginreport');
$select->set_label(get_string('gradereport', 'grades'), array('class' => 'accesshide'));
if ($return) {
return $OUTPUT->render($select);
} else {
echo $OUTPUT->render($select);
}
} else {
// only one option - no plugin selector needed
return '';
}
}
/**
* Print grading plugin selection tab-based navigation.
*
* @param string $active_type type of plugin on current page - import, export, report or edit
* @param string $active_plugin active plugin type - grader, user, cvs, ...
* @param array $plugin_info Array of plugins
* @param boolean $return return as string
*
* @return nothing or string if $return true
*/
function grade_print_tabs($active_type, $active_plugin, $plugin_info, $return=false) {
global $CFG, $COURSE;
if (!isset($currenttab)) { //TODO: this is weird
$currenttab = '';
}
$tabs = array();
$top_row = array();
$bottom_row = array();
$inactive = array($active_plugin);
$activated = array($active_type);
$count = 0;
$active = '';
foreach ($plugin_info as $plugin_type => $plugins) {
if ($plugin_type == 'strings') {
continue;
}
// If $plugins is actually the definition of a child-less parent link:
if (!empty($plugins->id)) {
$string = $plugins->string;
if (!empty($plugin_info[$active_type]->parent)) {
$string = $plugin_info[$active_type]->parent->string;
}
$top_row[] = new tabobject($plugin_type, $plugins->link, $string);
continue;
}
$first_plugin = reset($plugins);
$url = $first_plugin->link;
if ($plugin_type == 'report') {
$url = $CFG->wwwroot.'/grade/report/index.php?id='.$COURSE->id;
}
$top_row[] = new tabobject($plugin_type, $url, $plugin_info['strings'][$plugin_type]);
if ($active_type == $plugin_type) {
foreach ($plugins as $plugin) {
$bottom_row[] = new tabobject($plugin->id, $plugin->link, $plugin->string);
if ($plugin->id == $active_plugin) {
$inactive = array($plugin->id);
}
}
}
}
// Do not display rows that contain only one item, they are not helpful.
if (count($top_row) > 1) {
$tabs[] = $top_row;
}
if (count($bottom_row) > 1) {
$tabs[] = $bottom_row;
}
if (empty($tabs)) {
return;
}
$rv = html_writer::div(print_tabs($tabs, $active_plugin, $inactive, $activated, true), 'grade-navigation');
if ($return) {
return $rv;
} else {
echo $rv;
}
}
/**
* grade_get_plugin_info
*

View File

@ -3,6 +3,10 @@ Information provided here is intended especially for developers.
=== 4.0 ===
* The print_grade_plugin_selector() function has been deprecated. This function was used to generate and output the
dropdown box navigation in gradebook which is now replaced with tertiary navigation.
* The grade_print_tabs() function has been deprecated. This function was used to generate and output the tabs navigation
in gradebook which is now replaced with tertiary navigation.
* There is a new callback inside of grade_get_plugin_info called extend_gradebook_plugininfo
which allows for new tabs to be added to the gradebook.

View File

@ -3542,3 +3542,146 @@ function calendar_import_icalendar_events($ical, $unused = null, $subscriptionid
$return .= html_writer::end_tag('ul');
return $return;
}
/**
* Print grading plugin selection tab-based navigation.
*
* @deprecated since Moodle 4.0. Tabs navigation has been replaced with tertiary navigation.
* @param string $active_type type of plugin on current page - import, export, report or edit
* @param string $active_plugin active plugin type - grader, user, cvs, ...
* @param array $plugin_info Array of plugins
* @param boolean $return return as string
*
* @return nothing or string if $return true
*/
function grade_print_tabs($active_type, $active_plugin, $plugin_info, $return=false) {
global $CFG, $COURSE;
debugging('grade_print_tabs() has been deprecated. Tabs navigation has been replaced with tertiary navigation.',
DEBUG_DEVELOPER);
if (!isset($currenttab)) { //TODO: this is weird
$currenttab = '';
}
$tabs = array();
$top_row = array();
$bottom_row = array();
$inactive = array($active_plugin);
$activated = array($active_type);
$count = 0;
$active = '';
foreach ($plugin_info as $plugin_type => $plugins) {
if ($plugin_type == 'strings') {
continue;
}
// If $plugins is actually the definition of a child-less parent link:
if (!empty($plugins->id)) {
$string = $plugins->string;
if (!empty($plugin_info[$active_type]->parent)) {
$string = $plugin_info[$active_type]->parent->string;
}
$top_row[] = new tabobject($plugin_type, $plugins->link, $string);
continue;
}
$first_plugin = reset($plugins);
$url = $first_plugin->link;
if ($plugin_type == 'report') {
$url = $CFG->wwwroot.'/grade/report/index.php?id='.$COURSE->id;
}
$top_row[] = new tabobject($plugin_type, $url, $plugin_info['strings'][$plugin_type]);
if ($active_type == $plugin_type) {
foreach ($plugins as $plugin) {
$bottom_row[] = new tabobject($plugin->id, $plugin->link, $plugin->string);
if ($plugin->id == $active_plugin) {
$inactive = array($plugin->id);
}
}
}
}
// Do not display rows that contain only one item, they are not helpful.
if (count($top_row) > 1) {
$tabs[] = $top_row;
}
if (count($bottom_row) > 1) {
$tabs[] = $bottom_row;
}
if (empty($tabs)) {
return;
}
$rv = html_writer::div(print_tabs($tabs, $active_plugin, $inactive, $activated, true), 'grade-navigation');
if ($return) {
return $rv;
} else {
echo $rv;
}
}
/**
* Print grading plugin selection popup form.
*
* @deprecated since Moodle 4.0. Dropdown box navigation has been replaced with tertiary navigation.
* @param array $plugin_info An array of plugins containing information for the selector
* @param boolean $return return as string
*
* @return nothing or string if $return true
*/
function print_grade_plugin_selector($plugin_info, $active_type, $active_plugin, $return=false) {
global $CFG, $OUTPUT, $PAGE;
debugging('print_grade_plugin_selector() has been deprecated. Dropdown box navigation has been replaced ' .
'with tertiary navigation.', DEBUG_DEVELOPER);
$menu = array();
$count = 0;
$active = '';
foreach ($plugin_info as $plugin_type => $plugins) {
if ($plugin_type == 'strings') {
continue;
}
$first_plugin = reset($plugins);
$sectionname = $plugin_info['strings'][$plugin_type];
$section = array();
foreach ($plugins as $plugin) {
$link = $plugin->link->out(false);
$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 = new url_select($menu, $active, null, 'choosepluginreport');
$select->set_label(get_string('gradereport', 'grades'), array('class' => 'accesshide'));
if ($return) {
return $OUTPUT->render($select);
} else {
echo $OUTPUT->render($select);
}
} else {
// only one option - no plugin selector needed
return '';
}
}