MDL-29176 quiz editing: can't move questions onto a new page.

This commit is contained in:
Tim Hunt 2011-12-15 19:32:37 +00:00
parent 73c0d46416
commit 800944b015

View File

@ -356,11 +356,19 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
//move to the end of the selected page
$pagebreakpositions = array_keys($questions, 0);
$numpages = count($pagebreakpositions);
// Ensure the target page number is in range.
$moveselectedonpage = max(1, min($moveselectedonpage, $pagebreakpositions));
for ($i = $moveselectedonpage; $i > $numpages; $i--) {
$questions[] = 0;
$pagebreakpositions[] = count($questions) - 1;
}
$moveselectedpos = $pagebreakpositions[$moveselectedonpage - 1];
// Do the move.
array_splice($questions, $moveselectedpos, 0, $selectedquestionids);
$quiz->questions = implode(',', $questions);
// Update the database.
$DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
$deletepreviews = true;
}