Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
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/>.
16
 
17
/**
18
 * The gradebook grader report
19
 *
20
 * @package   gradereport_grader
21
 * @copyright 2007 Moodle Pty Ltd (http://moodle.com)
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once('../../../config.php');
26
require_once($CFG->libdir.'/gradelib.php');
27
require_once($CFG->dirroot.'/user/renderer.php');
28
require_once($CFG->dirroot.'/grade/lib.php');
29
require_once($CFG->dirroot.'/grade/report/grader/lib.php');
30
 
1441 ariadna 31
// This report may require a lot of memory and time on large courses.
32
raise_memory_limit(MEMORY_HUGE);
33
set_time_limit(120);
34
 
1 efrain 35
$courseid      = required_param('id', PARAM_INT);        // course id
36
$page          = optional_param('page', 0, PARAM_INT);   // active page
37
$edit          = optional_param('edit', -1, PARAM_BOOL); // sticky editting mode
38
 
39
$sortitemid    = optional_param('sortitemid', 0, PARAM_ALPHANUMEXT);
40
$sort          = optional_param('sort', '', PARAM_ALPHA);
41
$action        = optional_param('action', 0, PARAM_ALPHAEXT);
42
$move          = optional_param('move', 0, PARAM_INT);
43
$type          = optional_param('type', 0, PARAM_ALPHA);
44
$target        = optional_param('target', 0, PARAM_ALPHANUM);
45
$toggle        = optional_param('toggle', null, PARAM_INT);
46
$toggle_type   = optional_param('toggle_type', 0, PARAM_ALPHANUM);
47
 
48
$graderreportsifirst  = optional_param('sifirst', null, PARAM_NOTAGS);
49
$graderreportsilast   = optional_param('silast', null, PARAM_NOTAGS);
50
 
51
$studentsperpage = optional_param('perpage', null, PARAM_INT);
1441 ariadna 52
$baseurl = new moodle_url('/grade/report/grader/index.php', ['id' => $courseid]);
1 efrain 53
 
54
$PAGE->set_url(new moodle_url('/grade/report/grader/index.php', array('id'=>$courseid)));
55
$PAGE->set_pagelayout('report');
56
 
57
// basic access checks
58
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
59
    throw new \moodle_exception('invalidcourseid');
60
}
61
 
62
// Conditionally add the group JS if we have groups enabled.
63
if ($course->groupmode) {
1441 ariadna 64
    $PAGE->requires->js_call_amd('core_course/actionbar/group', 'init', [$baseurl->out(false)]);
1 efrain 65
}
66
 
67
require_login($course);
68
$context = context_course::instance($course->id);
69
 
70
// The report object is recreated each time, save search information to SESSION object for future use.
71
if (isset($graderreportsifirst)) {
72
    $SESSION->gradereport["filterfirstname-{$context->id}"] = $graderreportsifirst;
73
}
74
if (isset($graderreportsilast)) {
75
    $SESSION->gradereport["filtersurname-{$context->id}"] = $graderreportsilast;
76
}
77
 
78
if (isset($studentsperpage) && $studentsperpage >= 0) {
79
    set_user_preference('grade_report_studentsperpage', $studentsperpage);
80
}
81
 
82
require_capability('gradereport/grader:view', $context);
83
require_capability('moodle/grade:viewall', $context);
84
 
85
// return tracking object
86
$gpr = new grade_plugin_return(
87
    array(
88
        'type' => 'report',
89
        'plugin' => 'grader',
90
        'course' => $course,
91
        'page' => $page
92
    )
93
);
94
 
95
// last selected report session tracking
96
if (!isset($USER->grade_last_report)) {
97
    $USER->grade_last_report = array();
98
}
99
$USER->grade_last_report[$course->id] = 'grader';
100
 
101
// Build editing on/off buttons.
102
$buttons = '';
103
 
104
$PAGE->set_other_editing_capability('moodle/grade:edit');
105
if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) {
106
    if ($edit != - 1) {
107
        $USER->editing = $edit;
108
    }
109
 
110
    // Page params for the turn editing on button.
111
    $options = $gpr->get_options();
112
    $buttons = $OUTPUT->edit_button(new moodle_url($PAGE->url, $options), 'get');
113
}
114
 
115
$gradeserror = array();
116
 
117
// Handle toggle change request
118
if (!is_null($toggle) && !empty($toggle_type)) {
119
    set_user_preferences(array('grade_report_show'.$toggle_type => $toggle));
120
}
121
 
122
// Perform actions
123
if (!empty($target) && !empty($action) && confirm_sesskey()) {
124
    grade_report_grader::do_process_action($target, $action, $courseid);
125
}
126
 
127
$reportname = get_string('pluginname', 'gradereport_grader');
1441 ariadna 128
$regradetask = \core_course\task\regrade_final_grades::create($courseid);
129
$indicatorheading = get_string('recalculatinggrades', 'grades');
130
$indicatormessage = get_string('recalculatinggradesadhoc', 'grades');
131
$taskindicator = new \core\output\task_indicator($regradetask, $indicatorheading, $indicatormessage, $PAGE->url);
132
if (!$taskindicator->has_task_record()) {
133
    // Do this check just before printing the grade header (and only do it once).
134
    grade_regrade_final_grades_if_required($course);
135
}
1 efrain 136
 
137
//Initialise the grader report object that produces the table
138
//the class grade_report_grader_ajax was removed as part of MDL-21562
139
if ($sort && strcasecmp($sort, 'desc') !== 0) {
140
    $sort = 'asc';
141
}
142
// We have lots of hardcoded 'ASC' and 'DESC' strings in grade/report/grader.lib :(. So we need to uppercase the sort.
143
$sort = strtoupper($sort);
144
 
145
$report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid, $sort);
146
 
147
$numusers = $report->get_numusers(true, true);
148
 
149
$actionbar = new \gradereport_grader\output\action_bar($context, $report, $numusers);
150
print_grade_page_head($COURSE->id, 'report', 'grader', false, false, $buttons, true,
151
    null, null, null, $actionbar);
152
 
153
// make sure separate group does not prevent view
154
if ($report->currentgroup == -2) {
155
    echo $OUTPUT->heading(get_string("notingroup"));
156
    echo $OUTPUT->footer();
157
    exit;
158
}
159
 
160
$warnings = [];
161
$isediting = has_capability('moodle/grade:edit', $context) && isset($USER->editing) && $USER->editing;
162
if ($isediting && ($data = data_submitted()) && confirm_sesskey()) {
163
    // Processing posted grades here.
164
    $warnings = $report->process_data($data);
165
}
166
 
1441 ariadna 167
if ($taskindicator->has_task_record()) {
168
    echo $OUTPUT->render($taskindicator);
169
    echo $OUTPUT->footer();
170
    exit;
171
}
172
 
173
// We call this a little later since we need some info from the grader report.
174
$PAGE->requires->js_call_amd('gradereport_grader/collapse', 'init', [
175
    'userID' => $USER->id,
176
    'courseID' => $courseid,
177
    'defaultSort' => $report->get_default_sortable(),
178
]);
179
$PAGE->requires->js_call_amd('gradereport_grader/stickycolspan', 'init');
180
$PAGE->requires->js_call_amd('gradereport_grader/user', 'init', [$baseurl->out(false)]);
181
$PAGE->requires->js_call_amd('gradereport_grader/feedback_modal', 'init');
182
$PAGE->requires->js_call_amd('core_grades/gradebooksetup_forms', 'init');
183
 
1 efrain 184
// Final grades MUST be loaded after the processing.
185
$report->load_users();
186
$report->load_final_grades();
187
 
188
//show warnings if any
189
foreach ($warnings as $warning) {
190
    echo $OUTPUT->notification($warning);
191
}
192
 
193
$displayaverages = true;
194
if ($numusers == 0) {
195
    $displayaverages = false;
196
}
197
 
198
$reporthtml = $report->get_grade_table($displayaverages);
199
 
200
$studentsperpage = $report->get_students_per_page();
201
 
202
// Print per-page dropdown.
203
$pagingoptions = grade_report_grader::PAGINATION_OPTIONS;
204
if ($studentsperpage) {
205
    $pagingoptions[] = $studentsperpage; // To make sure the current preference is within the options.
206
}
207
$pagingoptions = array_unique($pagingoptions);
208
sort($pagingoptions);
209
$pagingoptions = array_combine($pagingoptions, $pagingoptions);
1441 ariadna 210
$maxusers = $report->get_max_students_per_page();
211
if ($numusers > $maxusers) {
212
    $pagingoptions['0'] = $maxusers;
1 efrain 213
} else {
214
    $pagingoptions['0'] = get_string('all');
215
}
216
 
217
$perpagedata = [
1441 ariadna 218
    'baseurl' => (new moodle_url('/grade/report/grader/index.php', ['id' => s($courseid), 'report' => 'grader']))->out(false),
1 efrain 219
    'options' => []
220
];
221
foreach ($pagingoptions as $key => $name) {
222
    $perpagedata['options'][] = [
223
        'name' => $name,
224
        'value' => $key,
225
        'selected' => $key == $studentsperpage,
226
    ];
227
}
228
 
229
$footercontent = html_writer::div(
230
    $OUTPUT->render_from_template('gradereport_grader/perpage', $perpagedata)
231
    , 'col-auto'
232
);
233
 
234
// The number of students per page is always limited even if it is claimed to be unlimited.
1441 ariadna 235
$studentsperpage = $studentsperpage ?: $maxusers;
1 efrain 236
$footercontent .= html_writer::div(
237
    $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl),
238
    'col'
239
);
240
 
241
// print submit button
242
if (!empty($USER->editing) && $report->get_pref('quickgrading')) {
243
    echo '<form action="index.php" enctype="application/x-www-form-urlencoded" method="post" id="gradereport_grader">'; // Enforce compatibility with our max_input_vars hack.
244
    echo '<div>';
245
    echo '<input type="hidden" value="'.s($courseid).'" name="id" />';
246
    echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
247
    echo '<input type="hidden" value="'.time().'" name="timepageload" />';
248
    echo '<input type="hidden" value="grader" name="report"/>';
249
    echo '<input type="hidden" value="'.$page.'" name="page"/>';
250
    echo $gpr->get_form_fields();
251
    echo $reporthtml;
252
 
253
    $footercontent .= html_writer::div(
254
        '<input type="submit" id="gradersubmit" class="btn btn-primary" value="'.s(get_string('savechanges')).'" />',
255
        'col-auto'
256
    );
257
 
258
    $stickyfooter = new core\output\sticky_footer($footercontent);
259
    echo $OUTPUT->render($stickyfooter);
260
 
261
    echo '</div></form>';
262
} else {
263
    echo $reporthtml;
264
 
265
    $stickyfooter = new core\output\sticky_footer($footercontent);
266
    echo $OUTPUT->render($stickyfooter);
267
}
268
 
269
$event = \gradereport_grader\event\grade_report_viewed::create(
270
    array(
271
        'context' => $context,
272
        'courseid' => $courseid,
273
    )
274
);
275
$event->trigger();
276
 
277
echo $OUTPUT->footer();