Skip to content

Commit dcd5503

Browse files
committed
broken-save - Comments and tweaks
1 parent c0afed5 commit dcd5503

7 files changed

Lines changed: 30 additions & 24 deletions

File tree

db/upgrade.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,16 +974,15 @@ function xmldb_qtype_stack_upgrade($oldversion) {
974974
upgrade_plugin_savepoint(true, 2024043000, 'qtype', 'stack');
975975
}
976976

977-
if ($oldversion < 2025042300) {
977+
if ($oldversion < 2025042500) {
978978
$table = new xmldb_table('qtype_stack_options');
979979
$field = new xmldb_field('isbroken', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'stackversion');
980-
// Conditionally launch add field scientificnotation.
981980
if (!$dbman->field_exists($table, $field)) {
982981
$dbman->add_field($table, $field);
983982
}
984983

985984
// STACK savepoint reached.
986-
upgrade_plugin_savepoint(true, 2025042300, 'qtype', 'stack');
985+
upgrade_plugin_savepoint(true, 2025042500, 'qtype', 'stack');
987986
}
988987
// Add new upgrade blocks just above here.
989988

edit_stack_form.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,14 @@ public function set_data($question) {
104104
}
105105

106106
parent::set_data($question);
107+
// If the question is broken we run validation when the form is loaded to display errors.
108+
// We have to temporarily remove the broken flag from the form to stop the validation
109+
// beign by-passed.
107110
if ($question->options->isbroken) {
108111
$mform = $this->_form;
109-
$mform->setDefault('savebroken', 0);
112+
$mform->setDefault('isbroken', 0);
110113
$this->is_validated();
111-
$mform->setDefault('savebroken', 1);
114+
$mform->setDefault('isbroken', 1);
112115
}
113116
}
114117

@@ -174,11 +177,11 @@ protected function definition() {
174177
stack_string('fixdollars'), stack_string('fixdollarslabel'));
175178
$mform->insertElementBefore($fixdollars, 'buttonar');
176179
$mform->addHelpButton('fixdollars', 'fixdollars', 'qtype_stack');
177-
$savebroken = $mform->createElement('checkbox', 'savebroken',
178-
stack_string('savebroken'), stack_string('savebrokenlabel'));
179-
$mform->setDefault('savebroken', $this->question->options->isbroken);
180-
$mform->insertElementBefore($savebroken, 'buttonar');
181-
$mform->addHelpButton('savebroken', 'savebroken', 'qtype_stack');
180+
$isbroken = $mform->createElement('checkbox', 'isbroken',
181+
stack_string('isbroken'), stack_string('isbrokenlabel'));
182+
$mform->setDefault('isbroken', $this->question->options->isbroken);
183+
$mform->insertElementBefore($isbroken, 'buttonar');
184+
$mform->addHelpButton('isbroken', 'isbroken', 'qtype_stack');
182185
$mform->closeHeaderBefore('fixdollars');
183186

