Skip to content

Commit

Permalink
Merge branch 'MDL-53507_29' of git://github.com/timhunt/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_29_STABLE
  • Loading branch information
danpoltawski committed Mar 26, 2016
2 parents 3668f28 + 03edf12 commit bd9348c
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 10 deletions.
23 changes: 15 additions & 8 deletions mod/quiz/classes/structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,17 @@ public function move_slot($idmove, $idmoveafter, $page) {
$moveafterslotnumber = (int) $this->slots[$idmoveafter]->slot;
}

// If the action came in as moving a slot to itself, normalise this to
// moving the slot to after the previous slot.
if ($moveafterslotnumber == $movingslotnumber) {
$moveafterslotnumber = $moveafterslotnumber - 1;
}

$followingslotnumber = $moveafterslotnumber + 1;
if ($followingslotnumber == $movingslotnumber) {
$followingslotnumber += 1;
}

// Check the target page number is OK.
if ($page == 0) {
$page = 1;
Expand All @@ -716,16 +727,10 @@ public function move_slot($idmove, $idmoveafter, $page) {
$page < 1) {
throw new \coding_exception('The target page number is too small.');
} else if (!$this->is_last_slot_in_quiz($moveafterslotnumber) &&
$page > $this->get_page_number_for_slot($moveafterslotnumber + 1)) {
$page > $this->get_page_number_for_slot($followingslotnumber)) {
throw new \coding_exception('The target page number is too large.');
}

// If the action came in as moving a slot to itself, normalise this to
// moving the slot to after the previosu slot.
if ($moveafterslotnumber == $movingslotnumber) {
$moveafterslotnumber = $moveafterslotnumber - 1;
}

// Work out how things are being moved.
$slotreorder = array();
if ($moveafterslotnumber > $movingslotnumber) {
Expand Down Expand Up @@ -768,10 +773,12 @@ public function move_slot($idmove, $idmoveafter, $page) {
$headingmoveafter = $movingslotnumber;
$headingmovebefore = $movingslotnumber + 2;
$headingmovedirection = -1;
} else {
} else if ($page < $movingslot->page) {
$headingmoveafter = $movingslotnumber - 1;
$headingmovebefore = $movingslotnumber + 1;
$headingmovedirection = 1;
} else {
return; // Nothing to do.
}
}

Expand Down
25 changes: 25 additions & 0 deletions mod/quiz/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -904,5 +904,30 @@ function xmldb_quiz_upgrade($oldversion) {
// Moodle v2.9.0 release upgrade line.
// Put any upgrade step following this.

if ($oldversion < 2015051102) {
// Update quiz_sections to repair quizzes what were broken by MDL-53507.
$problemquizzes = $DB->get_records_sql("
SELECT quizid, MIN(firstslot) AS firstsectionfirstslot
FROM {quiz_sections}
GROUP BY quizid
HAVING MIN(firstslot) > 1");

if ($problemquizzes) {
$pbar = new progress_bar('upgradegroupmembersonly', 500, true);
$total = count($problemquizzes);
$done = 0;
foreach ($problemquizzes as $problemquiz) {
$DB->set_field('quiz_sections', 'firstslot', 1,
array('quizid' => $problemquiz->quizid,
'firstslot' => $problemquiz->firstsectionfirstslot));
$done += 1;
$pbar->update($done, $total, "Fixing quiz layouts - {$done}/{$total}.");
}
}

// Quiz savepoint reached.
upgrade_mod_savepoint(true, 2015051102, 'quiz');
}

return true;
}
59 changes: 58 additions & 1 deletion mod/quiz/tests/structure_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public function test_move_slot_to_start() {
), $structure);
}

public function test_move_slot_to_down_start_of_second_section() {
public function test_move_slot_down_to_start_of_second_section() {
$quizobj = $this->create_test_quiz(array(
'Heading 1',
array('TF1', 1, 'truefalse'),
Expand All @@ -539,6 +539,63 @@ public function test_move_slot_to_down_start_of_second_section() {
), $structure);
}

public function test_move_first_slot_down_to_start_of_page_2() {
$quizobj = $this->create_test_quiz(array(
'Heading 1',
array('TF1', 1, 'truefalse'),
array('TF2', 2, 'truefalse'),
));
$structure = \mod_quiz\structure::create_for_quiz($quizobj);

$idtomove = $structure->get_question_in_slot(1)->slotid;
$structure->move_slot($idtomove, 0, '2');

$structure = \mod_quiz\structure::create_for_quiz($quizobj);
$this->assert_quiz_layout(array(
'Heading 1',
array('TF1', 1, 'truefalse'),
array('TF2', 1, 'truefalse'),
), $structure);
}

public function test_move_first_slot_to_same_place_on_page_1() {
$quizobj = $this->create_test_quiz(array(
'Heading 1',
array('TF1', 1, 'truefalse'),
array('TF2', 2, 'truefalse'),
));
$structure = \mod_quiz\structure::create_for_quiz($quizobj);

$idtomove = $structure->get_question_in_slot(1)->slotid;
$structure->move_slot($idtomove, 0, '1');

$structure = \mod_quiz\structure::create_for_quiz($quizobj);
$this->assert_quiz_layout(array(
'Heading 1',
array('TF1', 1, 'truefalse'),
array('TF2', 2, 'truefalse'),
), $structure);
}

public function test_move_first_slot_to_before_page_1() {
$quizobj = $this->create_test_quiz(array(
'Heading 1',
array('TF1', 1, 'truefalse'),
array('TF2', 2, 'truefalse'),
));
$structure = \mod_quiz\structure::create_for_quiz($quizobj);

$idtomove = $structure->get_question_in_slot(1)->slotid;
$structure->move_slot($idtomove, 0, '');

$structure = \mod_quiz\structure::create_for_quiz($quizobj);
$this->assert_quiz_layout(array(
'Heading 1',
array('TF1', 1, 'truefalse'),
array('TF2', 2, 'truefalse'),
), $structure);
}

public function test_move_slot_up_to_start_of_second_section() {
$quizobj = $this->create_test_quiz(array(
'Heading 1',
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2015051101;
$plugin->version = 2015051102;
$plugin->requires = 2015050500;
$plugin->component = 'mod_quiz';
$plugin->cron = 60;

0 comments on commit bd9348c

Please sign in to comment.