Skip to content

Commit a1da5d3

Browse files
committed
Merge branch 'broken-save' of github.com:maths/moodle-qtype_stack into broken-save
2 parents 6d1e606 + 1dc56e9 commit a1da5d3

49 files changed

Lines changed: 2828 additions & 2512 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

adminui/dependencies.php

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,22 @@
5656
'{qtype_stack_options} o, {question_versions} v WHERE q.id = o.questionid AND q.id = v.id ' . '
5757
AND NOT v.status = "hidden" AND o.compiledcache = ?;';
5858

59-
$notcompiled = $DB->get_recordset_sql($query, ['{}']);
60-
61-
$nnotcompiled = 0;
62-
$ncompiled = 0;
63-
foreach ($notcompiled as $item) {
64-
$nnotcompiled = $item->notcompiled;
65-
}
66-
$notcompiled->close();
59+
$notcompiled = $DB->get_record_sql($query, ['{}']);
60+
$nnotcompiled = $notcompiled->notcompiled;
6761

6862
$query = 'SELECT count(*) as compiled FROM {question} q, ' .
6963
'{qtype_stack_options} o, {question_versions} v WHERE q.id = o.questionid AND q.id = v.id ' . '
70-
AND NOT v.status = "hidden" AND o.compiledcache = ?;';
71-
72-
$compiled = $DB->get_recordset_sql($query, ['{}']);
64+
AND NOT v.status = "hidden" AND o.compiledcache != ?;';
7365

74-
foreach ($compiled as $item) {
75-
$ncompiled = $item->compiled;
76-
}
77-
$compiled->close();
66+
$compiled = $DB->get_record_sql($query, ['{}']);
67+
$ncompiled = $compiled->compiled;
7868

7969
echo $OUTPUT->header();
8070
echo $OUTPUT->heading($title);
8171

