Skip to content

Commit cead326

Browse files
committed
q-edit - Add warnings back in, rework missing alt-text, improve dependencies page
1 parent 9b6d72e commit cead326

3 files changed

Lines changed: 25 additions & 29 deletions

File tree

adminui/dependencies.php

Lines changed: 7 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 = ?;';
64+
AND NOT v.status = "hidden" AND o.compiledcache != ?;';
7165

72-
$compiled = $DB->get_recordset_sql($query, ['{}']);
73-
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 .
@@ -328,7 +318,7 @@
328318
// Load the whole question, simpler to get the contexts correct that way.
329319
foreach ($qs as $item) {
330320
$q = question_bank::load_question($item->questionid);
331-
$tags = $q->get_question_todos();
321+
list($hastodos, $tags) = $q->get_question_todos();
332322
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q);
333323
$qurl = qbank_previewquestion\helper::question_preview_url($item->questionid,
334324
null, null, null, null, $context);

edit_stack_form.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,13 @@ protected function definition_inner(/* MoodleQuickForm */ $mform) {
218218

219219
// TO-DO: add in warnings here. See b764b39675 for deleted materials.
220220
$warnings = '';
221+
if (isset($this->question->id)) {
222+
$question = question_bank::load_question($this->question->id);
223+
$warnings = implode("<br />", $question->validate_warnings());
224+
}
221225
if (get_class(editors_get_preferred_editor()) !== 'textarea_texteditor') {
222-
$warnings = '<i class="icon fa fa-exclamation-circle text-danger fa-fw"></i>' . stack_string('usetextarea');
226+
$warnings = ($warnings) ? $warnings . '<br />' : $warnings;
227+
$warnings .= '<i class="icon fa fa-exclamation-circle text-danger fa-fw"></i>' . stack_string('usetextarea');
223228
}
224229

225230
// Note that for the editor elements, we are using $mform->getElement('prtincorrect')->setValue(...); instead

question.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,17 +1750,18 @@ public function validate_warnings($errors = false) {
17501750
// 2. Check alt-text exists.
17511751
// Reminder: previous approach in Oct 2021 tried to use libxml_use_internal_errors, but this was a dead end.
17521752
$tocheck = [];
1753-
$text = '';
1754-
if ($this->questiontextinstantiated !== null) {
1755-
$text = trim($this->questiontextinstantiated->get_rendered());
1756-
}
1757-
if ($text !== '') {
1758-
$tocheck[stack_string('questiontext')] = $text;
1759-
}
1760-
$ct = $this->get_generalfeedback_castext();
1761-
$text = trim($ct->get_rendered($this->castextprocessor));
1762-
if ($text !== '') {
1763-
$tocheck[stack_string('generalfeedback')] = $text;
1753+
$fields = ['questiontext', 'specificfeedback', 'generalfeedback', 'questiondescription'];
1754+
foreach ($fields as $field) {
1755+
$text = '';
1756+
$fieldinstantiated = $field . 'instantiated';
1757+
if ($this->{$fieldinstantiated} !== null) {
1758+
$text = trim($this->{$fieldinstantiated}->get_rendered());
1759+
} else {
1760+
$text = trim($this->{$field});
1761+
}
1762+
if ($text !== '') {
1763+
$tocheck[stack_string($field)] = $text;
1764+
}
17641765
}
17651766
// This is a compromise. We concatinate all nodes and we don't instantiate this!
17661767
foreach ($this->prts as $prt) {

0 commit comments

Comments
 (0)