MDL-34599 quiz attempts: more robust if page number out of range.

Rather than throwing an exception, we should just show the first/last
page of the quiz if the page number is out-of-range.
This commit is contained in:
Tim Hunt
2012-07-27 11:42:03 +01:00
parent 55a568fa7d
commit ff2ec2cb95
4 changed files with 21 additions and 9 deletions
+11 -1
View File
@@ -555,6 +555,16 @@ class quiz_attempt {
}
}
/**
* If the given page number is out of range (before the first page, or after
* the last page, chnage it to be within range).
* @param int $page the requested page number.
* @return int a safe page number to use.
*/
public function force_page_number_into_range($page) {
return min(max($page, 0), count($this->pagelayout) - 1);
}
// Simple getters ==========================================================
public function get_quiz() {
return $this->quizobj->get_quiz();
@@ -1101,7 +1111,7 @@ class quiz_attempt {
}
/**
* Initialise the JS etc. required all the questions on a page..
* Initialise the JS etc. required all the questions on a page.
* @param mixed $page a page number, or 'all'.
*/
public function get_html_head_contributions($page = 'all', $showall = false) {