Proyectos de Subversion Moodle

Rev

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