MDL-10544 support for outcomes showing/hiding in grader report

This commit is contained in:
skodak 2007-08-08 08:31:04 +00:00
parent 9e5fe95780
commit aea4df411e
3 changed files with 54 additions and 10 deletions

View File

@ -470,7 +470,7 @@ class grade_tree {
* @param boolean $category_grade_last category grade item is the last child
* @param array $collapsed array of collapsed categories
*/
function grade_tree($courseid, $fillers=true, $category_grade_last=false, $collapsed=null) {
function grade_tree($courseid, $fillers=true, $category_grade_last=false, $collapsed=null, $nooutcomes=false) {
global $USER, $CFG;
$this->courseid = $courseid;
@ -486,6 +486,11 @@ class grade_tree {
grade_tree::category_collapse($this->top_element, $collapsed);
}
// no otucomes if requested
if (!empty($nooutcomes)) {
grade_tree::no_outcomes($this->top_element);
}
// move category item to last position in category
if ($category_grade_last) {
grade_tree::category_grade_last($this->top_element);
@ -527,6 +532,27 @@ class grade_tree {
}
}
/**
* Static recursive helper - removes all outcomes
* @static
* @param array $element The seed of the recursion
* @return void
*/
function no_outcomes(&$element) {
if ($element['type'] != 'category') {
return;
}
foreach ($element['children'] as $sortorder=>$child) {
if ($element['children'][$sortorder]['type'] == 'item'
and $element['children'][$sortorder]['object']->is_outcome_item()) {
unset($element['children'][$sortorder]);
} else if ($element['children'][$sortorder]['type'] == 'category') {
grade_tree::no_outcomes($element['children'][$sortorder]);
}
}
}
/**
* Static recursive helper - makes the grade_item for category the last children
* @static

View File

@ -80,8 +80,14 @@ class grade_report_grader extends grade_report {
} else {
$this->collapsed = array();
}
if (empty($CFG->enableoutcomes)) {
$nooutcomes = false;
} else {
$nooutcomes = get_user_preferences('grade_report_shownooutcomes');
}
// Grab the grade_tree for this course
$this->gtree = new grade_tree($this->courseid, true, $this->get_pref('aggregationposition'), $this->collapsed);
$this->gtree = new grade_tree($this->courseid, true, $this->get_pref('aggregationposition'), $this->collapsed, $nooutcomes);
$this->sortitemid = $sortitemid;
@ -306,7 +312,8 @@ class grade_report_grader extends grade_report {
* @return string HTML code
*/
function get_toggles_html() {
global $USER;
global $CFG, $USER;
$html = '<div id="grade-report-toggles">';
if ($USER->gradeediting[$this->courseid]) {
if (has_capability('moodle/grade:manage', $this->context) or has_capability('moodle/grade:hide', $this->context)) {
@ -325,6 +332,9 @@ class grade_report_grader extends grade_report {
$html .= $this->print_toggle('averages', true);
$html .= $this->print_toggle('groups', true);
$html .= $this->print_toggle('ranges', true);
if (!empty($CFG->enableoutcomes)) {
$html .= $this->print_toggle('nooutcomes', true);
}
$html .= '</div>';
return $html;
}
@ -338,13 +348,19 @@ class grade_report_grader extends grade_report {
function print_toggle($type, $return=false) {
global $CFG;
$icons = array('eyecons' => 'hide',
'calculations' => 'calc',
'locks' => 'lock',
'averages' => 'sigma');
$icons = array('eyecons' => 't/hide.gif',
'calculations' => 't/calc.gif',
'locks' => 't/lock.gif',
'averages' => 't/sigma.gif',
'nooutcomes' => 'i/outcomes.gif');
$pref_name = 'grade_report_show' . $type;
if (array_key_exists($pref_name, $CFG)) {
$show_pref = get_user_preferences($pref_name, $CFG->$pref_name);
} else {
$show_pref = get_user_preferences($pref_name);
}
$strshow = $this->get_lang_string('show' . $type, 'grades');
$strhide = $this->get_lang_string('hide' . $type, 'grades');
@ -360,12 +376,12 @@ class grade_report_grader extends grade_report {
if (array_key_exists($type, $icons)) {
$image_name = $icons[$type];
} else {
$image_name = $type;
$image_name = "t/$type.gif";
}
$string = ${'str' . $show_hide};
$img = '<img src="'.$CFG->pixpath.'/t/'.$image_name.'.gif" class="iconsmall" alt="'
$img = '<img src="'.$CFG->pixpath.'/'.$image_name.'" class="iconsmall" alt="'
.$string.'" title="'.$string.'" />'. "\n";
$retval = '<div class="gradertoggle">' . $img . '<a href="' . $this->baseurl . "&amp;toggle=$toggle_action&amp;toggle_type=$type\">"

View File

@ -185,6 +185,7 @@ $string['hideeyecons'] = 'Hide show/hide icons';
$string['hideaverages'] = 'Hide averages';
$string['hidegroups'] = 'Hide groups';
$string['hidelocks'] = 'Hide locks';
$string['hidenooutcomes'] = 'Show outcomes';
$string['hidefeedback'] = 'Hide feedback';
$string['hideranges'] = 'Hide ranges';
$string['highgradeascending'] = 'Sort by high grade ascending';
@ -329,6 +330,7 @@ $string['showfeedback'] = 'Show feedback';
$string['showgroups'] = 'Show groups';
$string['showhiddenitems'] = 'Show Hidden Items';
$string['showlocks'] = 'Show locks';
$string['shownooutcomes'] = 'Hide outcomes';
$string['showranges'] = 'Show ranges';
$string['showuserimage'] = 'Show user profile images';
$string['sitedefault'] = 'Site default ($a)';