-
Notifications
You must be signed in to change notification settings - Fork 4
/
attemptdetail.php
96 lines (81 loc) · 3.87 KB
/
attemptdetail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This page is a attempt detail of a particular embedquestion attempt.
*
* @package report_embedquestion
* @copyright 2020 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use \report_embedquestion\utils;
require(__DIR__ . '/../../config.php');
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
require_once($CFG->dirroot . '/question/engine/datalib.php');
$cmid = optional_param('cmid', null, PARAM_INT);
$courseid = optional_param('courseid', null, PARAM_INT);
$attemptid = required_param('attempt', PARAM_INT);
if (is_null($cmid) && is_null($courseid)) {
throw new moodle_exception('missingparam', '', '', 'courseid or cmid');
}
if ($cmid) {
[$course, $cm] = get_course_and_cm_from_cmid($cmid);
$context = context_module::instance($cm->id);
$url = new moodle_url('/report/embedquestion/attemptdetail.php',
['cmid' => $cm->id, 'attempt' => $attemptid]);
} else {
$course = get_course($courseid);
$cm = null;
$context = context_course::instance($courseid);
$url = new moodle_url('/report/embedquestion/attemptdetail.php',
['courseid' => $courseid, 'attempt' => $attemptid]);
}
$qa = (new question_engine_data_mapper())->load_question_attempt($attemptid);
$attemptinfo = $DB->get_record('report_embedquestion_attempt', ['questionusageid' => $qa->get_usage_id()], '*', MUST_EXIST);
$userattemptid = $attemptinfo->userid;
require_login($course, false, $cm);
$pagetitle = get_string('attempt-detail-page', 'report_embedquestion');
$title = utils::get_title($context);
$PAGE->set_url($url);
$PAGE->set_pagelayout('popup');
// Set the navbar.
if (is_null($cmid)) {
$PAGE->navbar->add($title, new moodle_url('/report/embedquestion/index.php', ['courseid' => $courseid]));
$PAGE->navbar->add(get_string('page-report-embedquestion-progress-detail', 'report_embedquestion'),
new moodle_url('/report/embedquestion/index.php',
['courseid' => $courseid, 'userid' => $userattemptid, 'usageid' => $qa->get_usage_id()]));
} else {
$PAGE->navbar->add($title, new moodle_url('/report/embedquestion/activity.php', ['cmid' => $cmid]));
$PAGE->navbar->add(get_string('page-report-embedquestion-progress-detail', 'report_embedquestion'),
new moodle_url('/report/embedquestion/activity.php',
['cmid' => $cmid, 'userid' => $userattemptid, 'usageid' => $qa->get_usage_id()]));
}
$PAGE->navbar->add(get_string('attempt-detail-page', 'report_embedquestion'), $url);
if (!has_capability('report/embedquestion:viewallprogress', $context)) {
require_capability('report/embedquestion:viewmyprogress', $context);
if ($userattemptid != $USER->id) {
// At this point, we know this next check will fail, but it generates the error message we want.
require_capability('report/viewallprogress:viewmyprogress', $context);
}
}
$renderer = $PAGE->get_renderer('report_embedquestion');
$PAGE->set_title($pagetitle);
$PAGE->set_heading($pagetitle);
$sumdata = utils::prepare_summary_attempt_information($course->id, $qa);
echo $OUTPUT->header();
echo $renderer->render_attempt_navigation();
echo $OUTPUT->heading($title);
echo $renderer->render_attempt_detail($sumdata, $qa, $context);
echo $OUTPUT->footer();