Skip to content

Commit 595201a

Browse files
committed
broken-save - Add search for broken questions to dependencies page
1 parent f90e1bb commit 595201a

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

adminui/dependencies.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
echo $OUTPUT->single_button(
9999
new moodle_url($PAGE->url, ['todo' => 1, 'sesskey' => sesskey()]),
100100
'Find "todo"');
101+
echo $OUTPUT->single_button(
102+
new moodle_url($PAGE->url, ['broken' => 1, 'sesskey' => sesskey()]),
103+
'Find "broken"');
101104

102105
if (data_submitted() && optional_param('includes', false, PARAM_BOOL)) {
103106
/*
@@ -329,4 +332,37 @@
329332
echo '</tbody></table>';
330333
}
331334

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+
332368
echo $OUTPUT->footer();

0 commit comments

Comments
 (0)