From b11d3741226004ea6e64a04aaf015e878c8736ae Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 7 Jul 2011 12:37:40 +0100 Subject: [PATCH] MDL-27483 make quiz repagination more robust. --- mod/quiz/lib.php | 3 ++- mod/quiz/locallib.php | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 3371e15c669..cde3701c9b0 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -101,7 +101,8 @@ function quiz_update_instance($quiz, $mform) { // Repaginate, if asked to. if (!$quiz->shufflequestions && !empty($quiz->repaginatenow)) { require_once($CFG->dirroot . '/mod/quiz/locallib.php'); - $quiz->questions = quiz_repaginate($oldquiz->questions, $quiz->questionsperpage); + $quiz->questions = quiz_repaginate(quiz_clean_layout($oldquiz->questions, true), + $quiz->questionsperpage); } unset($quiz->repaginatenow); diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 591eb0a77a9..601f9a5a175 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -84,11 +84,9 @@ function quiz_create_attempt($quiz, $attemptnumber, $lastattempt, $timenow, $isp $attempt->quiz = $quiz->id; $attempt->userid = $USER->id; $attempt->preview = 0; + $attempt->layout = quiz_clean_layout($quiz->questions, true); if ($quiz->shufflequestions) { - $attempt->layout = quiz_clean_layout(quiz_repaginate( - $quiz->questions, $quiz->questionsperpage, true), true); - } else { - $attempt->layout = quiz_clean_layout($quiz->questions, true); + $attempt->layout = quiz_repaginate($attempt->layout, $quiz->questionsperpage, true); } } else { // Build on last attempt. @@ -240,7 +238,9 @@ function quiz_number_of_questions_in_quiz($layout) { /** * Re-paginates the quiz layout * - * @param string $layout The string representing the quiz layout. + * @param string $layout The string representing the quiz layout. If there is + * if there is any doubt about the quality of the input data, call + * quiz_clean_layout before you call this function. * @param int $perpage The number of questions per page * @param bool $shuffle Should the questions be reordered randomly? * @return string the new layout string -- 2.11.4.GIT