From aea4df411ed310e176afe225fd7b9887deb3f7b2 Mon Sep 17 00:00:00 2001 From: skodak Date: Wed, 8 Aug 2007 08:31:04 +0000 Subject: [PATCH] MDL-10544 support for outcomes showing/hiding in grader report --- grade/lib.php | 28 +++++++++++++++++++++++++++- grade/report/grader/lib.php | 34 +++++++++++++++++++++++++--------- lang/en_utf8/grades.php | 2 ++ 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/grade/lib.php b/grade/lib.php index 7712f6cde9f..9ecbbddbb11 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -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 diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index fee2b93df26..710d0f53cfc 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -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 = '
'; 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 .= '
'; 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; - $show_pref = get_user_preferences($pref_name, $CFG->$pref_name); + + 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 = '<img src=pixpath.'/'.$image_name.'" class="iconsmall" alt="' .$string.'" title="'.$string.'" />'. "\n"; $retval = '
' . $img . '" diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index 0497ecb9d69..18cdd5c1954 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -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)';