forked from maths/moodle-qtype_stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompiledquestion.php
158 lines (117 loc) · 5.4 KB
/
compiledquestion.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
// This file is part of Stack - http://stack.maths.ed.ac.uk/
//
// Stack 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.
//
// Stack 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 Stack. If not, see <http://www.gnu.org/licenses/>.
/**
* This script shows the results of a compiling for a question.
* In a readable form, with CAS-content pretty printed.
*
* This is for developers.
*
* @copyright 2022 Aalto University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use question_bank;
require_once(__DIR__.'/../../../../config.php');
require_once($CFG->libdir . '/questionlib.php');
require_once(__DIR__ . '/../locallib.php');
require_once(__DIR__ . '/../../../engine/lib.php');
require_once(__DIR__ . '/../stack/utils.class.php');
require_once(__DIR__ . '/../stack/options.class.php');
require_once(__DIR__ . '/../stack/maximaparser/utils.php');
require_login();
$context = context_system::instance();
require_capability('qtype/stack:usediagnostictools', $context);
$urlparams = [];
$context = context_system::instance();
$PAGE->set_context($context);
$PAGE->set_url('/question/type/stack/adminui/compiledquestion.php', $urlparams);
$title = 'Compiled cache view';
$PAGE->set_title($title);
if (!isset($_GET['qid']) || !is_numeric($_GET['qid'])) {
echo $OUTPUT->header();
echo $OUTPUT->heading($title);
echo '<p>This tool requires a GET parameter "qid" that defines the question being explored.</p>';
echo $OUTPUT->footer();
die();
}
$q = question_bank::load_question($_GET['qid']);
echo $OUTPUT->header();
echo $OUTPUT->heading($title);
echo '<p>This tool presents the cached compialtion results related to a particular question.</p>';
echo '<p>These are mainly for STACK developers, these should not matter for authors or other users. ' .
'However, one may use these to find out what we do to your code before it gets evaluated.</p>';
echo '<h3>Simple details</h3>';
$selected = [
'units' => $q->get_cached('units'),
'langs' => $q->get_cached('langs'),
'forbiddenkeys' => array_keys($q->get_cached('forbiddenkeys')),
];
echo '<pre>' . htmlspecialchars(json_encode($selected, JSON_PRETTY_PRINT), ENT_COMPAT) . '</pre>';
echo '<h3>Question variables</h3>';
if ($q->get_cached('preamble-qv') !== null) {
echo '<p>Preamble:</p>';
echo '<pre>' . htmlspecialchars(maxima_parser_utils::parse($q->get_cached('preamble-qv'))->
toString(['pretty' => true]), ENT_COMPAT) . '</pre>';
}
if ($q->get_cached('contextvariables-qv') !== null) {
echo '<p>Contextvariables:</p>';
echo '<pre>' . htmlspecialchars(maxima_parser_utils::parse($q->get_cached('contextvariables-qv'))->
toString(['pretty' => true]), ENT_COMPAT) . '</pre>';
}
if ($q->get_cached('statement-qv') !== null) {
echo '<p>Question variables:</p>';
echo '<pre>' . htmlspecialchars(maxima_parser_utils::parse($q->get_cached('statement-qv'))->
toString(['pretty' => true]), ENT_COMPAT) . '</pre>';
} else {
echo '<p>No actual question variables.</p>';
}
echo '<h3>PRTs</h3>';
foreach ($q->prts as $prt) {
echo '<h4>' . $prt->get_name() . '</h4>';
echo '<p>Required inputs: ' . json_encode(array_keys($q->get_cached('required')[$prt->get_name()])) . '</p>';
if (isset($q->get_cached('prt-preamble')[$prt->get_name()]) &&
$q->get_cached('prt-preamble')[$prt->get_name()] !== null) {
echo '<p>PRT-preamble:</p>';
echo '<pre>' . htmlspecialchars(maxima_parser_utils::parse($q->get_cached('prt-preamble')[$prt->get_name()])->
toString(['pretty' => true]), ENT_COMPAT) . '</pre>';
}
if (isset($q->get_cached('prt-contextvariables')[$prt->get_name()]) &&
$q->get_cached('prt-contextvariables')[$prt->get_name()] !== null) {
echo '<p>PRT-contextvariables:</p>';
echo '<pre>' . htmlspecialchars(maxima_parser_utils::parse($q->get_cached('prt-contextvariables')[$prt->get_name()])->
toString(['pretty' => true]), ENT_COMPAT) . '</pre>';
}
echo '<p>PRT-logic:</p>';
echo '<pre>' . htmlspecialchars(maxima_parser_utils::parse($q->get_cached('prt-definition')[$prt->get_name()])->
toString(['pretty' => true]), ENT_COMPAT) . '</pre>';
}
echo '<h3>Various text fragments</h3>';
echo '<table><tr><th>Part</th><th>Compiled CASText code</th></tr>';
foreach ($q->compiledcache as $key => $value) {
if (strpos($key, 'castext-') === 0) {
echo '<tr><td>'. $key . '</td><td><pre>';
echo htmlspecialchars(maxima_parser_utils::parse($value)->toString(['pretty' => true]), ENT_COMPAT);
echo '</pre></td></tr>';
}
}
echo '</table>';
echo '<h3>Static strings</h3>';
echo '<p>These were extracted to avoid sending these to the CAS and back.</p>';
echo '<table><tr><th>key</th><th>value</th></tr>';
foreach ($q->get_cached('static-castext-strings') as $key => $value) {
echo '<tr><td><pre>' . $key . '</pre></td><td><pre>' . htmlspecialchars($value, ENT_COMPAT) . '</pre></td></tr>';
}
echo '</table>';
echo $OUTPUT->footer();