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
 * This page prints a review of a particular quiz attempt
19
 *
20
 * It is used either by the student whose attempts this is, after the attempt,
21
 * or by a teacher reviewing another's attempt during or afterwards.
22
 *
23
 * @package   mod_quiz
24
 * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
25
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
 
28
use mod_quiz\output\attempt_summary_information;
29
use mod_quiz\output\navigation_panel_review;
30
use mod_quiz\output\renderer;
31
use mod_quiz\quiz_attempt;
32
 
33
require_once(__DIR__ . '/../../config.php');
34
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
35
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
36
 
37
$attemptid = required_param('attempt', PARAM_INT);
38
$page      = optional_param('page', 0, PARAM_INT);
39
$showall   = optional_param('showall', null, PARAM_BOOL);
40
$cmid      = optional_param('cmid', null, PARAM_INT);
41
 
42
$url = new moodle_url('/mod/quiz/review.php', ['attempt' => $attemptid]);
43
if ($page !== 0) {
44
    $url->param('page', $page);
45
} else if ($showall) {
46
    $url->param('showall', $showall);
47
}
48
$PAGE->set_url($url);
49
$PAGE->set_secondary_active_tab("modulepage");
50
 
51
$attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
52
$attemptobj->preload_all_attempt_step_users();
53
$page = $attemptobj->force_page_number_into_range($page);
54
 
55
// Now we can validate the params better, re-genrate the page URL.
56
if ($showall === null) {
57
    $showall = $page == 0 && $attemptobj->get_default_show_all('review');
58
}
59
$PAGE->set_url($attemptobj->review_url(null, $page, $showall));
60
 
61
// Check login.
62
require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
63
$attemptobj->check_review_capability();
64
 
65
// Create an object to manage all the other (non-roles) access rules.
66
$accessmanager = $attemptobj->get_access_manager(time());
67
$accessmanager->setup_attempt_page($PAGE);
68
 
69
$options = $attemptobj->get_display_options(true);
70
 
71
// Check permissions - warning there is similar code in reviewquestion.php and
72
// quiz_attempt::check_file_access. If you change on, change them all.
73
if ($attemptobj->is_own_attempt()) {
74
    if (!$attemptobj->is_finished()) {
75
        redirect($attemptobj->attempt_url(null, $page));
76
 
77
    } else if (!$options->attempt) {
78
        $accessmanager->back_to_view_page($PAGE->get_renderer('mod_quiz'),
79
                $attemptobj->cannot_review_message());
80
    }
81
 
82
} else if (!$attemptobj->is_review_allowed()) {
83
    throw new moodle_exception('noreviewattempt', 'quiz', $attemptobj->view_url());
84
}
85
 
86
// Load the questions and states needed by this page.
87
if ($showall) {
88
    $questionids = $attemptobj->get_slots();
89
} else {
90
    $questionids = $attemptobj->get_slots($page);
91
}
92
 
93
// Save the flag states, if they are being changed.
94
if ($options->flags == question_display_options::EDITABLE && optional_param('savingflags', false,
95
        PARAM_BOOL)) {
96
    require_sesskey();
97
    $attemptobj->save_question_flags();
98
    redirect($attemptobj->review_url(null, $page, $showall));
99
}
100
 
101
// Work out appropriate title and whether blocks should be shown.
102
if ($attemptobj->is_own_preview()) {
103
    navigation_node::override_active_url($attemptobj->start_attempt_url());
104
    $attemptobj->update_questions_to_new_version_if_changed();
105
 
106
} else {
107
    if (empty($attemptobj->get_quiz()->showblocks) && !$attemptobj->is_preview_user()) {
108
        $PAGE->blocks->show_only_fake_blocks();
109
    }
110
}
111
 
112
// Set up the page header.
113
$headtags = $attemptobj->get_html_head_contributions($page, $showall);
114
$PAGE->set_title($attemptobj->review_page_title($page, $showall));
115
$PAGE->set_heading($attemptobj->get_course()->fullname);
116
$PAGE->activityheader->disable();
117
 
118
$summarydata = attempt_summary_information::create_for_attempt($attemptobj, $options, $page, $showall);
119
 
120
if ($showall) {
121
    $slots = $attemptobj->get_slots();
122
    $lastpage = true;
123
} else {
124
    $slots = $attemptobj->get_slots($page);
125
    $lastpage = $attemptobj->is_last_page($page);
126
}
127
 
128
/** @var renderer $output */
129
$output = $PAGE->get_renderer('mod_quiz');
130
 
131
// Arrange for the navigation to be displayed.
132
$navbc = $attemptobj->get_navigation_panel($output, navigation_panel_review::class, $page, $showall);
133
$regions = $PAGE->blocks->get_regions();
134
$PAGE->blocks->add_fake_block($navbc, reset($regions));
135
 
136
echo $output->review_page($attemptobj, $slots, $page, $showall, $lastpage, $options, $summarydata);
137
 
138
// Trigger an event for this review.
139
$attemptobj->fire_attempt_reviewed_event();