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 | ||
c9451960 | 30 | $courseid = optional_param('id', SITEID, PARAM_INT); |
aa330ebb | 31 | $userid = optional_param('userid', $USER->id, PARAM_INT); |
32 | ||
c9451960 | 33 | $PAGE->set_url(new moodle_url('/grade/report/overview/index.php', array('id' => $courseid, 'userid' => $userid))); |
beebcf26 | 34 | |
5c75a0a3 | 35 | if (!$course = $DB->get_record('course', array('id' => $courseid))) { |
aa330ebb | 36 | print_error('nocourseid'); |
37 | } | |
c9451960 | 38 | require_login(null, false); |
aa330ebb | 39 | |
d4060472 AG |
40 | $context = context_course::instance($course->id); |
41 | $systemcontext = context_system::instance(); | |
c9451960 AG |
42 | $personalcontext = null; |
43 | $PAGE->set_context($context); | |
44 | ||
45 | // If we are accessing the page from a site context then ignore this check. | |
46 | if ($courseid != SITEID) { | |
47 | require_capability('gradereport/overview:view', $context); | |
48 | } | |
aa330ebb | 49 | |
7ac88172 | 50 | if (empty($userid)) { |
78527462 | 51 | require_capability('moodle/grade:viewall', $context); |
7ac88172 | 52 | |
53 | } else { | |
b0639b78 | 54 | if (!$DB->get_record('user', array('id'=>$userid, 'deleted'=>0)) or isguestuser($userid)) { |
cac0c3ef | 55 | print_error('invaliduserid'); |
7ac88172 | 56 | } |
c9451960 | 57 | $personalcontext = context_user::instance($userid); |
7ac88172 | 58 | } |
59 | ||
60 | $access = false; | |
02b5087e | 61 | if (has_capability('moodle/grade:viewall', $systemcontext)) { |
78527462 | 62 | // Ok - can view all course grades. |
7ac88172 | 63 | $access = true; |
aa330ebb | 64 | |
78527462 PAM |
65 | } else if (has_capability('moodle/grade:viewall', $context)) { |
66 | // Ok - can view any grades in context. | |
02b5087e | 67 | $access = true; |
6c3ef410 | 68 | |
c9451960 AG |
69 | } else if ($userid == $USER->id and ((has_capability('moodle/grade:view', $context) and $course->showgrades) |
70 | || $courseid == SITEID)) { | |
78527462 | 71 | // Ok - can view own course grades. |
7ac88172 | 72 | $access = true; |
aa330ebb | 73 | |
c9451960 AG |
74 | } else if (has_capability('moodle/grade:viewall', $personalcontext) and $course->showgrades) { |
75 | // Ok - can view grades of this user - parent most probably. | |
76 | $access = true; | |
77 | } else if (has_capability('moodle/user:viewuseractivitiesreport', $personalcontext) and $course->showgrades) { | |
78 | // Ok - can view grades of this user - parent most probably. | |
7ac88172 | 79 | $access = true; |
80 | } | |
aa330ebb | 81 | |
7ac88172 | 82 | if (!$access) { |
83 | // no access to grades! | |
cac0c3ef | 84 | print_error('nopermissiontoviewgrades', 'error', $CFG->wwwroot.'/course/view.php?id='.$courseid); |
aa330ebb | 85 | } |
86 | ||
87 | /// return tracking object | |
bc430af2 | 88 | $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'overview', 'courseid'=>$course->id, 'userid'=>$userid)); |
aa330ebb | 89 | |
90 | /// last selected report session tracking | |
91 | if (!isset($USER->grade_last_report)) { | |
92 | $USER->grade_last_report = array(); | |
93 | } | |
bc430af2 | 94 | $USER->grade_last_report[$course->id] = 'overview'; |
aa330ebb | 95 | |
7ac88172 | 96 | //first make sure we have proper final grades - this must be done before constructing of the grade tree |
97 | grade_regrade_final_grades($courseid); | |
98 | ||
c9451960 | 99 | if (has_capability('moodle/grade:viewall', $context) && $courseid != SITEID) { |
78527462 | 100 | // Please note this would be extremely slow if we wanted to implement this properly for all teachers. |
7ac88172 | 101 | $groupmode = groups_get_course_groupmode($course); // Groups are being used |
102 | $currentgroup = groups_get_course_group($course, true); | |
aa330ebb | 103 | |
7ac88172 | 104 | if (!$currentgroup) { // To make some other functions work better later |
105 | $currentgroup = NULL; | |
106 | } | |
aa330ebb | 107 | |
7ac88172 | 108 | $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)); |
109 | ||
110 | if ($isseparategroups and (!$currentgroup)) { | |
48a4c849 | 111 | // no separate group access, can view only self |
112 | $userid = $USER->id; | |
4d5059d4 | 113 | $user_selector = false; |
48a4c849 | 114 | } else { |
4d5059d4 | 115 | $user_selector = true; |
7ac88172 | 116 | } |
117 | ||
7ac88172 | 118 | if (empty($userid)) { |
119 | // Add tabs | |
120 | print_grade_page_head($courseid, 'report', 'overview'); | |
4d5059d4 | 121 | |
7ac88172 | 122 | groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0))); |
4d5059d4 SH |
123 | |
124 | if ($user_selector) { | |
125 | $renderer = $PAGE->get_renderer('gradereport_overview'); | |
126 | echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false); | |
127 | } | |
7ac88172 | 128 | // do not list all users |
129 | ||
130 | } else { // Only show one user's report | |
131 | $report = new grade_report_overview($userid, $gpr, $context); | |
b5e7b2bf | 132 | print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview'). ' - '.fullname($report->user)); |
7ac88172 | 133 | groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0))); |
134 | ||
4d5059d4 SH |
135 | if ($user_selector) { |
136 | $renderer = $PAGE->get_renderer('gradereport_overview'); | |
137 | echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false); | |
138 | } | |
7ac88172 | 139 | |
140 | if ($currentgroup and !groups_is_member($currentgroup, $userid)) { | |
c3b834b4 | 141 | echo $OUTPUT->notification(get_string('groupusernotmember', 'error')); |
7ac88172 | 142 | } else { |
143 | if ($report->fill_table()) { | |
144 | echo '<br />'.$report->print_table(true); | |
145 | } | |
146 | } | |
147 | } | |
c9451960 | 148 | } else { // Non-admins and users viewing from the site context can just see their own report. |
aa330ebb | 149 | |
150 | // Create a report instance | |
151 | $report = new grade_report_overview($userid, $gpr, $context); | |
7ac88172 | 152 | |
c9451960 AG |
153 | // If the course id matches the site id then we don't have a course context to work with. |
154 | // Display a standard page. | |
155 | if ($courseid == SITEID) { | |
156 | $PAGE->set_pagelayout('standard'); | |
157 | $header = get_string('mygrades', 'grades'). ' - '.fullname($report->user); | |
158 | $PAGE->set_title($header); | |
159 | $PAGE->set_heading($header); | |
160 | ||
161 | if ($USER->id != $report->user->id) { | |
162 | $PAGE->navigation->extend_for_user($report->user); | |
163 | if ($node = $PAGE->settingsnav->get('userviewingsettings'.$report->user->id)) { | |
164 | $node->forceopen = true; | |
165 | } | |
166 | } else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) { | |
167 | $node->forceopen = true; | |
168 | } | |
aa330ebb | 169 | |
c9451960 AG |
170 | echo $OUTPUT->header(); |
171 | if ($report->fill_table(true)) { | |
172 | echo '<br />'.$report->print_table(true); | |
173 | } | |
174 | } else { // We have a course context. We must be navigating from the gradebook. | |
175 | print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview') | |
176 | . ' - ' . fullname($report->user)); | |
177 | if ($report->fill_table()) { | |
178 | echo '<br />'.$report->print_table(true); | |
179 | } | |
aa330ebb | 180 | } |
aa330ebb | 181 | } |
7ac88172 | 182 | |
87f860cd | 183 | $event = \gradereport_overview\event\grade_report_viewed::create( |
06dc1e7f AG |
184 | array( |
185 | 'context' => $context, | |
186 | 'courseid' => $courseid, | |
187 | 'relateduserid' => $userid, | |
188 | ) | |
189 | ); | |
190 | $event->trigger(); | |
191 | ||
5a931394 | 192 | echo $OUTPUT->footer(); |
aa330ebb | 193 | |
02b5087e | 194 |