@@ -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 ));
0 commit comments