-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
183 lines (151 loc) · 7.61 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle 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.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The gradebook forecast report page
*
* @package gradereport_forecast
* @copyright 2016 Louisiana State University, Chad Mazilly, Robert Russo, Dave Elliott
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../../config.php');
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/grade/lib.php');
require_once($CFG->dirroot.'/grade/report/forecast/lib.php');
$PAGE->requires->jquery();
$PAGE->requires->js('/grade/report/forecast/js/forecast.js');
$PAGE->requires->js('/grade/report/forecast/js/modal.js');
$courseid = required_param('id', PARAM_INT);
$userid = optional_param('userid', $USER->id, PARAM_INT);
$PAGE->set_url(new moodle_url('/grade/report/forecast/index.php', array('id' => $courseid)));
// Let's perform some basic access checks.
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
}
require_login($course);
$PAGE->set_pagelayout('report');
$context = context_course::instance($course->id);
require_capability('gradereport/forecast:view', $context);
if (empty($userid)) {
require_capability('moodle/grade:viewall', $context);
} else {
if (!$DB->get_record('user', array('id' => $userid, 'deleted' => 0)) or isguestuser($userid)) {
print_error('invaliduser');
}
}
$enabled = grade_get_setting($courseid, 'report_forecast_enabledforstudents', $CFG->grade_report_forecast_enabledforstudents);
$viewall = has_capability('moodle/grade:viewall', $context);
$viewown = $userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades;
$viewuser = has_capability('moodle/grade:viewall', context_user::instance($userid)) and $course->showgrades;
$url = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
if (!($viewall or ($viewown && $enabled) or $viewuser)) {
// Be sure users are not automatically redirected back here if disabled after use.
$USER->grade_last_report[$course->id] = 'user';
// Redirect them back to the course, letting them know it was disabled.
redirect($url, get_string('nopermissiontouseforecast', 'gradereport_forecast'), 1);
// If somehow they don't redirect, print an error and die.
print_error('nopermissiontouseforecast', 'gradereport_forecast', $url);
echo $OUTPUT->footer();
die();
}
// Return the tracking object.
$gpr = new grade_plugin_return(array('type' => 'report', 'plugin' => 'forecast', 'courseid' => $courseid, 'userid' => $userid));
// Last selected report session tracking.
if (!isset($USER->grade_last_report)) {
$USER->grade_last_report = array();
}
$USER->grade_last_report[$course->id] = 'forecast';
// First make sure we have proper final grades.
grade_regrade_final_grades_if_required($course);
if (has_capability('moodle/grade:viewall', $context)) {
// Teachers will see all student reports.
$groupmode = groups_get_course_groupmode($course);
// Groups are being used.
$currentgroup = groups_get_course_group($course, true);
if (!$currentgroup) {
// To make some other functions work better later.
$currentgroup = null;
}
$isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context));
if ($isseparategroups and (!$currentgroup)) {
// No separate group access, can view only self.
$userid = $USER->id;
$userselector = false;
} else {
$userselector = true;
}
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
// If a user is selected, show their report.
if (!empty($userid)) {
$report = new grade_report_forecast($courseid, $gpr, $context, $userid);
$studentnamelink = html_writer::link(new moodle_url('/user/view.php', array(
'id' => $report->user->id,
'course' => $courseid
)), fullname($report->user));
print_grade_page_head($courseid, 'report', 'forecast',
get_string('pluginname', 'gradereport_forecast') . ' - ' . $studentnamelink,
false, false, true, null, null, $report->user);
groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid' => 0)));
if ($userselector) {
$renderer = $PAGE->get_renderer('gradereport_forecast');
$showallusersoptions = false;
echo $renderer->graded_users_selector('forecast', $course, $userid, $currentgroup, $showallusersoptions);
}
if ($currentgroup and !groups_is_member($currentgroup, $userid)) {
echo $OUTPUT->notification(get_string('groupusernotmember', 'error'));
} else {
if ($report->fill_table()) {
echo '<br />'.$report->print_table(true);
}
}
} else {
// Add tabs.
print_grade_page_head($courseid, 'report', 'forecast');
groups_print_course_menu($course, $gpr->get_return_url('index.php?id=' . $courseid, array('userid' => 0)));
if ($userselector) {
$renderer = $PAGE->get_renderer('gradereport_forecast');
echo $renderer->graded_users_selector('forecast', $course, $userid, $currentgroup, false);
}
}
} else {
// Students will see just their own report.
// Create a report instance.
$report = new grade_report_forecast($courseid, $gpr, $context, $userid);
// Print the page.
print_grade_page_head($courseid, 'report', 'forecast', get_string(
'pluginname', 'gradereport_forecast'
) . ' - '.fullname($report->user));
if ($report->fill_table()) {
echo '<br />'.$report->print_table(true);
}
}
if (isset($report)) {
// Trigger report viewed event.
$report->viewed();
} else {
echo html_writer::tag('div', '', array('class' => 'clearfix'));
echo $OUTPUT->notification(get_string('selctauser'));
}
if (grade_get_setting($courseid, 'report_forecast_mustmakeenabled', $CFG->grade_report_forecast_mustmakeenabled)) {
echo $report->getMustMakeModal();
}
echo '<script>$(document).ready(function() {
listenForInputChanges(' . grade_get_setting($courseid,
'report_forecast_debouncewaittime',
$CFG->grade_report_forecast_debouncewaittime
) . ') });</script>';
echo $OUTPUT->footer();