From: toyomoyo Date: Mon, 16 Jul 2007 06:01:19 +0000 (+0000) Subject: fix for MDL-10345, use averages instead of totals X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ac04f85d8209f686115ee0e79e9fee2c4fdefe00;p=moodle.git fix for MDL-10345, use averages instead of totals --- diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php index 8a081bdb9d..5214f6db08 100644 --- a/grade/report/grader/index.php +++ b/grade/report/grader/index.php @@ -65,8 +65,8 @@ $reporthtml = ''; $reporthtml .= $report->get_headerhtml(); $reporthtml .= $report->get_scalehtml(); $reporthtml .= $report->get_studentshtml(); -$reporthtml .= $report->get_groupsumhtml(); -$reporthtml .= $report->get_gradesumhtml(); +$reporthtml .= $report->get_groupavghtml(); +$reporthtml .= $report->get_gradeavghtml($numusers); $reporthtml .= "
"; // print submit button if ($USER->gradeediting) { diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index 68e1474a80..2784f972cb 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -333,15 +333,23 @@ class grade_report_grader extends grade_report { * Fetches and returns a count of all the users that will be shows on this page. * @return int Count of users */ - function get_numusers() { + function get_numusers($group=true) { global $CFG; + + if ($group) { + $groupsql = $this->groupsql; + $groupsqlwhere = $this->groupwheresql; + } else { + $groupsql = ''; + $groupsqlwhere = ''; + } $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 + $groupsql WHERE ra.roleid in ($this->gradebookroles) - $this->groupwheresql + $groupsqlwhere AND ra.contextid ".get_related_contexts_string($this->context); return count_records_sql($countsql); } @@ -723,14 +731,15 @@ class grade_report_grader extends grade_report { * Builds and return the HTML rows of the table (grades headed by student). * @return string HTML */ - function get_groupsumhtml() { + function get_groupavghtml() { global $CFG; - $groupsumhtml = ''; - + $groupavghtml = ''; + $numusers = $this->get_numusers(true); // find number of users in this group if ($this->currentgroup && $this->get_pref('showgroups')) { /** SQL for finding group sum */ + // do not sum -1 (no grade), treat as 0 for now $SQL = "SELECT g.itemid, SUM(g.finalgrade) as sum FROM {$CFG->prefix}grade_items gi LEFT JOIN {$CFG->prefix}grade_grades g ON gi.id = g.itemid RIGHT OUTER JOIN @@ -741,6 +750,7 @@ class grade_report_grader extends grade_report { $this->groupwheresql AND ra.roleid in ($this->gradebookroles) AND ra.contextid ".get_related_contexts_string($this->context)." + AND g.finalgrade >= 0 GROUP BY g.itemid"; $groupsum = array(); @@ -749,32 +759,50 @@ class grade_report_grader extends grade_report { $groupsum[$itemid] = $csum; } - $groupsumhtml = 'Group total'; + $groupavghtml = ''.get_string('groupavg', 'grades').''; foreach ($this->items as $item) { if (!isset($groupsum[$item->id])) { - $groupsumhtml .= '-'; + $groupavghtml .= '-'; } else { $sum = $groupsum[$item->id]; - $groupsumhtml .= ''.$this->get_grade_clean($sum->sum).''; + + if ($item->scaleid) { + $scaleval = round($this->get_grade_clean($sum->sum/$numusers)); + $scales_array = get_records_list('scale', 'id', $item->scaleid); + $scale = $scales_array[$item->scaleid]; + $scales = explode(",", $scale->scale); + + // this could be a 0 when summed and rounded, e.g, 1, no grade, no grade, no grade + if ($scaleval < 1) { + $scaleval = 1; + } + + $gradehtml = $scales[$scaleval-1]; + } else { + $gradeval = $this->get_grade_clean($sum->sum/$numusers); + $gradehtml = $gradeval; + } + $groupavghtml .= ''.$gradehtml.''; } } - $groupsumhtml .= ''; + $groupavghtml .= ''; } - return $groupsumhtml; + return $groupavghtml; } /** * Builds and return the HTML row of column totals. * @return string HTML */ - function get_gradesumhtml() { + function get_gradeavghtml() { global $CFG; - $gradesumhtml = ''; + $gradeavghtml = ''; + $numusers = $this->get_numusers(false); // find total number of users, without group constraint if ($this->get_pref('showgrandtotals')) { /** SQL for finding the SUM grades of all visible users ($CFG->gradebookroles) */ - + // do not sum -1 (no grade), treat as 0 for now $SQL = "SELECT g.itemid, SUM(g.finalgrade) as sum FROM {$CFG->prefix}grade_items gi LEFT JOIN {$CFG->prefix}grade_grades g ON gi.id = g.itemid RIGHT OUTER JOIN @@ -783,6 +811,7 @@ class grade_report_grader extends grade_report { WHERE gi.courseid = $this->courseid AND ra.roleid in ($this->gradebookroles) AND ra.contextid ".get_related_contexts_string($this->context)." + AND g.finalgrade >= 0 GROUP BY g.itemid"; $classsum = array(); @@ -791,18 +820,35 @@ class grade_report_grader extends grade_report { $classsum[$itemid] = $csum; } - $gradesumhtml = 'Total'; + $gradeavghtml = ''.get_string('average').''; foreach ($this->items as $item) { if (!isset($classsum[$item->id])) { - $gradesumhtml .= '-'; + $gradeavghtml .= '-'; } else { $sum = $classsum[$item->id]; - $gradesumhtml .= ''.$this->get_grade_clean($sum->sum).''; + + if ($item->scaleid) { + $scaleval = round($this->get_grade_clean($sum->sum/$numusers)); + $scales_array = get_records_list('scale', 'id', $item->scaleid); + $scale = $scales_array[$item->scaleid]; + $scales = explode(",", $scale->scale); + + // this could be a 0 when summed and rounded, e.g, 1, no grade, no grade, no grade + if ($scaleval < 1) { + $scaleval = 1; + } + + $gradehtml = $scales[$scaleval-1]; + } else { + $gradeval = $this->get_grade_clean($sum->sum/$numusers); + $gradehtml = $gradeval; + } + $gradeavghtml .= ''.$gradehtml.''; } } - $gradesumhtml .= ''; + $gradeavghtml .= ''; } - return $gradesumhtml; + return $gradeavghtml; } /**