From e8666d9abbb4d7b9d95d979bb43ea275c6872c1c Mon Sep 17 00:00:00 2001 From: tjhunt Date: Thu, 13 Sep 2007 17:29:08 +0000 Subject: [PATCH] MDL-11081 and MDL-11211 - Implement quiz_question_list_instances. The lach of this function was causing a horrible dataloss bug: MDL-11211. Fix thanks to Janne Mikkonen, refined by me. Merged from MOODLE_16_STABLE. --- mod/quiz/lib.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 3f7422b068..dd23884a58 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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(); } -- 2.39.5