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
 * 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();
1441 ariadna 61
// Set the caption.
62
$summary->set_caption(get_string('summaryofattempt', 'quiz'));
1 efrain 63
// Student name.
64
$userpicture = new user_picture($student);
65
$userpicture->courseid = $attemptobj->get_courseid();
66
$summary->add_item('user', $userpicture, new action_link(
67
        new moodle_url('/user/view.php', [ 'id' => $student->id, 'course' => $attemptobj->get_courseid()]),
68
        fullname($student, true)));
69
 
70
// Quiz name.
71
$summary->add_item('quizname', get_string('modulename', 'quiz'), format_string($attemptobj->get_quiz_name()));
72
 
73
// Question name.
74
$summary->add_item('questionname', get_string('question', 'quiz'), $attemptobj->get_question_name($slot));
75
 
1441 ariadna 76
// Error message in case of input invalid mark.
77
$submiterror = false;
78
 
1 efrain 79
// Process any data that was submitted.
80
if (data_submitted() && confirm_sesskey()) {
81
    if (optional_param('submit', false, PARAM_BOOL) && question_engine::is_manual_grade_in_range($attemptobj->get_uniqueid(), $slot)) {
82
        $transaction = $DB->start_delegated_transaction();
83
        $attemptobj->process_submitted_actions(time());
84
        $transaction->allow_commit();
85
 
86
        // Log this action.
87
        $params = [
88
            'objectid' => $attemptobj->get_question_attempt($slot)->get_question_id(),
89
            'courseid' => $attemptobj->get_courseid(),
90
            'context' => $attemptobj->get_quizobj()->get_context(),
91
            'other' => [
92
                'quizid' => $attemptobj->get_quizid(),
93
                'attemptid' => $attemptobj->get_attemptid(),
94
                'slot' => $slot
95
            ]
96
        ];
97
        $event = \mod_quiz\event\question_manually_graded::create($params);
98
        $event->trigger();
99
 
100
        echo $output->notification(get_string('changessaved'), 'notifysuccess');
101
        close_window(2, true);
102
        die;
1441 ariadna 103
    } else {
104
        $submiterror = true;
1 efrain 105
    }
106
}
107
 
108
// Print quiz information.
109
echo html_writer::div($output->render($summary), 'mb-3');
110
 
1441 ariadna 111
// Display notification if current mark is invalid.
112
if ($submiterror) {
113
    echo $output->notification(get_string('savemanualgradingfailed', 'quiz'), \core\output\notification::NOTIFY_ERROR);
114
}
1 efrain 115
// Print the comment form.
116
echo '<form method="post" class="mform" id="manualgradingform" action="' .
117
        $CFG->wwwroot . '/mod/quiz/comment.php">';
118
echo $attemptobj->render_question_for_commenting($slot);
119
?>
120
<div>
121
    <input type="hidden" name="attempt" value="<?php echo $attemptobj->get_attemptid(); ?>" />
122
    <input type="hidden" name="slot" value="<?php echo $slot; ?>" />
123
    <input type="hidden" name="slots" value="<?php echo $slot; ?>" />
124
    <input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
125
</div>
126
<fieldset class="hidden">
127
    <div>
128
        <div class="fitem fitem_actionbuttons fitem_fsubmit mt-3">
129
            <fieldset class="felement fsubmit">
130
                <input id="id_submitbutton" type="submit" name="submit" class="btn btn-primary" value="<?php
131
                        print_string('save', 'quiz'); ?>"/>
132
            </fieldset>
133
        </div>
134
    </div>
135
</fieldset>
136
<?php
137
echo '</form>';
138
$PAGE->requires->js_init_call('M.mod_quiz.init_comment_popup', null, false, quiz_get_js_module());
139
 
140
// End of the page.
141
echo $output->footer();