Skip to content

Commit 6cb1a26

Browse files
committed
Improve output of prototype-usage script.
1 parent d1948a0 commit 6cb1a26

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

classes/bulk_tester.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,21 @@ public function get_categories_for_context($contextid) {
135135

136136

137137
/**
138-
* Get all the non-prototype coderunner questions in the given context.
139-
* Only the latest version of a question is returned.
138+
* Get all the coderunner questions in the given context.
140139
*
141-
* @param courseid
140+
* @param courseid The id of the course of interest.
141+
* @param includeprototypes true to include prototypes in the returned list.
142142
* @return array qid => question
143143
*/
144-
public function get_all_coderunner_questions_in_context($contextid) {
144+
public function get_all_coderunner_questions_in_context($contextid, $includeprototypes=0) {
145145
global $DB;
146146

147+
if ($includeprototypes) {
148+
$exclprototypes = '';
149+
} else {
150+
$exclprototypes = 'AND prototypetype=0';
151+
}
152+
147153
return $DB->get_records_sql("
148154
SELECT q.id, ctx.id as contextid, qc.id as category, qc.name as categoryname, q.*, opts.*
149155
FROM {context} ctx
@@ -152,12 +158,12 @@ public function get_all_coderunner_questions_in_context($contextid) {
152158
JOIN {question_versions} qv ON qv.questionbankentryid = qbe.id
153159
JOIN {question} q ON q.id = qv.questionid
154160
JOIN {question_coderunner_options} opts ON opts.questionid = q.id
155-
WHERE prototypetype = 0
156-
AND (qv.version = (SELECT MAX(v.version)
161+
WHERE (qv.version = (SELECT MAX(v.version)
157162
FROM {question_versions} v
158163
JOIN {question_bank_entries} be ON be.id = v.questionbankentryid
159164
WHERE be.id = qbe.id)
160165
)
166+
$exclprototypes
161167
AND ctx.id = :contextid
162168
ORDER BY name", array('contextid' => $contextid));
163169
}
@@ -357,10 +363,12 @@ public function print_overall_result($numpasses, $failingtests, $missinganswers)
357363
*/
358364
public static function display_prototypes($courseid, $prototypes, $missingprototypes) {
359365
global $OUTPUT;
360-
366+
ksort($prototypes, SORT_STRING | SORT_FLAG_CASE);
361367
foreach ($prototypes as $prototypename => $prototype) {
362368
if (isset($prototype->usages)) {
369+
$name = isset($prototype->name) ? " ({$prototype->category}/{$prototype->name})" : ' (global)';
363370
echo $OUTPUT->heading($prototypename, 4);
371+
echo $OUTPUT->heading($name, 6);
364372
echo html_writer::start_tag('ul');
365373
foreach ($prototype->usages as $question) {
366374
echo html_writer::tag('li', self::make_question_link($courseid, $question));

prototypeusage.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
if (!has_capability('moodle/question:editall', $coursecontext)) {
5555
echo html::tag('p', get_string('unauthorisedbulktest', 'qtype_coderunner'));
5656
} else {
57-
$questions = $bulktester->get_all_coderunner_questions_in_context($coursecontextid);
57+
$questions = $bulktester->get_all_coderunner_questions_in_context($coursecontextid, true);
5858
$prototypequestions = qtype_coderunner::get_all_prototypes($courseid);
5959
$prototypes = [];
6060
foreach ($prototypequestions as $prototype) {
@@ -73,6 +73,10 @@
7373
$missing[$type] = array($question);
7474
}
7575
} else {
76+
if ($question->prototypetype != 0) {
77+
$prototypes[$type]->name = $question->name;
78+
$prototypes[$type]->category = $question->categoryname;
79+
}
7680
if (isset($prototypes[$type]->usages)) {
7781
$prototypes[$type]->usages[] = $question;
7882
} else {

0 commit comments

Comments
 (0)