public function test_quiz_move_question_up() { $this->assertEquals(quiz_move_question_up('0', 123), '0'); $this->assertEquals(quiz_move_question_up('1,2,0', 1), '1,2,0'); $this->assertEquals(quiz_move_question_up('1,2,0', 0), '1,2,0'); $this->assertEquals(quiz_move_question_up('1,2,0', 2), '2,1,0'); $this->assertEquals(quiz_move_question_up('1,2,0,3,4,0', 3), '1,2,3,0,4,0'); $this->assertEquals(quiz_move_question_up('1,2,3,0,4,0', 4), '1,2,3,4,0,0'); }
$quiz->questions = quiz_repaginate($quiz->questions, 0); } // Get the list of question ids had their check-boxes ticked. $selectedquestionids = array(); $params = (array) data_submitted(); foreach ($params as $key => $value) { if (preg_match('!^s([0-9]+)$!', $key, $matches)) { $selectedquestionids[] = $matches[1]; } } $afteractionurl = new moodle_url($thispageurl); if ($scrollpos) { $afteractionurl->param('scrollpos', $scrollpos); } if (($up = optional_param('up', false, PARAM_INT)) && confirm_sesskey()) { $quiz->questions = quiz_move_question_up($quiz->questions, $up); $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id)); quiz_delete_previews($quiz); redirect($afteractionurl); } if (($down = optional_param('down', false, PARAM_INT)) && confirm_sesskey()) { $quiz->questions = quiz_move_question_down($quiz->questions, $down); $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id)); quiz_delete_previews($quiz); redirect($afteractionurl); } if (optional_param('repaginate', false, PARAM_BOOL) && confirm_sesskey()) { // Re-paginate the quiz. $questionsperpage = optional_param('questionsperpage', $quiz->questionsperpage, PARAM_INT); $quiz->questions = quiz_repaginate($quiz->questions, $questionsperpage); $DB->set_field('quiz', 'questions', $quiz->questions, array('id' => $quiz->id));
// Get the list of question ids had their check-boxes ticked. $selectedslots = array(); $params = (array) data_submitted(); foreach ($params as $key => $value) { if (preg_match('!^s([0-9]+)$!', $key, $matches)) { $selectedslots[] = $matches[1]; } } $afteractionurl = new moodle_url($thispageurl); if ($scrollpos) { $afteractionurl->param('scrollpos', $scrollpos); } if (($up = optional_param('up', false, PARAM_INT)) && confirm_sesskey()) { quiz_move_question_up($quiz, $up); quiz_delete_previews($quiz); redirect($afteractionurl); } if (($down = optional_param('down', false, PARAM_INT)) && confirm_sesskey()) { quiz_move_question_down($quiz, $down); quiz_delete_previews($quiz); redirect($afteractionurl); } if (optional_param('repaginate', false, PARAM_BOOL) && confirm_sesskey()) { // Re-paginate the quiz. $questionsperpage = optional_param('questionsperpage', $quiz->questionsperpage, PARAM_INT); quiz_repaginate_questions($quiz->id, $questionsperpage ); quiz_delete_previews($quiz);