]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11081 and MDL-11211 - Implement quiz_question_list_instances. The lach of this...
authortjhunt <tjhunt>
Thu, 13 Sep 2007 17:29:08 +0000 (17:29 +0000)
committertjhunt <tjhunt>
Thu, 13 Sep 2007 17:29:08 +0000 (17:29 +0000)
mod/quiz/lib.php

index 3f7422b06887cd58d9dc46d25bb7f6dd1afcac81..dd23884a58357c03c70d1fa6ba5a5198f9be30aa 100644 (file)
@@ -821,11 +821,25 @@ function quiz_get_post_actions() {
 /**
  * Returns an array of names of quizzes that use this question
  *
- * TODO: write this
  * @param object $questionid
  * @return array of strings
  */
 function quiz_question_list_instances($questionid) {
+    global $CFG;
+
+    // TODO: we should also consider other questions that are used by
+    // random questions in this quiz, but that is very hard.
+
+    $sql = "SELECT q.id, q.name
+            FROM {$CFG->prefix}quiz q
+            INNER JOIN
+                 {$CFG->prefix}quiz_question_instances qqi
+            ON q.id = qqi.quiz
+            WHERE qqi.question = '$questionid'";
+
+    if ($instances = get_records_sql_menu($sql)) {
+        return $instances;
+    }
     return array();
 }