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 |
* This page allows the teacher to enter a manual grade for a particular question.
|
|
|
19 |
* This page is expected to only be used in a popup window.
|
|
|
20 |
*
|
|
|
21 |
* @package mod_quiz
|
|
|
22 |
* @copyright gustav delius 2006
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
use mod_quiz\output\attempt_summary_information;
|
|
|
27 |
|
|
|
28 |
require_once('../../config.php');
|
|
|
29 |
require_once('locallib.php');
|
|
|
30 |
|
|
|
31 |
$attemptid = required_param('attempt', PARAM_INT);
|
|
|
32 |
$slot = required_param('slot', PARAM_INT); // The question number in the attempt.
|
|
|
33 |
$cmid = optional_param('cmid', null, PARAM_INT);
|
|
|
34 |
|
|
|
35 |
$PAGE->set_url('/mod/quiz/comment.php', ['attempt' => $attemptid, 'slot' => $slot]);
|
|
|
36 |
|
|
|
37 |
$attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
|
|
|
38 |
$attemptobj->preload_all_attempt_step_users();
|
|
|
39 |
$student = $DB->get_record('user', ['id' => $attemptobj->get_userid()]);
|
|
|
40 |
|
|
|
41 |
// Can only grade finished attempts.
|
|
|
42 |
if (!$attemptobj->is_finished()) {
|
|
|
43 |
throw new \moodle_exception('attemptclosed', 'quiz');
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
// Check login and permissions.
|
|
|
47 |
require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
|
|
|
48 |
$attemptobj->require_capability('mod/quiz:grade');
|
|
|
49 |
|
|
|
50 |
// Print the page header.
|
|
|
51 |
$PAGE->set_pagelayout('popup');
|
|
|
52 |
$PAGE->set_title(get_string('manualgradequestion', 'quiz', [
|
|
|
53 |
'question' => format_string($attemptobj->get_question_name($slot)),
|
|
|
54 |
'quiz' => format_string($attemptobj->get_quiz_name()), 'user' => fullname($student)]));
|
|
|
55 |
$PAGE->set_heading($attemptobj->get_course()->fullname);
|
|
|
56 |
$output = $PAGE->get_renderer('mod_quiz');
|
|
|
57 |
echo $output->header();
|
|
|
58 |
|
|
|
59 |
// Prepare summary information about this question attempt.
|
|
|
60 |
$summary = new attempt_summary_information();
|
|
|
61 |
|
|
|
62 |
// Student name.
|
|
|
63 |
$userpicture = new user_picture($student);
|
|
|
64 |
$userpicture->courseid = $attemptobj->get_courseid();
|
|
|
65 |
$summary->add_item('user', $userpicture, new action_link(
|
|
|
66 |
new moodle_url('/user/view.php', [ 'id' => $student->id, 'course' => $attemptobj->get_courseid()]),
|
|
|
67 |
fullname($student, true)));
|
|
|
68 |
|
|
|
69 |
// Quiz name.
|
|
|
70 |
$summary->add_item('quizname', get_string('modulename', 'quiz'), format_string($attemptobj->get_quiz_name()));
|
|
|
71 |
|
|
|
72 |
// Question name.
|
|
|
73 |
$summary->add_item('questionname', get_string('question', 'quiz'), $attemptobj->get_question_name($slot));
|
|
|
74 |
|
|
|
75 |
// Process any data that was submitted.
|
|
|
76 |
if (data_submitted() && confirm_sesskey()) {
|
|
|
77 |
if (optional_param('submit', false, PARAM_BOOL) && question_engine::is_manual_grade_in_range($attemptobj->get_uniqueid(), $slot)) {
|
|
|
78 |
$transaction = $DB->start_delegated_transaction();
|
|
|
79 |
$attemptobj->process_submitted_actions(time());
|
|
|
80 |
$transaction->allow_commit();
|
|
|
81 |
|
|
|
82 |
// Log this action.
|
|
|
83 |
$params = [
|
|
|
84 |
'objectid' => $attemptobj->get_question_attempt($slot)->get_question_id(),
|
|
|
85 |
'courseid' => $attemptobj->get_courseid(),
|
|
|
86 |
'context' => $attemptobj->get_quizobj()->get_context(),
|
|
|
87 |
'other' => [
|
|
|
88 |
'quizid' => $attemptobj->get_quizid(),
|
|
|
89 |
'attemptid' => $attemptobj->get_attemptid(),
|
|
|
90 |
'slot' => $slot
|
|
|
91 |
]
|
|
|
92 |
];
|
|
|
93 |
$event = \mod_quiz\event\question_manually_graded::create($params);
|
|
|
94 |
$event->trigger();
|
|
|
95 |
|
|
|
96 |
echo $output->notification(get_string('changessaved'), 'notifysuccess');
|
|
|
97 |
close_window(2, true);
|
|
|
98 |
die;
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
// Print quiz information.
|
|
|
103 |
echo html_writer::div($output->render($summary), 'mb-3');
|
|
|
104 |
|
|
|
105 |
// Print the comment form.
|
|
|
106 |
echo '<form method="post" class="mform" id="manualgradingform" action="' .
|
|
|
107 |
$CFG->wwwroot . '/mod/quiz/comment.php">';
|
|
|
108 |
echo $attemptobj->render_question_for_commenting($slot);
|
|
|
109 |
?>
|
|
|
110 |
<div>
|
|
|
111 |
<input type="hidden" name="attempt" value="<?php echo $attemptobj->get_attemptid(); ?>" />
|
|
|
112 |
<input type="hidden" name="slot" value="<?php echo $slot; ?>" />
|
|
|
113 |
<input type="hidden" name="slots" value="<?php echo $slot; ?>" />
|
|
|
114 |
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
|
|
|
115 |
</div>
|
|
|
116 |
<fieldset class="hidden">
|
|
|
117 |
<div>
|
|
|
118 |
<div class="fitem fitem_actionbuttons fitem_fsubmit mt-3">
|
|
|
119 |
<fieldset class="felement fsubmit">
|
|
|
120 |
<input id="id_submitbutton" type="submit" name="submit" class="btn btn-primary" value="<?php
|
|
|
121 |
print_string('save', 'quiz'); ?>"/>
|
|
|
122 |
</fieldset>
|
|
|
123 |
</div>
|
|
|
124 |
</div>
|
|
|
125 |
</fieldset>
|
|
|
126 |
<?php
|
|
|
127 |
echo '</form>';
|
|
|
128 |
$PAGE->requires->js_init_call('M.mod_quiz.init_comment_popup', null, false, quiz_get_js_module());
|
|
|
129 |
|
|
|
130 |
// End of the page.
|
|
|
131 |
echo $output->footer();
|