3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.com //
10 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
26 * File in which the overview_report class is defined.
30 require_once($CFG->dirroot
. '/grade/report/lib.php');
31 require_once($CFG->libdir
.'/tablelib.php');
34 * Class providing an API for the overview report building and displaying.
38 class grade_report_overview
extends grade_report
{
47 * A flexitable to hold the data.
58 * Constructor. Sets local copies of user preferences and initialises grade_tree.
60 * @param object $gpr grade plugin return tracking object
61 * @param string $context
63 function grade_report_overview($userid, $gpr, $context) {
65 parent
::grade_report($COURSE->id
, $gpr, $context);
67 $this->showrank
= grade_get_setting($this->courseid
, 'report_overview_showrank', !empty($CFG->grade_report_overview_showrank
));
69 // get the user (for full name)
70 $this->user
= get_record('user', 'id', $userid);
72 // base url for sorting by first/last name
73 $this->baseurl
= $CFG->wwwroot
.'/grade/overview/index.php?id='.$userid;
74 $this->pbarurl
= $this->baseurl
;
80 * Prepares the headers and attributes of the flexitable.
82 function setup_table() {
85 *| course | final grade | rank (optional) |
88 // setting up table headers
89 if ($this->showrank
) {
90 $tablecolumns = array('coursename', 'grade', 'rank');
91 $tableheaders = array($this->get_lang_string('coursename', 'grades'),
92 $this->get_lang_string('grade'),
93 $this->get_lang_string('rank', 'grades'));
95 $tablecolumns = array('coursename', 'grade');
96 $tableheaders = array($this->get_lang_string('coursename', 'grades'),
97 $this->get_lang_string('grade'));
99 $this->table
= new flexible_table('grade-report-overview-'.$this->user
->id
);
101 $this->table
->define_columns($tablecolumns);
102 $this->table
->define_headers($tableheaders);
103 $this->table
->define_baseurl($this->baseurl
);
105 $this->table
->set_attribute('cellspacing', '0');
106 $this->table
->set_attribute('id', 'overview-grade');
107 $this->table
->set_attribute('class', 'boxaligncenter generaltable');
109 $this->table
->setup();
112 function fill_table() {
115 // MDL-11679, only show 'mycourses' instead of all courses
116 if ($courses = get_my_courses($this->user
->id
, 'c.sortorder ASC', 'id, shortname')) {
117 $numusers = $this->get_numusers(false);
119 foreach ($courses as $course) {
120 $courselink = '<a href="'.$CFG->wwwroot
.'/grade/report/user/index.php?id='.$course->id
.'">'.$course->shortname
.'</a>';
122 // Get course grade_item
123 $grade_item = grade_item
::fetch_course_item($course->id
);
126 $grade = new grade_grade(array('itemid'=>$grade_item->id
, 'userid'=>$this->user
->id
));
127 $grade->grade_item
=& $grade_item;
128 $finalgrade = $grade->finalgrade
;
130 // TODO: this DOES NOT work properly if there are any hidden grades,
131 // rank might be wrong & totals might be different from user report!!!
132 if ($grade->is_hidden() and !has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
136 $data = array($courselink, grade_format_gradevalue($finalgrade, $grade_item, true));
138 if (!$this->showrank
) {
141 } else if (!is_null($finalgrade)) {
142 /// find the number of users with a higher grade
143 $sql = "SELECT COUNT(DISTINCT(userid))
144 FROM {$CFG->prefix}grade_grades
145 WHERE finalgrade IS NOT NULL AND finalgrade > $finalgrade
146 AND itemid = {$grade_item->id}";
147 $rank = count_records_sql($sql) +
1;
149 $data[] = "$rank/$numusers";
156 $this->table
->add_data($data);
161 notify(get_string('nocourses', 'grades'));
167 * Prints or returns the HTML from the flexitable.
168 * @param bool $return Whether or not to return the data instead of printing it directly.
171 function print_table($return=false) {
173 $this->table
->print_html();
174 $html = ob_get_clean();
183 * Processes the data sent by the form (grades and feedbacks).
185 * @return bool Success or Failure (array of errors).
187 function process_data($data) {
191 function grade_report_overview_settings_definition(&$mform) {
194 $options = array(-1 => get_string('default', 'grades'),
195 0 => get_string('hide'),
196 1 => get_string('show'));
198 if (empty($CFG->grade_overviewreport_showrank
)) {
199 $options[-1] = get_string('defaultprev', 'grades', $options[0]);
201 $options[-1] = get_string('defaultprev', 'grades', $options[1]);
204 $mform->addElement('select', 'report_overview_showrank', get_string('showrank', 'grades'), $options);
205 $mform->setHelpButton('report_overview_showrank', array('showrank', get_string('showrank', 'grades'), 'grade'));