Merge branch 'MDL-35939-37' of git://github.com/rezaies/moodle into MOODLE_37_STABLE

This commit is contained in:
Andrew Nicols
2019-08-15 12:03:48 +08:00
6 changed files with 119 additions and 6 deletions
+1 -2
View File
@@ -120,9 +120,8 @@ $navbc = $attemptobj->get_navigation_panel($output, 'quiz_attempt_nav_panel', $p
$regions = $PAGE->blocks->get_regions();
$PAGE->blocks->add_fake_block($navbc, reset($regions));
$title = get_string('attempt', 'quiz', $attemptobj->get_attempt_number());
$headtags = $attemptobj->get_html_head_contributions($page);
$PAGE->set_title($attemptobj->get_quiz_name());
$PAGE->set_title($attemptobj->attempt_page_title($page));
$PAGE->set_heading($attemptobj->get_course()->fullname);
if ($attemptobj->is_last_page($page)) {
+50 -2
View File
@@ -1402,12 +1402,30 @@ class quiz_attempt {
return $this->quizobj->start_attempt_url($page);
}
/**
* Generates the title of the attempt page.
*
* @param int $page the page number (starting with 0) in the attempt.
* @return string
*/
public function attempt_page_title(int $page) : string {
if ($this->get_num_pages() > 1) {
$a = new stdClass();
$a->name = $this->get_quiz_name();
$a->currentpage = $page + 1;
$a->totalpages = $this->get_num_pages();
$title = get_string('attempttitlepaged', 'quiz', $a);
} else {
$title = get_string('attempttitle', 'quiz', $this->get_quiz_name());
}
return $title;
}
/**
* @param int $slot if speified, the slot number of a specific question to link to.
* @param int $page if specified, a particular page to link to. If not givem deduced
* from $slot, or goes to the first page.
* @param int $questionid a question id. If set, will add a fragment to the URL
* to jump to a particuar question on the page.
* @param int $thispage if not -1, the current page. Will cause links to other things on
* this page to be output as only a fragment.
* @return string the URL to continue this attempt.
@@ -1416,6 +1434,15 @@ class quiz_attempt {
return $this->page_and_question_url('attempt', $slot, $page, false, $thispage);
}
/**
* Generates the title of the summary page.
*
* @return string
*/
public function summary_page_title() : string {
return get_string('attemptsummarytitle', 'quiz', $this->get_quiz_name());
}
/**
* @return string the URL of this quiz's summary page.
*/
@@ -1430,6 +1457,27 @@ class quiz_attempt {
return new moodle_url('/mod/quiz/processattempt.php');
}
/**
* Generates the title of the review page.
*
* @param int $page the page number (starting with 0) in the attempt.
* @param bool $showall whether the review page contains the entire attempt on one page.
* @return string
*/
public function review_page_title(int $page, bool $showall = false) : string {
if (!$showall && $this->get_num_pages() > 1) {
$a = new stdClass();
$a->name = $this->get_quiz_name();
$a->currentpage = $page + 1;
$a->totalpages = $this->get_num_pages();
$title = get_string('attemptreviewtitlepaged', 'quiz', $a);
} else {
$title = get_string('attemptreviewtitle', 'quiz', $this->get_quiz_name());
}
return $title;
}
/**
* @param int $slot indicates which question to link to.
* @param int $page if specified, the URL of this particular page of the attempt, otherwise
+5
View File
@@ -98,6 +98,8 @@ $string['attemptincomplete'] = 'That attempt (by {$a}) is not yet completed.';
$string['attemptlast'] = 'Last attempt';
$string['attemptnumber'] = 'Attempt';
$string['attemptquiznow'] = 'Attempt quiz now';
$string['attemptreviewtitle'] = '{$a}: Attempt review';
$string['attemptreviewtitlepaged'] = '{$a->name}: Attempt review (page {$a->currentpage} of {$a->totalpages})';
$string['attempts'] = 'Attempts';
$string['attempts_help'] = 'The total number of attempts allowed (not the number of extra attempts).';
$string['attemptsallowed'] = 'Attempts allowed';
@@ -110,7 +112,10 @@ $string['attemptsnumyourgroups'] = 'Attempts: {$a->total} ({$a->group} from your
$string['attemptsonly'] = 'Show only students with attempts';
$string['attemptstate'] = 'State';
$string['attemptstillinprogress'] = 'Attempt still in progress';
$string['attemptsummarytitle'] = '{$a}: Attempt summary';
$string['attemptsunlimited'] = 'Unlimited attempts';
$string['attempttitle'] = '{$a}';
$string['attempttitlepaged'] = '{$a->name} (page {$a->currentpage} of {$a->totalpages})';
$string['autosaveperiod'] = 'Auto-save delay';
$string['autosaveperiod_desc'] = 'Responses can be saved automatically during quiz attempts. The responses are saved whenever one is changed, and then after this delay. There is a trade-off: a shorter delay increases the server load, but reduces the chance that students lose their work. If you are going to make this delay much shorter, you should change the value gradually and monitor the server load. If the load gets too high, make the delay longer again. Setting the delay to 0 turns off auto-saving.';
$string['back'] = 'Back to preview question';
+1 -1
View File
@@ -106,7 +106,7 @@ if ($attemptobj->is_own_preview()) {
// Set up the page header.
$headtags = $attemptobj->get_html_head_contributions($page, $showall);
$PAGE->set_title($attemptobj->get_quiz_name());
$PAGE->set_title($attemptobj->review_page_title($page, $showall));
$PAGE->set_heading($attemptobj->get_course()->fullname);
// Summary table start. ============================================================================
+1 -1
View File
@@ -87,7 +87,7 @@ $regions = $PAGE->blocks->get_regions();
$PAGE->blocks->add_fake_block($navbc, reset($regions));
$PAGE->navbar->add(get_string('summaryofattempt', 'quiz'));
$PAGE->set_title($attemptobj->get_quiz_name());
$PAGE->set_title($attemptobj->summary_page_title());
$PAGE->set_heading($attemptobj->get_course()->fullname);
// Display the page.
+61
View File
@@ -216,6 +216,67 @@ class mod_quiz_attempt_testcase extends advanced_testcase {
$this->assertEquals(new moodle_url($url, $params), $attempt->review_url(11, -1, false, 0));
}
/**
* Tests attempt page titles when all questions are on a single page.
*/
public function test_attempt_titles_single() {
$attempt = $this->create_quiz_and_attempt_with_layout('1,2,0');
// Attempt page.
$this->assertEquals('Quiz 1', $attempt->attempt_page_title(0));
// Summary page.
$this->assertEquals('Quiz 1: Attempt summary', $attempt->summary_page_title());
// Review page.
$this->assertEquals('Quiz 1: Attempt review', $attempt->review_page_title(0));
}
/**
* Tests attempt page titles when questions are on multiple pages, but are reviewed on a single page.
*/
public function test_attempt_titles_multiple_single() {
$attempt = $this->create_quiz_and_attempt_with_layout('1,2,0,3,4,0,5,6,0');
// Attempt page.
$this->assertEquals('Quiz 1 (page 1 of 3)', $attempt->attempt_page_title(0));
$this->assertEquals('Quiz 1 (page 2 of 3)', $attempt->attempt_page_title(1));
$this->assertEquals('Quiz 1 (page 3 of 3)', $attempt->attempt_page_title(2));
// Summary page.
$this->assertEquals('Quiz 1: Attempt summary', $attempt->summary_page_title());
// Review page.
$this->assertEquals('Quiz 1: Attempt review', $attempt->review_page_title(0, true));
}
/**
* Tests attempt page titles when questions are on multiple pages, and they are reviewed on multiple pages as well.
*/
public function test_attempt_titles_multiple_multiple() {
$attempt = $this->create_quiz_and_attempt_with_layout(
'1,2,3,4,5,6,7,8,9,10,0,11,12,13,14,15,16,17,18,19,20,0,' .
'21,22,23,24,25,26,27,28,29,30,0,31,32,33,34,35,36,37,38,39,40,0,' .
'41,42,43,44,45,46,47,48,49,50,0,51,52,53,54,55,56,57,58,59,60,0');
// Attempt page.
$this->assertEquals('Quiz 1 (page 1 of 6)', $attempt->attempt_page_title(0));
$this->assertEquals('Quiz 1 (page 2 of 6)', $attempt->attempt_page_title(1));
$this->assertEquals('Quiz 1 (page 6 of 6)', $attempt->attempt_page_title(5));
// Summary page.
$this->assertEquals('Quiz 1: Attempt summary', $attempt->summary_page_title());
// Review page.
$this->assertEquals('Quiz 1: Attempt review (page 1 of 6)', $attempt->review_page_title(0));
$this->assertEquals('Quiz 1: Attempt review (page 2 of 6)', $attempt->review_page_title(1));
$this->assertEquals('Quiz 1: Attempt review (page 6 of 6)', $attempt->review_page_title(5));
// When all questions are shown.
$this->assertEquals('Quiz 1: Attempt review', $attempt->review_page_title(0, true));
$this->assertEquals('Quiz 1: Attempt review', $attempt->review_page_title(1, true));
}
public function test_is_participant() {
global $USER;
$this->resetAfterTest();