184187
// There is no un-closeHeaderBefore, so fake it.
@@ -830,6 +833,7 @@ protected function data_preprocessing_inputs($question) {
830833
foreach ($question->inputs as $inputname => $input) {
831834
$question->{$inputname . 'type'} = $input->type;
832835
$question->{$inputname . 'modelans'} = $input->tans;
836+
// Cast to int required to avoid erroneous validation messages on loading a broken question.
833837
$question->{$inputname . 'boxsize'} = (int) $input->boxsize;
834838
// TO-DO: remove this when we delete it from the DB.
835839
$question->{$inputname . 'strictsyntax'} = true;
@@ -957,7 +961,9 @@ protected function prepare_text_field($field, $text, $format, $itemid, $filearea
957961
// phpcs:ignore moodle.Commenting.MissingDocblock.Function
958962
public function validation($fromform, $files) {
959963
$errors = parent::validation($fromform, $files);
960-
if (empty($fromform['savebroken'])) {
964+
// By-pass STACK-specific validation if question is marked as broken.
965+
// Moodle validation still performed.
966+
if (empty($fromform['isbroken'])) {
961967
$qtype = new qtype_stack();
962968
return $qtype->validate_fromform($fromform, $errors);
963969
} else {

lang/en/qtype_stack.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@
141141
$string['fixdollarslabel'] = 'Replace <code>$...$</code> with <code>\(...\)</code>, <code>$$...$$</code> with <code>\[...\]</code> and <code>@...@</code> with <code>{@...@}</code> on save.';
142142
$string['fixdollars_help'] = 'This option is useful if are copying and pasting (or typing) TeX with <code>$...$</code> and <code>$$...$$</code> delimiters. Those delimiters will be replaced by the recommended delimiters during the save process.';
143143
$string['forbiddendoubledollars'] = 'Please use the delimiters <code>\(...\)</code> for inline maths and <code>\[...\]</code> for display maths. <code>$...$</code> and <code>$$...$$</code> are not permitted. There is an option at the end of the form to fix this automatically.';
144-
$string['savebroken'] = 'Save as broken';
145-
$string['savebrokenlabel'] = 'Mark the question as broken. This will allow the question to be saved even with errors but it will not be displayed.';
146-
$string['savebroken_help'] = 'This option allows you to save your work even if a question is incomplete or has errors. You or a colleague can then return to work on it later.';
144+
$string['isbroken'] = 'Save as broken';
145+
$string['isbrokenlabel'] = 'Mark the question as broken. This will allow the question to be saved even with errors but it will not be displayed to students.';
146+
$string['isbroken_help'] = 'This option allows you to save your work even if a question is incomplete or has errors. You or a colleague can then return to work on it later.';
147147
$string['forbidfloat'] = 'Forbid float';
148148
$string['forbidfloat_help'] = 'If set to yes, then any answer of the student which has a floating point number will be rejected as invalid.';
149149
$string['forbidfloat_link'] = '%%WWWROOT%%/question/type/stack/doc/doc.php/Authoring/Inputs.md#Forbid_Floats';

question.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,13 @@ public function start_attempt(question_attempt_step $step, $variant) {
364364
* Once we know the random seed, we can initialise all the other parts of the question.
365365
*/
366366
public function initialise_question_from_seed() {
367+
// If the question is marked as broken skip straight to error output.
367368
// We can detect a logically faulty question by checking if the cache can
368369
// return anything if it can't then we can simply skip to the output of errors.
369-
if ($this->get_cached('units') !== null) {
370+
if ($this->isbroken) {
371+
// Question is marked as broken. Students should not see it.
372+
$this->runtimeerrors[stack_string('questionbroken')] = true;
373+
} else if ($this->get_cached('units') !== null) {
370374
// Build up the question session out of all the bits that need to go into it.
371375
// 1. question variables.
372376
$session = new stack_cas_session2([], $this->options, $this->seed);
@@ -491,9 +495,6 @@ public function initialise_question_from_seed() {
491495
if ($session->get_valid()) {
492496
$session->instantiate();
493497
}
494-
if ($this->isbroken) {
495-
$this->runtimeerrors[stack_string('questionbroken')] = true;
496-
}
497498
if ($session->get_errors()) {
498499
// In previous versions we threw an exception here.
499500
// Upgrade and import stops errors being caught during validation when the question was edited or deployed.

questiontype.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function save_question_options($fromform) {
174174
$options->logicsymbol = $fromform->logicsymbol;
175175
$options->matrixparens = $fromform->matrixparens;
176176
$options->variantsselectionseed = $fromform->variantsselectionseed;
177-
$options->isbroken = !empty($fromform->savebroken) ? 1 : 0;
177+
$options->isbroken = !empty($fromform->isbroken) ? 1 : 0;
178178

179179
// We will not have the values for this.
180180
$options->compiledcache = '{}';

stack/maxima/stackmaxima.mac

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ if is(MAXIMA_VERSION_NUM>30.0) then compile(scientific_notation)$
191191
texput(QMCHAR, "\\color{red}{?}");
192192
texput(theta, "\\theta");
193193

194-
/* Issue #615 suggests we make matrix multiplication much more promenent.
194+
/* Issue #615 suggests we make matrix multiplication much more promenent.
195195
This is possible, but would be confused with notation for Hadamard product.
196196

197197
texput(".","\\circ ",infix);
@@ -3267,14 +3267,14 @@ hasAddConst(expr, vars) := block([othervars, const, deriv, allvariables, strict]
32673267
if debug then print(["Variables in expression: ", othervars]),
32683268
for var in vars do othervars : delete(var,othervars),
32693269
if debug then print(["Remaining variables after deletion: ", othervars]),
3270-
3270+
32713271

32723272
/* check number of candidates, should be exactly 1 */
32733273
if length(othervars) = 0 then
32743274
return([false, "ATAddConst_noconst"]),
32753275
if length(othervars) > 1 then
32763276
return([false, "ATAddConst_severalconst"]),
3277-
3277+
32783278
/* if there is one candidate, check if it's exactly additive or something else */
32793279
const : othervars[1],
32803280
deriv : ev(diff(expr,const), simp),
@@ -3507,4 +3507,4 @@ is_lang(code):=ev(is(%_STACK_LANG=code),simp=true)$
35073507

35083508
/* Stack expects some output with the version number the output happens at */
35093509
/* maximalocal.mac after additional library loading */
3510-
stackmaximaversion:2025040200$
3510+
stackmaximaversion:2025042500$

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
defined('MOODLE_INTERNAL') || die();
2626

27-
$plugin->version = 2025042300;
27+
$plugin->version = 2025042500;
2828
$plugin->requires = 2022041900;
2929
$plugin->cron = 0;
3030
$plugin->component = 'qtype_stack';

0 commit comments

Comments
 (0)