Moved function quiz_question_used from mod/quiz/locallib.php to question_used in lib/questionlib. Fixed some more links.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
?>
|
||||
|
||||
+1
-19
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
// TODO: remove restriction to quiz
|
||||
$streditingquestion = get_string('editingquestion', 'quiz');
|
||||
if (isset($SESSION->modform->instance)) {
|
||||
$strediting = '<a href="edit.php">'.get_string('editingquiz', 'quiz').'</a> -> '.
|
||||
$strediting = '<a href=".$editurl.">'.get_string('editingquiz', 'quiz').'</a> -> '.
|
||||
$streditingquestion;
|
||||
} else {
|
||||
$strediting = '<a href="edit.php?courseid='.$course->id.'">'.
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user