Fixed bug reported at http://moodle.org/mod/forum/discuss.php?d=23526
This commit is contained in:
@@ -486,6 +486,14 @@ function quiz_print_cat_question_list($course, $categoryid, $quizselected=true,
|
||||
|
||||
// hide-feature
|
||||
$showhidden = $showhidden ? '' : " AND hidden = '0'";
|
||||
|
||||
if (!$totalnumber = count_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden")) {
|
||||
echo "<p align=\"center\">";
|
||||
print_string("noquestions", "quiz");
|
||||
echo "</p>";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$questions = get_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden", 'qtype, name ASC', '*', $page*$perpage, $perpage)) {
|
||||
echo "<p align=\"center\">";
|
||||
print_string("noquestions", "quiz");
|
||||
@@ -557,9 +565,7 @@ function quiz_print_cat_question_list($course, $categoryid, $quizselected=true,
|
||||
quiz_category_select_menu($course->id, false, true, $category->id);
|
||||
echo "</td></tr></table>";
|
||||
|
||||
$numquestions = count($questions);
|
||||
|
||||
print_paging_bar($numquestions, $page, $perpage,
|
||||
print_paging_bar($totalnumber, $page, $perpage,
|
||||
"edit.php?perpage=$perpage&");
|
||||
|
||||
if ($quizselected) {
|
||||
|
||||
@@ -1420,8 +1420,12 @@ function quiz_extract_responses($questions, $responses, $defaultevent) {
|
||||
*/
|
||||
function quiz_regrade_question_in_quizzes($question, $quizlist) {
|
||||
|
||||
if (empty($quizlist)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$quizlist = implode(',', $quizlist);
|
||||
if (empty($quizlist)) { // assume that all quizzes are affected
|
||||
if ($quizlist == 'all') { // assume that all quizzes are affected
|
||||
if (! $instances = get_records('quiz_question_instances',
|
||||
'question', $question->id)) {
|
||||
// No instances were found, so it successfully regraded all of them
|
||||
|
||||
+33
-33
@@ -207,48 +207,48 @@
|
||||
}
|
||||
|
||||
/// now update the question references in the quizzes
|
||||
if (empty($replaceinquiz) || !$quizzes = get_records_list("quiz", "id", implode(',', $replaceinquiz))) {
|
||||
$quizzes = array();
|
||||
}
|
||||
if (!empty($replaceinquiz) and $quizzes = get_records_list("quiz", "id", implode(',', $replaceinquiz))) {
|
||||
|
||||
foreach($quizzes as $quiz) {
|
||||
$questionlist = ",$quiz->questions,"; // a little hack with the commas here. not nice but effective
|
||||
$questionlist = str_replace(",$oldquestionid,", ",$question->id,", $questionlist);
|
||||
$questionlist = substr($questionlist, 1, -1); // and get rid of the surrounding commas again
|
||||
if (!set_field("quiz", 'questions', $questionlist, 'id', $quiz->id)) {
|
||||
error("Could not update questionlist in quiz $quiz->id!");
|
||||
}
|
||||
|
||||
// the quiz_question_instances table needs to be updated too (aah, the joys of duplication :)
|
||||
if (!set_field('quiz_question_instances', 'question', $question->id, 'quiz', $quiz->id, 'question', $oldquestionid)) {
|
||||
error("Could not update question instance!");
|
||||
}
|
||||
if (isset($SESSION->modform) && (int)$SESSION->modform->instance === (int)$quiz->id) {
|
||||
$SESSION->modform->questions = $questionlist;
|
||||
$SESSION->modform->grades[$question->id] = $SESSION->modform->grades[$oldquestionid];
|
||||
unset($SESSION->modform->grades[$oldquestionid]);
|
||||
}
|
||||
}
|
||||
|
||||
// set originalquestion in states
|
||||
if ($attempts = get_records_list('quiz_attempts', 'quiz', implode(',', $replaceinquiz))) {
|
||||
foreach ($attempts as $attempt) {
|
||||
set_field('quiz_states', 'originalquestion', $oldquestionid, 'attempt', $attempt->id, 'question', $question->id, 'originalquestion', '0');
|
||||
}
|
||||
}
|
||||
foreach($quizzes as $quiz) {
|
||||
$questionlist = ",$quiz->questions,"; // a little hack with the commas here. not nice but effective
|
||||
$questionlist = str_replace(",$oldquestionid,", ",$question->id,", $questionlist);
|
||||
$questionlist = substr($questionlist, 1, -1); // and get rid of the surrounding commas again
|
||||
if (!set_field("quiz", 'questions', $questionlist, 'id', $quiz->id)) {
|
||||
error("Could not update questionlist in quiz $quiz->id!");
|
||||
}
|
||||
|
||||
// the quiz_question_instances table needs to be updated too (aah, the joys of duplication :)
|
||||
if (!set_field('quiz_question_instances', 'question', $question->id, 'quiz', $quiz->id, 'question', $oldquestionid)) {
|
||||
error("Could not update question instance!");
|
||||
}
|
||||
if (isset($SESSION->modform) && (int)$SESSION->modform->instance === (int)$quiz->id) {
|
||||
$SESSION->modform->questions = $questionlist;
|
||||
$SESSION->modform->grades[$question->id] = $SESSION->modform->grades[$oldquestionid];
|
||||
unset($SESSION->modform->grades[$oldquestionid]);
|
||||
}
|
||||
}
|
||||
|
||||
// set originalquestion in states
|
||||
if ($attempts = get_records_list('quiz_attempts', 'quiz', implode(',', $replaceinquiz))) {
|
||||
foreach ($attempts as $attempt) {
|
||||
set_field('quiz_states', 'originalquestion', $oldquestionid, 'attempt', $attempt->id, 'question', $question->id, 'originalquestion', '0');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// use the old code which simply overwrites old versions
|
||||
// it is also used for creating new questions
|
||||
$question = $QUIZ_QTYPES[$qtype]->save_question($question, $form, $course);
|
||||
$quizlist = array();
|
||||
$replaceinquiz = 'all';
|
||||
}
|
||||
|
||||
if (empty($question->errors) &&
|
||||
$QUIZ_QTYPES[$qtype]->finished_edit_wizard($form)) {
|
||||
$QUIZ_QTYPES[$question->qtype]->get_question_options($question);
|
||||
if (empty($question->errors) && $QUIZ_QTYPES[$qtype]->finished_edit_wizard($form)) {
|
||||
// Automagically regrade all attempts (and states) in the affected quizzes
|
||||
quiz_regrade_question_in_quizzes($question, $quizlist);
|
||||
if (!empty($replaceinquiz)) {
|
||||
$QUIZ_QTYPES[$question->qtype]->get_question_options($question);
|
||||
quiz_regrade_question_in_quizzes($question, $replaceinquiz);
|
||||
}
|
||||
redirect("edit.php");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user