From 66ef0471ae96c51b413649c7f9f37baec5e45b7c Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Wed, 15 Aug 2007 11:15:39 +0000 Subject: [PATCH] MDL-10838 Applied standard table classes and scopes to tr, th and tds of the grader report. Also fixed a bug with the display of grand averages when a group is selected and the average column is set to aggregate all grades. --- grade/lib.php | 18 ++++++++++++ grade/report/grader/index.php | 2 +- grade/report/grader/lib.php | 68 +++++++++++++++++++++++++++++-------------- 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/grade/lib.php b/grade/lib.php index 84d49cfda..bd3faafb7 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -432,6 +432,24 @@ function grade_build_nav($path, $pagename=null, $id=null) { } /** + * Computes then returns the percentage value of the grade value within the given range. + * @param float $gradeval + * @param float $grademin + * @param float $grademx + * @return float $percentage + */ +function grade_to_percentage($gradeval, $grademin, $grademax) { + if ($grademin >= $grademax) { + debugging("The minimum grade ($grademin) was higher than or equal to the maximum grade ($grademax)!!! Cannot proceed with computation."); + } + $offset_value = $gradeval - $grademin; + $offset_max = $grademax - $grademin; + $factor = 100 / $offset_max; + $percentage = $offset_value * $factor; + return $percentage; +} + +/** * This class represents a complete tree of categories, grade_items and final grades, * organises as an array primarily, but which can also be converted to other formats. * It has simple method calls with complex implementations, allowing for easy insertion, diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php index 00e77d759..b72f6c260 100644 --- a/grade/report/grader/index.php +++ b/grade/report/grader/index.php @@ -153,7 +153,7 @@ echo '
'; echo $report->get_toggles_html(); print_paging_bar($numusers, $report->page, $report->get_pref('studentsperpage'), $report->pbarurl); -$reporthtml = ''; +$reporthtml = '
'; $reporthtml .= $report->get_headerhtml(); $reporthtml .= $report->get_rangehtml(); $reporthtml .= $report->get_studentshtml(); diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index c1a99b693..c46dab48a 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -58,6 +58,12 @@ class grade_report_grader extends grade_report { var $collapsed; /** + * A count of the rows, used for css classes. + * @var int $rowcount + */ + var $rowcount = 0; + + /** * Constructor. Sets local copies of user preferences and initialises grade_tree. * @param int $courseid * @param object $gpr grade plugin return tracking object @@ -261,19 +267,24 @@ class grade_report_grader extends grade_report { /** * Fetches and returns a count of all the users that will be shown on this page. + * @param bool $groups Whether to apply groupsql * @return int Count of users */ - function get_numusers() { + function get_numusers($groups=true) { global $CFG; $countsql = "SELECT COUNT(DISTINCT u.id) FROM {$CFG->prefix}grade_grades g RIGHT OUTER JOIN {$CFG->prefix}user u ON (u.id = g.userid AND g.itemid = $this->sortitemid) - LEFT JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid - $this->groupsql - WHERE ra.roleid in ($this->gradebookroles) - $this->groupwheresql - AND ra.contextid ".get_related_contexts_string($this->context); + LEFT JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid "; + if ($groups) { + $countsql .= $this->groupsql; + } + $countsql .= " WHERE ra.roleid in ($this->gradebookroles) "; + if ($groups) { + $countsql .= $this->groupwheresql; + } + $countsql .= " AND ra.contextid ".get_related_contexts_string($this->context); return count_records_sql($countsql); } @@ -423,19 +434,22 @@ class grade_report_grader extends grade_report { $columns_to_unset = array(); + foreach ($this->gtree->levels as $key=>$row) { + $columncount = 0; if ($key == 0) { // do not display course grade category // continue; } - $headerhtml .= ''; + $headerhtml .= ''; if ($key == $numrows - 1) { - $headerhtml .= ''; } else { - $headerhtml .= ''; + $headerhtml .= ''; } foreach ($row as $columnkey => $element) { @@ -451,8 +465,10 @@ class grade_report_grader extends grade_report { $itemmodule = null; $iteminstance = null; + $columnclass = 'c' . $columncount++; if (!empty($element['colspan'])) { $colspan = 'colspan="'.$element['colspan'].'"'; + $columnclass = ''; } else { $colspan = ''; } @@ -465,11 +481,12 @@ class grade_report_grader extends grade_report { // Element is a filler if ($type == 'filler' or $type == 'fillerfirst' or $type == 'fillerlast') { - $headerhtml .= ''; + $headerhtml .= ''; } // Element is a category else if ($type == 'category') { - $headerhtml .= ''; $this->items[$element['object']->sortorder] =& $element['object']; @@ -554,13 +571,15 @@ class grade_report_grader extends grade_report { } foreach ($this->users as $userid => $user) { + $columncount = 0; // Student name and link $user_pic = null; if ($showuserimage) { $user_pic = '
' . print_user_picture($user->id, $this->courseid, true, 0, true) . '
'; } - $studentshtml .= ''; foreach ($this->items as $itemid=>$item) { @@ -587,9 +606,9 @@ class grade_report_grader extends grade_report { $element = array('eid'=>$eid, 'object'=>$grade, 'type'=>'grade'); if ($grade->is_overridden()) { - $studentshtml .= ''; + + $avghtml = ''; + + $columncount=1; foreach ($this->items as $item) { $decimalpoints = $this->get_pref('decimalpoints', $item->id); // Determine which display type to use for this average @@ -835,7 +856,7 @@ class grade_report_grader extends grade_report { } if (empty($count_array[$item->id]) || !isset($sum_array[$item->id])) { - $avghtml .= ''; + $avghtml .= ''; } else { $sum = $sum_array[$item->id]; @@ -866,7 +887,7 @@ class grade_report_grader extends grade_report { $gradehtml = grade_grade::get_letter($letters, $gradeval, $item->grademin, $item->grademax); } - $avghtml .= ''; + $avghtml .= ''; } } $avghtml .= ''; @@ -885,9 +906,12 @@ class grade_report_grader extends grade_report { if ($this->get_pref('showranges')) { $rangesdisplaytype = $this->get_pref('rangesdisplaytype'); $rangesdecimalpoints = $this->get_pref('rangesdecimalpoints'); - $scalehtml = ''; + $scalehtml = '' + . ''; + $columncount = 1; foreach ($this->items as $item) { + $decimalpoints = $this->get_pref('decimalpoints', $item->id); // Determine which display type to use for this range $gradedisplaytype = $this->get_pref('gradedisplaytype', $item->id); @@ -916,7 +940,7 @@ class grade_report_grader extends grade_report { $grademax = reset($letters); } - $scalehtml .= ''; + $scalehtml .= ''; } $scalehtml .= ''; } -- 2.11.4.GIT
' . $strfirstname . ' ' //TODO: localize + $headerhtml .= '' + . $strfirstname . ' ' //TODO: localize . $firstarrow. '/ ' . $strlastname . ''. $lastarrow .'    '.$element['object']->get_name(); + $headerhtml .= '' + . $element['object']->get_name(); $headerhtml .= $this->get_collapsing_icon($element); // Print icons @@ -509,7 +526,7 @@ class grade_report_grader extends grade_report { } $headerlink = $this->get_module_link($element['object']->get_name(), $itemmodule, $iteminstance); - $headerhtml .= ''. $headerlink . $arrow; + $headerhtml .= ''. $headerlink . $arrow; $headerhtml .= $this->get_icons($element) . '
' . $user_pic . 'rowcount++.'">' . $user_pic + . '' . fullname($user) . ''; + $studentshtml .= ''; } else { - $studentshtml .= ''; + $studentshtml .= ''; } if ($grade->is_excluded()) { @@ -768,7 +787,7 @@ class grade_report_grader extends grade_report { if ($meanselection == GRADE_AGGREGATE_MEAN_GRADED) { $totalcount = 0; } else { - $totalcount = $this->get_numusers(); + $totalcount = $this->get_numusers(false); } if ($showaverages) { @@ -804,7 +823,6 @@ class grade_report_grader extends grade_report { AND ra.contextid ".get_related_contexts_string($this->context)." ) GROUP BY g.itemid"; - $sum_array = array(); $count_array = array(); if ($sums = get_records_sql($SQL)) { @@ -817,7 +835,10 @@ class grade_report_grader extends grade_report { } } } - $avghtml = '
'.$straverage.'
'.$straverage.'--'.$gradehtml.''.$gradehtml.'
'.$this->get_lang_string('range','grades').'
'.$this->get_lang_string('range','grades').''. $grademin.'-'. $grademax.''. $grademin.'-'. $grademax.'