Commit | Line | Data |
---|---|---|
e060e33d | 1 | <?php |
e060e33d | 2 | // This file is part of Moodle - http://moodle.org/ |
3 | // | |
4 | // Moodle is free software: you can redistribute it and/or modify | |
5 | // it under the terms of the GNU General Public License as published by | |
6 | // the Free Software Foundation, either version 3 of the License, or | |
7 | // (at your option) any later version. | |
8 | // | |
9 | // Moodle is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | // | |
14 | // You should have received a copy of the GNU General Public License | |
15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
aa330ebb | 16 | |
a153c9f2 AD |
17 | /** |
18 | * The gradebook overview report | |
19 | * | |
20 | * @package gradereport_overview | |
21 | * @copyright 2007 Nicolas Connault | |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | */ | |
24 | ||
aa330ebb | 25 | require_once '../../../config.php'; |
26 | require_once $CFG->libdir.'/gradelib.php'; | |
27 | require_once $CFG->dirroot.'/grade/lib.php'; | |
28 | require_once $CFG->dirroot.'/grade/report/overview/lib.php'; | |
29 | ||
7ac88172 | 30 | $courseid = required_param('id', PARAM_INT); |
aa330ebb | 31 | $userid = optional_param('userid', $USER->id, PARAM_INT); |
32 | ||
4d5059d4 | 33 | $PAGE->set_url(new moodle_url('/grade/report/overview/index.php', array('id'=>$courseid))); |
beebcf26 | 34 | |
aa330ebb | 35 | /// basic access checks |
5c75a0a3 | 36 | if (!$course = $DB->get_record('course', array('id' => $courseid))) { |
aa330ebb | 37 | print_error('nocourseid'); |
38 | } | |
39 | require_login($course); | |
40 | ||
d4060472 AG |
41 | $context = context_course::instance($course->id); |
42 | $systemcontext = context_system::instance(); | |
aa330ebb | 43 | require_capability('gradereport/overview:view', $context); |
44 | ||
7ac88172 | 45 | if (empty($userid)) { |
78527462 | 46 | require_capability('moodle/grade:viewall', $context); |
7ac88172 | 47 | |
48 | } else { | |
b0639b78 | 49 | if (!$DB->get_record('user', array('id'=>$userid, 'deleted'=>0)) or isguestuser($userid)) { |
cac0c3ef | 50 | print_error('invaliduserid'); |
7ac88172 | 51 | } |
52 | } | |
53 | ||
54 | $access = false; | |
02b5087e | 55 | if (has_capability('moodle/grade:viewall', $systemcontext)) { |
78527462 | 56 | // Ok - can view all course grades. |
7ac88172 | 57 | $access = true; |
aa330ebb | 58 | |
78527462 PAM |
59 | } else if (has_capability('moodle/grade:viewall', $context)) { |
60 | // Ok - can view any grades in context. | |
02b5087e | 61 | $access = true; |
6c3ef410 | 62 | |
7ac88172 | 63 | } else if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) { |
78527462 | 64 | // Ok - can view own course grades. |
7ac88172 | 65 | $access = true; |
aa330ebb | 66 | |
d4060472 | 67 | } else if (has_capability('moodle/grade:viewall', context_user::instance($userid)) and $course->showgrades) { |
78527462 | 68 | // Ok - can view grades of this user- parent most probably. |
7ac88172 | 69 | $access = true; |
70 | } | |
aa330ebb | 71 | |
7ac88172 | 72 | if (!$access) { |
73 | // no access to grades! | |
cac0c3ef | 74 | print_error('nopermissiontoviewgrades', 'error', $CFG->wwwroot.'/course/view.php?id='.$courseid); |
aa330ebb | 75 | } |
76 | ||
77 | /// return tracking object | |
bc430af2 | 78 | $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'overview', 'courseid'=>$course->id, 'userid'=>$userid)); |
aa330ebb | 79 | |
80 | /// last selected report session tracking | |
81 | if (!isset($USER->grade_last_report)) { | |
82 | $USER->grade_last_report = array(); | |
83 | } | |
bc430af2 | 84 | $USER->grade_last_report[$course->id] = 'overview'; |
aa330ebb | 85 | |
7ac88172 | 86 | //first make sure we have proper final grades - this must be done before constructing of the grade tree |
87 | grade_regrade_final_grades($courseid); | |
88 | ||
78527462 PAM |
89 | if (has_capability('moodle/grade:viewall', $context)) { |
90 | // Please note this would be extremely slow if we wanted to implement this properly for all teachers. | |
7ac88172 | 91 | $groupmode = groups_get_course_groupmode($course); // Groups are being used |
92 | $currentgroup = groups_get_course_group($course, true); | |
aa330ebb | 93 | |
7ac88172 | 94 | if (!$currentgroup) { // To make some other functions work better later |
95 | $currentgroup = NULL; | |
96 | } | |
aa330ebb | 97 | |
7ac88172 | 98 | $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)); |
99 | ||
100 | if ($isseparategroups and (!$currentgroup)) { | |
48a4c849 | 101 | // no separate group access, can view only self |
102 | $userid = $USER->id; | |
4d5059d4 | 103 | $user_selector = false; |
48a4c849 | 104 | } else { |
4d5059d4 | 105 | $user_selector = true; |
7ac88172 | 106 | } |
107 | ||
7ac88172 | 108 | if (empty($userid)) { |
109 | // Add tabs | |
110 | print_grade_page_head($courseid, 'report', 'overview'); | |
4d5059d4 | 111 | |
7ac88172 | 112 | groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0))); |
4d5059d4 SH |
113 | |
114 | if ($user_selector) { | |
115 | $renderer = $PAGE->get_renderer('gradereport_overview'); | |
116 | echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false); | |
117 | } | |
7ac88172 | 118 | // do not list all users |
119 | ||
120 | } else { // Only show one user's report | |
121 | $report = new grade_report_overview($userid, $gpr, $context); | |
b5e7b2bf | 122 | print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview'). ' - '.fullname($report->user)); |
7ac88172 | 123 | groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0))); |
124 | ||
4d5059d4 SH |
125 | if ($user_selector) { |
126 | $renderer = $PAGE->get_renderer('gradereport_overview'); | |
127 | echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false); | |
128 | } | |
7ac88172 | 129 | |
130 | if ($currentgroup and !groups_is_member($currentgroup, $userid)) { | |
c3b834b4 | 131 | echo $OUTPUT->notification(get_string('groupusernotmember', 'error')); |
7ac88172 | 132 | } else { |
133 | if ($report->fill_table()) { | |
134 | echo '<br />'.$report->print_table(true); | |
135 | } | |
136 | } | |
137 | } | |
02b5087e | 138 | } else { //Non-admins will see just their own report |
aa330ebb | 139 | |
140 | // Create a report instance | |
141 | $report = new grade_report_overview($userid, $gpr, $context); | |
7ac88172 | 142 | |
143 | // print the page | |
b5e7b2bf | 144 | print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview'). ' - '.fullname($report->user)); |
aa330ebb | 145 | |
146 | if ($report->fill_table()) { | |
7ac88172 | 147 | echo '<br />'.$report->print_table(true); |
aa330ebb | 148 | } |
aa330ebb | 149 | } |
7ac88172 | 150 | |
87f860cd | 151 | $event = \gradereport_overview\event\grade_report_viewed::create( |
06dc1e7f AG |
152 | array( |
153 | 'context' => $context, | |
154 | 'courseid' => $courseid, | |
155 | 'relateduserid' => $userid, | |
156 | ) | |
157 | ); | |
158 | $event->trigger(); | |
159 | ||
5a931394 | 160 | echo $OUTPUT->footer(); |
aa330ebb | 161 | |
02b5087e | 162 |