8272
echo '<p>This tool only acts on succesfully compiled questions, to compile questions run the bulk tester ' .
8373
'or preview/use those questions.</p><p>';
84-
if ($ncompiled !== $notcompiled) {
74+
if ($nnotcompiled) {
8575
echo stack_string_error('errors') . '. ';
8676
}
8777
echo 'Currently there are ' . $ncompiled . ' compiled questions and ' . $nnotcompiled .
@@ -108,6 +98,9 @@
10898
echo $OUTPUT->single_button(
10999
new moodle_url($PAGE->url, ['todo' => 1, 'sesskey' => sesskey()]),
110100
'Find "todo"');
101+
echo $OUTPUT->single_button(
102+
new moodle_url($PAGE->url, ['broken' => 1, 'sesskey' => sesskey()]),
103+
'Find "broken"');
111104

112105
if (data_submitted() && optional_param('includes', false, PARAM_BOOL)) {
113106
/*
@@ -328,7 +321,7 @@
328321
// Load the whole question, simpler to get the contexts correct that way.
329322
foreach ($qs as $item) {
330323
$q = question_bank::load_question($item->questionid);
331-
$tags = $q->get_question_todos();
324+
list($hastodos, $tags) = $q->get_question_todos();
332325
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q);
333326
$qurl = qbank_previewquestion\helper::question_preview_url($item->questionid,
334327
null, null, null, null, $context);
@@ -339,4 +332,37 @@
339332
echo '</tbody></table>';
340333
}
341334

335+
if (data_submitted() && optional_param('broken', false, PARAM_BOOL)) {
336+
/*
337+
* Question marked as broken.
338+
*/
339+
$qs = $DB->get_recordset_sql('SELECT q.id as questionid, q.name as name
340+
FROM {question} q
341+
JOIN {question_versions} qv ON qv.questionid = q.id
342+
JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid
343+
JOIN {qtype_stack_options} o ON q.id = o.questionid
344+
WHERE o.isbroken = 1
345+
AND qv.version = (
346+
SELECT MAX(version)
347+
FROM {question_versions} v
348+
WHERE v.questionbankentryid = qbe.id
349+
)');
350+
echo '<h4>Questions with most recent version marked as broken</h4>';
351+
echo '<table><thead><tr><th>Question</th><th>Version</th></thead><tbody>';
352+
// Load the whole question, simpler to get the contexts correct that way.
353+
foreach ($qs as $item) {
354+
$q = question_bank::load_question($item->questionid);
355+
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q);
356+
$editurl = new \moodle_url('/question/bank/editquestion/question.php', [
357+
'id' => $urlparams['questionid'],
358+
'returnURL' => new moodle_url('/question/type/stack/adminui/dependencies.php'),
359+
'courseid' => $urlparams['courseid'],
360+
]);
361+
echo '<tr><td>' . $item->name . ' ' .
362+
$OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit'))) .
363+
'</td><td>' . $q->version . '</td></tr>';
364+
}
365+
echo '</tbody></table>';
366+
}
367+
342368
echo $OUTPUT->footer();

api/README.md

Lines changed: 344 additions & 344 deletions
Large diffs are not rendered by default.

api/emulation/Localization.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,17 @@ function current_language() {
3636
function get_string($identifier, $component, $a = null) {
3737
$userlanguage = current_language();
3838

39+
static $string = [];
3940
switch ($userlanguage)
4041
{
4142
case 'de':
42-
static $string = [];
4343
if (empty($string)) {
4444
// Load en values as defaults.
4545
include(__DIR__ .'/../../lang/en/qtype_stack.php');
4646
include(__DIR__ .'/../../lang/de/qtype_stack.php');
4747
}
4848
break;
4949
default:
50-
static $string = [];
5150
if (empty($string)) {
5251
include(__DIR__ .'/../../lang/en/qtype_stack.php');
5352
}

api/public/api.css

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,63 @@ a.nav-link:link, a.nav-link:visited, a.nav-link:hover, a.nav-link:active {
5656
.sidebar {width: 100%; height: auto; position: relative; border-style: solid; border-width: 0px 0px 1px 0px; border-color: #e0dfdf}
5757
.sidebar a {text-align: center; float: none;}
5858
.main-content {margin-left: 0; padding: 0px;}
59-
}
59+
}
60+
.container-footer {
61+
width: 100%;
62+
padding-right: 1rem;
63+
padding-left: 1rem;
64+
max-width: 97.75rem;
65+
margin-right: auto;
66+
margin-left: auto
67+
}
68+
@media (min-width: 768px) {
69+
.container-footer {
70+
padding-right:2rem;
71+
padding-left: 2rem
72+
}
73+
}
74+
.footer-discover {
75+
background: #252525
76+
}
77+
.footer-discover-heading {
78+
width: 100%;
79+
padding-right: 1rem;
80+
padding-left: 1rem;
81+
max-width: 97.75rem;
82+
margin-right: auto;
83+
margin-left: auto;
84+
font-size: calc(1.34375rem + .65625vw);
85+
padding-top: 1.5rem;
86+
padding-bottom: 1.3rem;
87+
margin-bottom: 0;
88+
font-family: "Crimson Text",serif;
89+
font-weight: 400;
90+
line-height: 1;
91+
color: #b0b0b0;
92+
text-transform: uppercase
93+
}
94+
@media (min-width: 768px) {
95+
.footer-discover-heading {
96+
padding-right:2rem;
97+
padding-left: 2rem
98+
}
99+
}
100+
@media (min-width: 1600px) {
101+
.footer-discover-heading {
102+
font-size:2rem
103+
}
104+
}
105+
.footer {
106+
padding: 1rem 0;
107+
color: #d4d4d4;
108+
background: linear-gradient(to bottom,#3a3a3a 0,#252525 100%) repeat scroll 0 0;
109+
background-color: #3a3a3a;
110+
}
111+
footer a {
112+
color: white;
113+
text-decoration: none
114+
}
115+
footer a:hover {
116+
--edgel-link-color-rgb: var(--edgel-link-hover-color-rgb);
117+
text-decoration: underline
118+
}

api/public/favicon.ico

101 KB
Binary file not shown.

api/public/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with Stack. If not, see <http://www.gnu.org/licenses/>.
1616

1717
/**
18-
* This script handles the various deploy/undeploy actions from questiontestrun.php.
18+
* STACK API main landing page.
1919
*
2020
* @package qtype_stack
2121
* @copyright 2023 RWTH Aachen
@@ -51,5 +51,5 @@
5151
$app->post('/grade', GradingController::class);
5252
$app->post('/validate', ValidationController::class);
5353
$app->post('/download', DownloadController::class);
54-
54+
$app->redirect('/{page}', '/sample.php', 301);
5555
$app->run();

api/public/sample.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function toggleAnswer(button) {
117117
<span style="display: flex; align-items: center; font-size: 20px">
118118
<span style="display: flex; align-items: center;">
119119
<img src="logo_large.png" style="height: 50px;">
120-
<span style="font-size: 50px;"><b>STACK </b></span>
120+
<span style="font-size: 50px;"><b>STACK API demonstration</b></span>
121121
</span>
122122
&nbsp;| Online assessment
123123
</span>
@@ -127,7 +127,6 @@ function toggleAnswer(button) {
127127
<div class="col-lg-9">
128128
<p>
129129
STACK is the world-leading open-source online assessment system for mathematics and STEM.
130-
It is available for Moodle, ILIAS and as an integration through LTI.
131130
</p>
132131
<p>
133132
This page allows you to try some STACK questions. Click on the name of a question in the menu to view it.
@@ -138,8 +137,12 @@ function toggleAnswer(button) {
138137
<p>
139138
STACK questions can have random variants. If these are available for a question, you can click 'Next Variant' to see another.
140139
</p>
141-
<a>
142-
For more information on STACK, visit <a href="https://stack-assessment.org/">the STACK community page</a>.
140+
<p>
141+
STACK is also available for direct integration in Moodle, ILIAS and through LTI.
142+
For more information visit <a href="https://stack-assessment.org/">the STACK community page</a>.
143+
</p>
144+
<p>
145+
There is also a <a href="/stack.php">library of STACK questions</a> on this demo site.
143146
</p>
144147
<hr>
145148
</div>
@@ -180,11 +183,21 @@ function toggleAnswer(button) {
180183
</div>
181184
</div>
182185
</div>
186+
<div class="col-lg-9">
187+
<hr />
188+
<p style="font-size: 0.875em;color:gray;">
189+
The STACK source code, including this API, is Licensed under the GNU General Public, License Version 3.
190+
Documentation, sample questions and materials, are licensed under Creative Commons Attribution-ShareAlike 4.0 International.
191+
See the <a href="https://docs.stack-assessment.org/en/About/License/">STACK licence</a> page for full details.
192+
</p>
193+
<? readfile(__DIR__ . '/stackfooter.html') ?>
194+
</div>
183195
</div>
184196
</div>
185197
<br>
186198
</div>
187199
</div>
200+
188201
</body>
189202
<script type="text/javascript">
190203
<?php

api/public/stack.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function setQuestion(question) {
133133
</div>
134134
<?php echo stack_string('api_choose_q')?>:
135135
<?php
136-
$files = stack_question_library::get_file_list('../../samplequestions/*');
136+
$files = stack_question_library::get_file_list('../../samplequestions/stacklibrary/*');
137137
function render_directory($dirdetails) {
138138
echo '<div style="margin-left: 30px;">';
139139
foreach ($dirdetails as $file) {
@@ -193,7 +193,7 @@ function render_directory($dirdetails) {
193193
</div>
194194
</div>
195195
<br>
196-
196+
<? readfile(__DIR__ . '/stackfooter.html') ?>
197197
</body>
198198
<script>
199199
const yamlEditor = CodeMirror.fromTextArea(document.getElementById("xml"),

api/public/stackfooter.html

Whitespace-only changes.

api/public/stackshared.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ function send() {
9292
const inputs = json.questioninputs;
9393
let correctAnswers = '';
9494
// Show correct answers.
95-
for (const [name, input] of Object.entries(inputs)) {
95+
const placeholders = question.matchAll(/\[\[input:([a-zA-Z][a-zA-Z0-9_]*)\]\]/g);
96+
for (const holder of placeholders) {
97+
const name = holder[1];
98+
const input = inputs[name];
9699
question = question.replace(`[[input:${name}]]`, input.render);
97100
question = question.replace(`[[validation:${name}]]`, `<span name='${validationPrefix + name}'></span>`);
98101
if (input.samplesolutionrender && name !== 'remember') {

0 commit comments

Comments
 (0)