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