@@ -135,15 +135,21 @@ public function get_categories_for_context($contextid) {
135
135
136
136
137
137
/**
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.
140
139
*
141
- * @param courseid
140
+ * @param courseid The id of the course of interest.
141
+ * @param includeprototypes true to include prototypes in the returned list.
142
142
* @return array qid => question
143
143
*/
144
- public function get_all_coderunner_questions_in_context ($ contextid ) {
144
+ public function get_all_coderunner_questions_in_context ($ contextid, $ includeprototypes = 0 ) {
145
145
global $ DB ;
146
146
147
+ if ($ includeprototypes ) {
148
+ $ exclprototypes = '' ;
149
+ } else {
150
+ $ exclprototypes = 'AND prototypetype=0 ' ;
151
+ }
152
+
147
153
return $ DB ->get_records_sql ("
148
154
SELECT q.id, ctx.id as contextid, qc.id as category, qc.name as categoryname, q.*, opts.*
149
155
FROM {context} ctx
@@ -152,12 +158,12 @@ public function get_all_coderunner_questions_in_context($contextid) {
152
158
JOIN {question_versions} qv ON qv.questionbankentryid = qbe.id
153
159
JOIN {question} q ON q.id = qv.questionid
154
160
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)
157
162
FROM {question_versions} v
158
163
JOIN {question_bank_entries} be ON be.id = v.questionbankentryid
159
164
WHERE be.id = qbe.id)
160
165
)
166
+ $ exclprototypes
161
167
AND ctx.id = :contextid
162
168
ORDER BY name " , array ('contextid ' => $ contextid ));
163
169
}
@@ -357,10 +363,12 @@ public function print_overall_result($numpasses, $failingtests, $missinganswers)
357
363
*/
358
364
public static function display_prototypes ($ courseid , $ prototypes , $ missingprototypes ) {
359
365
global $ OUTPUT ;
360
-
366
+ ksort ( $ prototypes , SORT_STRING | SORT_FLAG_CASE );
361
367
foreach ($ prototypes as $ prototypename => $ prototype ) {
362
368
if (isset ($ prototype ->usages )) {
369
+ $ name = isset ($ prototype ->name ) ? " ( {$ prototype ->category }/ {$ prototype ->name }) " : ' (global) ' ;
363
370
echo $ OUTPUT ->heading ($ prototypename , 4 );
371
+ echo $ OUTPUT ->heading ($ name , 6 );
364
372
echo html_writer::start_tag ('ul ' );
365
373
foreach ($ prototype ->usages as $ question ) {
366
374
echo html_writer::tag ('li ' , self ::make_question_link ($ courseid , $ question ));
0 commit comments