From 4b32fd66aba28ecb8f2054d40f6862aac320962e Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Fri, 24 Feb 2006 12:53:47 +0000 Subject: [PATCH] Moved function quiz_question_used from mod/quiz/locallib.php to question_used in lib/questionlib. Fixed some more links. --- lib/questionlib.php | 19 +++++++++++++++++++ mod/quiz/locallib.php | 20 +------------------- question/question.php | 8 ++++---- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/questionlib.php b/lib/questionlib.php index 0fbdb53fb94..0ef5d78fd8f 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -1275,4 +1275,23 @@ function get_questions_category( $category, $noparent=false ) { return $qresults; } +/** +* Array of names of course modules a question appears in +* +* TODO: Currently this works with quiz only +* +* @return array Array of quiz names +* @param integer $id Question id +*/ +function question_used($id) { + + $quizlist = array(); + if ($instances = get_records('quiz_question_instances', 'question', $id)) { + foreach($instances as $instance) { + $quizlist[$instance->quiz] = get_field('quiz', 'name', 'id', $instance->quiz); + } + } + + return $quizlist; +} ?> diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 7b169c6c875..008024b1a9e 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -418,24 +418,6 @@ function quiz_view_dates($quiz) { print_simple_box_end(); } -/** -* Array of names of quizzes a question appears in -* -* @return array Array of quiz names -* @param integer $id Question id -*/ -function quizzes_question_used($id) { - - $quizlist = array(); - if ($instances = get_records('quiz_question_instances', 'question', $id)) { - foreach($instances as $instance) { - $quizlist[$instance->quiz] = get_field('quiz', 'name', 'id', $instance->quiz); - } - } - - return $quizlist; -} - /** * Parse field names used for the replace options on question edit forms @@ -559,7 +541,7 @@ function quizzes_category_used($id, $recursive = false) { //Look for each question in the category if ($questions = get_records('quiz_questions', 'category', $id)) { foreach ($questions as $question) { - $qlist = quizzes_question_used($question->id); + $qlist = question_used($question->id); $quizlist = $quizlist + $qlist; } } diff --git a/question/question.php b/question/question.php index 0f051d1a718..2d6922d2d92 100644 --- a/question/question.php +++ b/question/question.php @@ -98,7 +98,7 @@ // TODO: remove restriction to quiz $streditingquestion = get_string('editingquestion', 'quiz'); if (isset($SESSION->modform->instance)) { - $strediting = ''.get_string('editingquiz', 'quiz').' -> '. + $strediting = ''.get_string('editingquiz', 'quiz').' -> '. $streditingquestion; } else { $strediting = ''. @@ -123,21 +123,21 @@ error("An error occurred trying to delete question (id $question->id)"); } } - redirect("edit.php"); + redirect($editurl); } else { error("Confirmation string was incorrect"); } } else { // TODO: check for other modules using this question - if ($quiznames = quizzes_question_used($id)) { + if ($quiznames = question_used($id)) { $a->questionname = $question->name; $a->quiznames = implode(', ', $quiznames); notify(get_string('questioninuse', 'quiz', $a)); } notice_yesno(get_string("deletequestioncheck", "quiz", $question->name), - "question.php?sesskey=$USER->sesskey&id=$question->id&delete=$delete&confirm=".md5($delete), "edit.php"); + "question.php?sesskey=$USER->sesskey&id=$question->id&delete=$delete&confirm=".md5($delete), $editurl); } print_footer($course); exit;