MFC: MDL-11718 partial cleanup in overview report - unfortunately the problems with hidden grades can not be solved here without db changes
This commit is contained in:
@@ -88,9 +88,6 @@ if ($access) {
|
||||
// Create a report instance
|
||||
$report = new grade_report_overview($userid, $gpr, $context);
|
||||
|
||||
$gradetotal = 0;
|
||||
$gradesum = 0;
|
||||
|
||||
// print the page
|
||||
print_heading(get_string('modulename', 'gradereport_overview'). ' - '.fullname($report->user));
|
||||
|
||||
|
||||
@@ -49,6 +49,11 @@ class grade_report_overview extends grade_report {
|
||||
*/
|
||||
var $table;
|
||||
|
||||
/**
|
||||
* show student ranks
|
||||
*/
|
||||
var $showrank;
|
||||
|
||||
/**
|
||||
* Constructor. Sets local copies of user preferences and initialises grade_tree.
|
||||
* @param int $userid
|
||||
@@ -59,6 +64,8 @@ class grade_report_overview extends grade_report {
|
||||
global $CFG, $COURSE;
|
||||
parent::grade_report($COURSE->id, $gpr, $context);
|
||||
|
||||
$this->showrank = grade_get_setting($this->courseid, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank));
|
||||
|
||||
// get the user (for full name)
|
||||
$this->user = get_record('user', 'id', $userid);
|
||||
|
||||
@@ -74,16 +81,21 @@ class grade_report_overview extends grade_report {
|
||||
*/
|
||||
function setup_table() {
|
||||
/*
|
||||
* Table has 3 columns
|
||||
*| course | final grade | rank |
|
||||
*/
|
||||
* Table has 3 columns
|
||||
*| course | final grade | rank (optional) |
|
||||
*/
|
||||
|
||||
// setting up table headers
|
||||
$tablecolumns = array('coursename', 'grade', 'rank');
|
||||
$tableheaders = array($this->get_lang_string('coursename', 'grades'),
|
||||
$this->get_lang_string('grade'),
|
||||
$this->get_lang_string('rank', 'grades'));
|
||||
|
||||
if ($this->showrank) {
|
||||
$tablecolumns = array('coursename', 'grade', 'rank');
|
||||
$tableheaders = array($this->get_lang_string('coursename', 'grades'),
|
||||
$this->get_lang_string('grade'),
|
||||
$this->get_lang_string('rank', 'grades'));
|
||||
} else {
|
||||
$tablecolumns = array('coursename', 'grade');
|
||||
$tableheaders = array($this->get_lang_string('coursename', 'grades'),
|
||||
$this->get_lang_string('grade'));
|
||||
}
|
||||
$this->table = new flexible_table('grade-report-overview-'.$this->user->id);
|
||||
|
||||
$this->table->define_columns($tablecolumns);
|
||||
@@ -99,45 +111,52 @@ class grade_report_overview extends grade_report {
|
||||
|
||||
function fill_table() {
|
||||
global $CFG;
|
||||
$numusers = $this->get_numusers();
|
||||
|
||||
// if ($courses = get_courses('all', null, 'c.id, c.shortname')) {
|
||||
// MDL-11679, only show 'mycourses' instead of all courses
|
||||
if ($courses = get_my_courses($this->user->id, 'c.sortorder ASC', 'id, shortname')) {
|
||||
$numusers = $this->get_numusers();
|
||||
|
||||
foreach ($courses as $course) {
|
||||
$courselink = '<a href="'.$CFG->wwwroot.'/grade/report/user/index.php?id='.$course->id.'">'.$course->shortname.'</a>';
|
||||
|
||||
// Get course grade_item
|
||||
if (!$grade_item = grade_item::fetch(array('itemtype' => 'course', 'courseid' => $course->id))) {
|
||||
// Create the course item if it doesn't already exist.
|
||||
$coursecat = grade_category::fetch_course_category($course->id);
|
||||
$grade_item = $coursecat->get_grade_item();
|
||||
}
|
||||
$grade_item = grade_item::fetch_course_item($course->id);
|
||||
|
||||
// Get the grade
|
||||
$finalgrade = get_field('grade_grades', 'finalgrade', 'itemid', $grade_item->id, 'userid', $this->user->id);
|
||||
$grade = new grade_grade(array('itemid'=>$grade_item->id, 'userid'=>$this->user->id));
|
||||
$grade->grade_item =& $grade_item;
|
||||
$finalgrade = $grade->finalgrade;
|
||||
|
||||
/// prints rank
|
||||
if ($finalgrade) {
|
||||
/// find the number of users with a higher grade
|
||||
$sql = "SELECT COUNT(DISTINCT(userid))
|
||||
FROM {$CFG->prefix}grade_grades
|
||||
WHERE finalgrade > $finalgrade
|
||||
AND itemid = $grade_item->id";
|
||||
$rank = count_records_sql($sql) + 1;
|
||||
|
||||
$rankdata = "$rank/$numusers";
|
||||
} else {
|
||||
// no grade, no rank
|
||||
$rankdata = "-";
|
||||
// TODO: this DOES NOT work properly if there are any hidden grades,
|
||||
// rank might be wrong & totals might be different from user report!!!
|
||||
if ($grade->is_hidden() and !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
$finalgrade = null;
|
||||
}
|
||||
|
||||
$courselink = '<a href="' . $CFG->wwwroot . '/grade/report/user/index.php?id=' . $course->id . '">' . $course->shortname . '</a>';
|
||||
$data = array($courselink, grade_format_gradevalue($finalgrade, $grade_item, true));
|
||||
|
||||
$this->table->add_data(array($courselink,
|
||||
round(grade_to_percentage($finalgrade, $grade_item->grademin, $grade_item->grademax), 1) . '%',
|
||||
$rankdata));
|
||||
if (!$this->showrank) {
|
||||
//nothing to do
|
||||
|
||||
} else if (!is_null($finalgrade)) {
|
||||
/// find the number of users with a higher grade
|
||||
$sql = "SELECT COUNT(DISTINCT(userid))
|
||||
FROM {$CFG->prefix}grade_grades
|
||||
WHERE finalgrade IS NOT NULL AND finalgrade > $finalgrade
|
||||
AND itemid = {$grade_item->id}";
|
||||
$rank = count_records_sql($sql) + 1;
|
||||
|
||||
$data[] = "$rank/$numusers";
|
||||
|
||||
} else {
|
||||
// no grade, no rank
|
||||
$data[] = '-';
|
||||
}
|
||||
|
||||
$this->table->add_data($data);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
notify(get_string('nocourses', 'grades'));
|
||||
return false;
|
||||
@@ -167,6 +186,24 @@ class grade_report_overview extends grade_report {
|
||||
*/
|
||||
function process_data($data) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function grade_report_overview_settings_definition(&$mform) {
|
||||
global $CFG;
|
||||
|
||||
$options = array(-1 => get_string('default', 'grades'),
|
||||
0 => get_string('hide'),
|
||||
1 => get_string('show'));
|
||||
|
||||
if (empty($CFG->grade_overviewreport_showrank)) {
|
||||
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
||||
} else {
|
||||
$options[-1] = get_string('defaultprev', 'grades', $options[1]);
|
||||
}
|
||||
|
||||
$mform->addElement('select', 'report_overview_showrank', get_string('showrank', 'grades'), $options);
|
||||
$mform->setHelpButton('report_overview_showrank', array(false, get_string('showrank', 'grades'),
|
||||
false, true, false, get_string('configshowrank', 'grades')));
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php // $Id$
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// NOTICE OF COPYRIGHT //
|
||||
// //
|
||||
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
|
||||
// http://moodle.com //
|
||||
// //
|
||||
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
|
||||
// //
|
||||
// This program is free software; you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation; either version 2 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// This program is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details: //
|
||||
// //
|
||||
// http://www.gnu.org/copyleft/gpl.html //
|
||||
// //
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// Add settings for this module to the $settings object (it's already defined)
|
||||
|
||||
$settings->add(new admin_setting_configcheckbox('grade_report_overview_showrank', get_string('showrank', 'grades'), get_string('configshowrank', 'grades'), 0, PARAM_INT));
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user