MDL-42181 quiz nav: highight all buttons when all Qs on one page
[moodle.git] / mod / quiz / renderer.php
CommitLineData
b3782c71
TH
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Defines the renderer for the quiz module.
19 *
20 * @package mod
21 * @subpackage quiz
22 * @copyright 2011 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26
9d568789
TH
27defined('MOODLE_INTERNAL') || die();
28
29
b3782c71
TH
30/**
31 * The renderer for the quiz module.
32 *
78a61cd6 33 * @copyright 2011 The Open University
b3782c71
TH
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 */
36class mod_quiz_renderer extends plugin_renderer_base {
2c3e2b53
DL
37 /**
38 * Builds the review page
39 *
40 * @param quiz_attempt $attemptobj an instance of quiz_attempt.
41 * @param array $slots an array of intgers relating to questions.
42 * @param int $page the current page number
43 * @param bool $showall whether to show entire attempt on one page.
44 * @param bool $lastpage if true the current page is the last page.
45 * @param mod_quiz_display_options $displayoptions instance of mod_quiz_display_options.
46 * @param array $summarydata contains all table data
47 * @return $output containing html data.
48 */
b3782c71 49 public function review_page(quiz_attempt $attemptobj, $slots, $page, $showall,
9f335e76
DL
50 $lastpage, mod_quiz_display_options $displayoptions,
51 $summarydata) {
b3782c71
TH
52
53 $output = '';
54 $output .= $this->header();
55 $output .= $this->review_summary_table($summarydata, $page);
56 $output .= $this->review_form($page, $showall, $displayoptions,
06eb64b8 57 $this->questions($attemptobj, true, $slots, $page, $showall, $displayoptions),
8c4deb80 58 $attemptobj);
b3782c71
TH
59
60 $output .= $this->review_next_navigation($attemptobj, $page, $lastpage);
61 $output .= $this->footer();
62 return $output;
63 }
64
3a5da40b
TH
65 /**
66 * Renders the review question pop-up.
67 *
68 * @param quiz_attempt $attemptobj an instance of quiz_attempt.
69 * @param int $slot which question to display.
70 * @param int $seq which step of the question attempt to show. null = latest.
71 * @param mod_quiz_display_options $displayoptions instance of mod_quiz_display_options.
72 * @param array $summarydata contains all table data
73 * @return $output containing html data.
74 */
75 public function review_question_page(quiz_attempt $attemptobj, $slot, $seq,
76 mod_quiz_display_options $displayoptions, $summarydata) {
77
78 $output = '';
79 $output .= $this->header();
80 $output .= $this->review_summary_table($summarydata, 0);
81
82 if (!is_null($seq)) {
da729916 83 $output .= $attemptobj->render_question_at_step($slot, $seq, true);
3a5da40b 84 } else {
da729916 85 $output .= $attemptobj->render_question($slot, true);
3a5da40b
TH
86 }
87
88 $output .= $this->close_window_button();
89 $output .= $this->footer();
90 return $output;
91 }
92
93 /**
94 * Renders the review question pop-up.
95 *
96 * @param string $message Why the review is not allowed.
97 * @return string html to output.
98 */
99 public function review_question_not_allowed($message) {
100 $output = '';
101 $output .= $this->header();
c544ee92 102 $output .= $this->heading(format_string($attemptobj->get_quiz_name(), true,
103 array("context" => $attemptobj->get_quizobj()->get_context())));
3a5da40b
TH
104 $output .= $this->notification($message);
105 $output .= $this->close_window_button();
106 $output .= $this->footer();
107 return $output;
108 }
109
2c3e2b53
DL
110 /**
111 * Filters the summarydata array.
112 *
113 * @param array $summarydata contains row data for table
114 * @param int $page the current page number
115 * @return $summarydata containing filtered row data
116 */
b39b5d77 117 protected function filter_review_summary_table($summarydata, $page) {
b3782c71
TH
118 if ($page == 0) {
119 return $summarydata;
120 }
121
122 // Only show some of summary table on subsequent pages.
123 foreach ($summarydata as $key => $rowdata) {
124 if (!in_array($key, array('user', 'attemptlist'))) {
125 unset($summarydata[$key]);
126 }
127 }
128
129 return $summarydata;
130 }
131
2c3e2b53
DL
132 /**
133 * Outputs the table containing data from summary data array
134 *
135 * @param array $summarydata contains row data for table
136 * @param int $page contains the current page number
137 */
b3782c71 138 public function review_summary_table($summarydata, $page) {
b39b5d77 139 $summarydata = $this->filter_review_summary_table($summarydata, $page);
b3782c71
TH
140 if (empty($summarydata)) {
141 return '';
142 }
143
144 $output = '';
145 $output .= html_writer::start_tag('table', array(
146 'class' => 'generaltable generalbox quizreviewsummary'));
147 $output .= html_writer::start_tag('tbody');
148 foreach ($summarydata as $rowdata) {
149 if ($rowdata['title'] instanceof renderable) {
150 $title = $this->render($rowdata['title']);
151 } else {
152 $title = $rowdata['title'];
153 }
154
155 if ($rowdata['content'] instanceof renderable) {
156 $content = $this->render($rowdata['content']);
157 } else {
158 $content = $rowdata['content'];
159 }
160
161 $output .= html_writer::tag('tr',
162 html_writer::tag('th', $title, array('class' => 'cell', 'scope' => 'row')) .
9f335e76 163 html_writer::tag('td', $content, array('class' => 'cell'))
b3782c71
TH
164 );
165 }
166
167 $output .= html_writer::end_tag('tbody');
168 $output .= html_writer::end_tag('table');
169 return $output;
170 }
171
2c3e2b53
DL
172 /**
173 * Renders each question
174 *
175 * @param quiz_attempt $attemptobj instance of quiz_attempt
176 * @param bool $reviewing
177 * @param array $slots array of intgers relating to questions
178 * @param int $page current page number
179 * @param bool $showall if true shows attempt on single page
180 * @param mod_quiz_display_options $displayoptions instance of mod_quiz_display_options
181 */
b3782c71 182 public function questions(quiz_attempt $attemptobj, $reviewing, $slots, $page, $showall,
bcd42560 183 mod_quiz_display_options $displayoptions) {
b3782c71
TH
184 $output = '';
185 foreach ($slots as $slot) {
186 $output .= $attemptobj->render_question($slot, $reviewing,
187 $attemptobj->review_url($slot, $page, $showall));
188 }
189 return $output;
190 }
191
2c3e2b53
DL
192 /**
193 * Renders the main bit of the review page.
194 *
195 * @param array $summarydata contain row data for table
196 * @param int $page current page number
197 * @param mod_quiz_display_options $displayoptions instance of mod_quiz_display_options
198 * @param $content contains each question
199 * @param quiz_attempt $attemptobj instance of quiz_attempt
200 * @param bool $showall if true display attempt on one page
201 */
8c4deb80 202 public function review_form($page, $showall, $displayoptions, $content, $attemptobj) {
b3782c71
TH
203 if ($displayoptions->flags != question_display_options::EDITABLE) {
204 return $content;
205 }
206
9f335e76
DL
207 $this->page->requires->js_init_call('M.mod_quiz.init_review_form', null, false,
208 quiz_get_js_module());
b3782c71 209
b3782c71 210 $output = '';
918776f4 211 $output .= html_writer::start_tag('form', array('action' => $attemptobj->review_url(null,
bcd42560
DL
212 $page, $showall), 'method' => 'post', 'class' => 'questionflagsaveform'));
213 $output .= html_writer::start_tag('div');
2c3e2b53 214 $output .= $content;
bcd42560
DL
215 $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey',
216 'value' => sesskey()));
217 $output .= html_writer::start_tag('div', array('class' => 'submitbtns'));
218 $output .= html_writer::empty_tag('input', array('type' => 'submit',
219 'class' => 'questionflagsavebutton', 'name' => 'savingflags',
220 'value' => get_string('saveflags', 'question')));
06eb64b8
DL
221 $output .= html_writer::end_tag('div');
222 $output .= html_writer::end_tag('div');
223 $output .= html_writer::end_tag('form');
b3782c71
TH
224
225 return $output;
226 }
227
2c3e2b53
DL
228 /**
229 * Returns either a liink or button
230 *
d869de66 231 * @param quiz_attempt $attemptobj instance of quiz_attempt
2c3e2b53 232 */
d869de66
TH
233 public function finish_review_link(quiz_attempt $attemptobj) {
234 $url = $attemptobj->view_url();
235
236 if ($attemptobj->get_access_manager(time())->attempt_must_be_in_popup()) {
9f335e76
DL
237 $this->page->requires->js_init_call('M.mod_quiz.secure_window.init_close_button',
238 array($url), quiz_get_js_module());
239 return html_writer::empty_tag('input', array('type' => 'button',
240 'value' => get_string('finishreview', 'quiz'),
241 'id' => 'secureclosebutton'));
d869de66 242
9f335e76
DL
243 } else {
244 return html_writer::link($url, get_string('finishreview', 'quiz'));
245 }
b3782c71
TH
246 }
247
2c3e2b53
DL
248 /**
249 * Creates a next page arrow or the finishing link
250 *
251 * @param quiz_attempt $attemptobj instance of quiz_attempt
252 * @param int $page the current page
253 * @param bool $lastpage if true current page is the last page
254 */
b3782c71
TH
255 public function review_next_navigation(quiz_attempt $attemptobj, $page, $lastpage) {
256 if ($lastpage) {
d869de66 257 $nav = $this->finish_review_link($attemptobj);
b3782c71 258 } else {
918776f4 259 $nav = link_arrow_right(get_string('next'), $attemptobj->review_url(null, $page + 1));
b3782c71
TH
260 }
261 return html_writer::tag('div', $nav, array('class' => 'submitbtns'));
262 }
263
264 /**
265 * Return the HTML of the quiz timer.
266 * @return string HTML content.
267 */
2b2b6458
TH
268 public function countdown_timer(quiz_attempt $attemptobj, $timenow) {
269
8e771aed 270 $timeleft = $attemptobj->get_time_left_display($timenow);
2b2b6458 271 if ($timeleft !== false) {
8e771aed
MP
272 $ispreview = $attemptobj->is_preview();
273 $timerstartvalue = $timeleft;
274 if (!$ispreview) {
275 // Make sure the timer starts just above zero. If $timeleft was <= 0, then
276 // this will just have the effect of causing the quiz to be submitted immediately.
277 $timerstartvalue = max($timerstartvalue, 1);
278 }
279 $this->initialise_timer($timerstartvalue, $ispreview);
2b2b6458
TH
280 }
281
babfb615 282 return html_writer::tag('div', get_string('timeleft', 'quiz') . ' ' .
b3782c71 283 html_writer::tag('span', '', array('id' => 'quiz-time-left')),
e498f214
TH
284 array('id' => 'quiz-timer', 'role' => 'timer',
285 'aria-atomic' => 'true', 'aria-relevant' => 'text'));
b3782c71
TH
286 }
287
2c3e2b53
DL
288 /**
289 * Create a preview link
290 *
291 * @param $url contains a url to the given page
292 */
b3782c71
TH
293 public function restart_preview_button($url) {
294 return $this->single_button($url, get_string('startnewpreview', 'quiz'));
295 }
296
2c3e2b53
DL
297 /**
298 * Outputs the navigation block panel
299 *
300 * @param quiz_nav_panel_base $panel instance of quiz_nav_panel_base
301 */
b3782c71
TH
302 public function navigation_panel(quiz_nav_panel_base $panel) {
303
304 $output = '';
305 $userpicture = $panel->user_picture();
306 if ($userpicture) {
370ee378
TH
307 $fullname = fullname($userpicture->user);
308 if ($userpicture->size === true) {
309 $fullname = html_writer::div($fullname);
310 }
311 $output .= html_writer::tag('div', $this->render($userpicture) . $fullname,
b3782c71
TH
312 array('id' => 'user-picture', 'class' => 'clearfix'));
313 }
314 $output .= $panel->render_before_button_bits($this);
315
0328341f
K
316 $bcc = $panel->get_button_container_class();
317 $output .= html_writer::start_tag('div', array('class' => "qn_buttons $bcc"));
b3782c71
TH
318 foreach ($panel->get_question_buttons() as $button) {
319 $output .= $this->render($button);
320 }
321 $output .= html_writer::end_tag('div');
322
323 $output .= html_writer::tag('div', $panel->render_end_bits($this),
324 array('class' => 'othernav'));
325
9f335e76
DL
326 $this->page->requires->js_init_call('M.mod_quiz.nav.init', null, false,
327 quiz_get_js_module());
b3782c71
TH
328
329 return $output;
330 }
331
2c3e2b53
DL
332 /**
333 * Returns the quizzes navigation button
334 *
335 * @param quiz_nav_question_button $button
336 */
b3782c71 337 protected function render_quiz_nav_question_button(quiz_nav_question_button $button) {
33c8d37b 338 $classes = array('qnbutton', $button->stateclass, $button->navmethod);
b3782c71
TH
339 $attributes = array();
340
341 if ($button->currentpage) {
342 $classes[] = 'thispage';
343 $attributes[] = get_string('onthispage', 'quiz');
344 }
345
b3782c71
TH
346 // Flagged?
347 if ($button->flagged) {
348 $classes[] = 'flagged';
349 $flaglabel = get_string('flagged', 'question');
350 } else {
351 $flaglabel = '';
352 }
353 $attributes[] = html_writer::tag('span', $flaglabel, array('class' => 'flagstate'));
354
355 if (is_numeric($button->number)) {
356 $qnostring = 'questionnonav';
357 } else {
358 $qnostring = 'questionnonavinfo';
359 }
360
361 $a = new stdClass();
362 $a->number = $button->number;
363 $a->attributes = implode(' ', $attributes);
33c8d37b
CF
364 $tagcontents = html_writer::tag('span', '', array('class' => 'thispageholder')) .
365 html_writer::tag('span', '', array('class' => 'trafficlight')) .
366 get_string($qnostring, 'quiz', $a);
367 $tagattributes = array('class' => implode(' ', $classes), 'id' => $button->id,
368 'title' => $button->statestring);
369
370 if ($button->url) {
371 return html_writer::link($button->url, $tagcontents, $tagattributes);
372 } else {
373 return html_writer::tag('span', $tagcontents, $tagattributes);
374 }
b3782c71
TH
375 }
376
2c3e2b53
DL
377 /**
378 * outputs the link the other attempts.
379 *
380 * @param mod_quiz_links_to_other_attempts $links
381 */
b3782c71 382 protected function render_mod_quiz_links_to_other_attempts(
bcd42560 383 mod_quiz_links_to_other_attempts $links) {
b3782c71
TH
384 $attemptlinks = array();
385 foreach ($links->links as $attempt => $url) {
386 if ($url) {
387 $attemptlinks[] = html_writer::link($url, $attempt);
388 } else {
389 $attemptlinks[] = html_writer::tag('strong', $attempt);
390 }
391 }
392 return implode(', ', $attemptlinks);
393 }
9f335e76 394
987c2d49
TH
395 public function start_attempt_page(quiz $quizobj, mod_quiz_preflight_check_form $mform) {
396 $output = '';
397 $output .= $this->header();
c544ee92 398 $output .= $this->heading(format_string($quizobj->get_quiz_name(), true,
399 array("context" => $quizobj->get_context())));
987c2d49
TH
400 $output .= $this->quiz_intro($quizobj->get_quiz(), $quizobj->get_cm());
401 ob_start();
402 $mform->display();
403 $output .= ob_get_clean();
404 $output .= $this->footer();
405 return $output;
406 }
407
2c3e2b53 408 /**
606e07d5 409 * Attempt Page
2c3e2b53
DL
410 *
411 * @param quiz_attempt $attemptobj Instance of quiz_attempt
412 * @param int $page Current page number
413 * @param quiz_access_manager $accessmanager Instance of quiz_access_manager
414 * @param array $messages An array of messages
415 * @param array $slots Contains an array of integers that relate to questions
416 * @param int $id The ID of an attempt
417 * @param int $nextpage The number of the next page
606e07d5 418 */
9f335e76 419 public function attempt_page($attemptobj, $page, $accessmanager, $messages, $slots, $id,
bcd42560 420 $nextpage) {
606e07d5 421 $output = '';
babfb615 422 $output .= $this->header();
bcd42560 423 $output .= $this->quiz_notices($messages);
9f335e76 424 $output .= $this->attempt_form($attemptobj, $page, $slots, $id, $nextpage);
babfb615 425 $output .= $this->footer();
606e07d5
DL
426 return $output;
427 }
9f335e76 428
2c3e2b53
DL
429 /**
430 * Returns any notices.
431 *
432 * @param array $messages
433 */
8e8bd3f9 434 public function quiz_notices($messages) {
bcd42560
DL
435 if (!$messages) {
436 return '';
606e07d5 437 }
bcd42560 438 return $this->box($this->heading(get_string('accessnoticesheader', 'quiz'), 3) .
adf7fe21 439 $this->access_messages($messages), 'quizaccessnotices');
606e07d5 440 }
9f335e76 441
2c3e2b53
DL
442 /**
443 * Ouputs the form for making an attempt
444 *
445 * @param quiz_attempt $attemptobj
446 * @param int $page Current page number
447 * @param array $slots Array of integers relating to questions
448 * @param int $id ID of the attempt
449 * @param int $nextpage Next page number
450 */
8e8bd3f9 451 public function attempt_form($attemptobj, $page, $slots, $id, $nextpage) {
9f335e76 452 $output = '';
bcd42560 453
9e83f3d1 454 // Start the form.
63be47d9 455 $output .= html_writer::start_tag('form',
13040e14 456 array('action' => $attemptobj->processattempt_url(), 'method' => 'post',
63be47d9
DL
457 'enctype' => 'multipart/form-data', 'accept-charset' => 'utf-8',
458 'id' => 'responseform'));
bcd42560 459 $output .= html_writer::start_tag('div');
9f335e76 460
9e83f3d1 461 // Print all the questions.
606e07d5 462 foreach ($slots as $slot) {
45e5fbe1
TH
463 $output .= $attemptobj->render_question($slot, false,
464 $attemptobj->attempt_url($slot, $page));
606e07d5 465 }
9f335e76 466
bcd42560 467 $output .= html_writer::start_tag('div', array('class' => 'submitbtns'));
63be47d9
DL
468 $output .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'next',
469 'value' => get_string('next')));
bcd42560 470 $output .= html_writer::end_tag('div');
9f335e76 471
606e07d5 472 // Some hidden fields to trach what is going on.
63be47d9
DL
473 $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'attempt',
474 'value' => $attemptobj->get_attemptid()));
475 $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'thispage',
476 'value' => $page, 'id' => 'followingpage'));
477 $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'nextpage',
478 'value' => $nextpage));
479 $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'timeup',
480 'value' => '0', 'id' => 'timeup'));
481 $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey',
482 'value' => sesskey()));
483 $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'scrollpos',
484 'value' => '', 'id' => 'scrollpos'));
9f335e76 485
606e07d5
DL
486 // Add a hidden field with questionids. Do this at the end of the form, so
487 // if you navigate before the form has finished loading, it does not wipe all
488 // the student's answers.
63be47d9
DL
489 $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'slots',
490 'value' => implode(',', $slots)));
491
9e83f3d1 492 // Finish the form.
bcd42560
DL
493 $output .= html_writer::end_tag('div');
494 $output .= html_writer::end_tag('form');
9f335e76
DL
495
496 return $output;
606e07d5 497 }
cbe87543 498
d755b0f5
TH
499 /**
500 * Output the JavaScript required to initialise the countdown timer.
501 * @param int $timerstartvalue time remaining, in seconds.
502 */
8e771aed
MP
503 public function initialise_timer($timerstartvalue, $ispreview) {
504 $options = array($timerstartvalue, (bool)$ispreview);
505 $this->page->requires->js_init_call('M.mod_quiz.timer.init', $options, false, quiz_get_js_module());
d755b0f5
TH
506 }
507
508 /**
509 * Output a page with an optional message, and JavaScript code to close the
510 * current window and redirect the parent window to a new URL.
511 * @param moodle_url $url the URL to redirect the parent window to.
512 * @param string $message message to display before closing the window. (optional)
513 * @return string HTML to output.
514 */
515 public function close_attempt_popup($url, $message = '') {
516 $output = '';
517 $output .= $this->header();
518 $output .= $this->box_start();
519
520 if ($message) {
d89eb938
TH
521 $output .= html_writer::tag('p', $message);
522 $output .= html_writer::tag('p', get_string('windowclosing', 'quiz'));
d755b0f5
TH
523 $delay = 5;
524 } else {
d89eb938 525 $output .= html_writer::tag('p', get_string('pleaseclose', 'quiz'));
d755b0f5
TH
526 $delay = 0;
527 }
ddda79ca
TH
528 $this->page->requires->js_init_call('M.mod_quiz.secure_window.close',
529 array($url, $delay), false, quiz_get_js_module());
d755b0f5
TH
530
531 $output .= $this->box_end();
532 $output .= $this->footer();
533 return $output;
534 }
535
13040e14
DL
536 /**
537 * Print each message in an array, surrounded by &lt;p>, &lt;/p> tags.
538 *
539 * @param array $messages the array of message strings.
540 * @param bool $return if true, return a string, instead of outputting.
541 *
d755b0f5 542 * @return string HTML to output.
13040e14
DL
543 */
544 public function access_messages($messages) {
545 $output = '';
546 foreach ($messages as $message) {
547 $output .= html_writer::tag('p', $message) . "\n";
548 }
549 return $output;
550 }
9f335e76 551
63be47d9
DL
552 /*
553 * Summary Page
554 */
2c3e2b53
DL
555 /**
556 * Create the summary page
557 *
558 * @param quiz_attempt $attemptobj
559 * @param mod_quiz_display_options $displayoptions
560 */
63be47d9
DL
561 public function summary_page($attemptobj, $displayoptions) {
562 $output = '';
babfb615
TH
563 $output .= $this->header();
564 $output .= $this->heading(format_string($attemptobj->get_quiz_name()));
565 $output .= $this->heading(get_string('summaryofattempt', 'quiz'), 3);
63be47d9 566 $output .= $this->summary_table($attemptobj, $displayoptions);
13040e14 567 $output .= $this->summary_page_controls($attemptobj);
babfb615 568 $output .= $this->footer();
63be47d9
DL
569 return $output;
570 }
571
2c3e2b53
DL
572 /**
573 * Generates the table of summarydata
574 *
575 * @param quiz_attempt $attemptobj
576 * @param mod_quiz_display_options $displayoptions
577 */
8e8bd3f9 578 public function summary_table($attemptobj, $displayoptions) {
9e83f3d1 579 // Prepare the summary table header.
63be47d9
DL
580 $table = new html_table();
581 $table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter';
582 $table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz'));
583 $table->align = array('left', 'left');
584 $table->size = array('', '');
585 $markscolumn = $displayoptions->marks >= question_display_options::MARK_AND_MAX;
586 if ($markscolumn) {
587 $table->head[] = get_string('marks', 'quiz');
588 $table->align[] = 'left';
589 $table->size[] = '';
590 }
591 $table->data = array();
592
593 // Get the summary info for each question.
594 $slots = $attemptobj->get_slots();
595 foreach ($slots as $slot) {
596 if (!$attemptobj->is_real_question($slot)) {
597 continue;
598 }
599 $flag = '';
600 if ($attemptobj->is_question_flagged($slot)) {
601 $flag = html_writer::empty_tag('img', array('src' => $this->pix_url('i/flagged'),
c3847443 602 'alt' => get_string('flagged', 'question'), 'class' => 'questionflag icon-post'));
63be47d9 603 }
33c8d37b
CF
604 if ($attemptobj->can_navigate_to($slot)) {
605 $row = array(html_writer::link($attemptobj->attempt_url($slot),
606 $attemptobj->get_question_number($slot) . $flag),
607 $attemptobj->get_question_status($slot, $displayoptions->correctness));
608 } else {
9e83f3d1
TH
609 $row = array($attemptobj->get_question_number($slot) . $flag,
610 $attemptobj->get_question_status($slot, $displayoptions->correctness));
33c8d37b 611 }
63be47d9
DL
612 if ($markscolumn) {
613 $row[] = $attemptobj->get_question_mark($slot);
614 }
615 $table->data[] = $row;
97cdc1de
TH
616 $table->rowclasses[] = $attemptobj->get_question_state_class(
617 $slot, $displayoptions->correctness);
63be47d9
DL
618 }
619
620 // Print the summary table.
621 $output = html_writer::table($table);
622
623 return $output;
624 }
625
2c3e2b53
DL
626 /**
627 * Creates any controls a the page should have.
628 *
629 * @param quiz_attempt $attemptobj
630 */
8e8bd3f9 631 public function summary_page_controls($attemptobj) {
63be47d9 632 $output = '';
63be47d9 633
9e83f3d1 634 // Return to place button.
96e5168c
TH
635 if ($attemptobj->get_state() == quiz_attempt::IN_PROGRESS) {
636 $button = new single_button(
637 new moodle_url($attemptobj->attempt_url(null, $attemptobj->get_currentpage())),
638 get_string('returnattempt', 'quiz'));
639 $output .= $this->container($this->container($this->render($button),
640 'controls'), 'submitbtns mdl-align');
641 }
33c8d37b 642
63be47d9 643 // Finish attempt button.
63be47d9
DL
644 $options = array(
645 'attempt' => $attemptobj->get_attemptid(),
646 'finishattempt' => 1,
647 'timeup' => 0,
648 'slots' => '',
649 'sesskey' => sesskey(),
650 );
651
652 $button = new single_button(
653 new moodle_url($attemptobj->processattempt_url(), $options),
654 get_string('submitallandfinish', 'quiz'));
655 $button->id = 'responseform';
2b2b6458
TH
656 if ($attemptobj->get_state() == quiz_attempt::IN_PROGRESS) {
657 $button->add_action(new confirm_action(get_string('confirmclose', 'quiz'), null,
658 get_string('submitallandfinish', 'quiz')));
659 }
63be47d9 660
2b2b6458
TH
661 $duedate = $attemptobj->get_due_date();
662 $message = '';
663 if ($attemptobj->get_state() == quiz_attempt::OVERDUE) {
664 $message = get_string('overduemustbesubmittedby', 'quiz', userdate($duedate));
665
666 } else if ($duedate) {
667 $message = get_string('mustbesubmittedby', 'quiz', userdate($duedate));
668 }
669
670 $output .= $this->countdown_timer($attemptobj, time());
671 $output .= $this->container($message . $this->container(
672 $this->render($button), 'controls'), 'submitbtns mdl-align');
63be47d9
DL
673
674 return $output;
675 }
cbe87543 676
06eb64b8
DL
677 /*
678 * View Page
679 */
2c3e2b53
DL
680 /**
681 * Generates the view page
682 *
683 * @param int $course The id of the course
684 * @param array $quiz Array conting quiz data
685 * @param int $cm Course Module ID
686 * @param int $context The page context ID
adf7fe21 687 * @param array $infomessages information about this quiz
2c3e2b53 688 * @param mod_quiz_view_object $viewobj
adf7fe21
TH
689 * @param string $buttontext text for the start/continue attempt button, if
690 * it should be shown.
691 * @param array $infomessages further information about why the student cannot
692 * attempt this quiz now, if appicable this quiz
2c3e2b53 693 */
d755b0f5 694 public function view_page($course, $quiz, $cm, $context, $viewobj) {
06eb64b8 695 $output = '';
987c2d49 696 $output .= $this->view_information($quiz, $cm, $context, $viewobj->infomessages);
06eb64b8 697 $output .= $this->view_table($quiz, $context, $viewobj);
06eb64b8 698 $output .= $this->view_result_info($quiz, $context, $cm, $viewobj);
d755b0f5
TH
699 $output .= $this->box($this->view_page_buttons($viewobj), 'quizattempt');
700 return $output;
701 }
702
703 /**
704 * Work out, and render, whatever buttons, and surrounding info, should appear
705 * at the end of the review page.
706 * @param mod_quiz_view_object $viewobj the information required to display
707 * the view page.
708 * @return string HTML to output.
709 */
710 public function view_page_buttons(mod_quiz_view_object $viewobj) {
eb665c34 711 global $CFG;
d755b0f5
TH
712 $output = '';
713
714 if (!$viewobj->quizhasquestions) {
715 $output .= $this->no_questions_message($viewobj->canedit, $viewobj->editurl);
716 }
717
718 $output .= $this->access_messages($viewobj->preventmessages);
719
720 if ($viewobj->buttontext) {
721 $output .= $this->start_attempt_button($viewobj->buttontext,
722 $viewobj->startattempturl, $viewobj->startattemptwarning,
723 $viewobj->popuprequired, $viewobj->popupoptions);
724
eb665c34
FM
725 }
726
727 if ($viewobj->showbacktocourse) {
d755b0f5
TH
728 $output .= $this->single_button($viewobj->backtocourseurl,
729 get_string('backtocourse', 'quiz'), 'get',
730 array('class' => 'continuebutton'));
731 }
732
733 return $output;
734 }
735
736 /**
737 * Generates the view attempt button
738 *
739 * @param int $course The course ID
740 * @param array $quiz Array containging quiz date
741 * @param int $cm The Course Module ID
742 * @param int $context The page Context ID
743 * @param mod_quiz_view_object $viewobj
744 * @param string $buttontext
745 */
746 public function start_attempt_button($buttontext, moodle_url $url,
747 $startattemptwarning, $popuprequired, $popupoptions) {
748
749 $button = new single_button($url, $buttontext);
750 $button->class .= ' quizstartbuttondiv';
751
752 $warning = '';
753 if ($popuprequired) {
754 $this->page->requires->js_module(quiz_get_js_module());
755 $this->page->requires->js('/mod/quiz/module.js');
756 $popupaction = new popup_action('click', $url, 'quizpopup', $popupoptions);
757
758 $button->class .= ' quizsecuremoderequired';
759 $button->add_action(new component_action('click',
760 'M.mod_quiz.secure_window.start_attempt_action', array(
761 'url' => $url->out(false),
762 'windowname' => 'quizpopup',
ee664a16 763 'options' => $popupaction->get_js_options(),
d755b0f5
TH
764 'fullscreen' => true,
765 'startattemptwarning' => $startattemptwarning,
766 )));
767
768 $warning = html_writer::tag('noscript', $this->heading(get_string('noscript', 'quiz')));
769
770 } else if ($startattemptwarning) {
771 $button->add_action(new confirm_action($startattemptwarning, null,
772 get_string('startattempt', 'quiz')));
773 }
774
775 return $this->render($button) . $warning;
776 }
777
778 /**
779 * Generate a message saying that this quiz has no questions, with a button to
780 * go to the edit page, if the user has the right capability.
781 * @param object $quiz the quiz settings.
782 * @param object $cm the course_module object.
783 * @param object $context the quiz context.
784 * @return string HTML to output.
785 */
0eafc988 786 public function no_questions_message($canedit, $editurl) {
d755b0f5
TH
787 $output = '';
788 $output .= $this->notification(get_string('noquestions', 'quiz'));
789 if ($canedit) {
790 $output .= $this->single_button($editurl, get_string('editquiz', 'quiz'), 'get');
791 }
792
06eb64b8
DL
793 return $output;
794 }
37015e0c 795
2c3e2b53
DL
796 /**
797 * Outputs an error message for any guests accessing the quiz
798 *
799 * @param int $course The course ID
800 * @param array $quiz Array contingin quiz data
801 * @param int $cm Course Module ID
802 * @param int $context The page contect ID
803 * @param array $messages Array containing any messages
804 */
37015e0c 805 public function view_page_guest($course, $quiz, $cm, $context, $messages) {
88c7e2a9 806 $output = '';
987c2d49 807 $output .= $this->view_information($quiz, $cm, $context, $messages);
37015e0c
DL
808 $guestno = html_writer::tag('p', get_string('guestsno', 'quiz'));
809 $liketologin = html_writer::tag('p', get_string('liketologin'));
4e5b9e49 810 $output .= $this->confirm($guestno."\n\n".$liketologin."\n", get_login_url(),
37015e0c 811 get_referer(false));
88c7e2a9
DL
812 return $output;
813 }
37015e0c 814
2c3e2b53
DL
815 /**
816 * Outputs and error message for anyone who is not enrolle don the course
817 *
818 * @param int $course The course ID
819 * @param array $quiz Array contingin quiz data
820 * @param int $cm Course Module ID
821 * @param int $context The page contect ID
822 * @param array $messages Array containing any messages
823 */
37015e0c 824 public function view_page_notenrolled($course, $quiz, $cm, $context, $messages) {
88c7e2a9
DL
825 global $CFG;
826 $output = '';
987c2d49 827 $output .= $this->view_information($quiz, $cm, $context, $messages);
37015e0c
DL
828 $youneedtoenrol = html_writer::tag('p', get_string('youneedtoenrol', 'quiz'));
829 $button = html_writer::tag('p',
830 $this->continue_button($CFG->wwwroot . '/course/view.php?id=' . $course->id));
4e5b9e49 831 $output .= $this->box($youneedtoenrol."\n\n".$button."\n", 'generalbox', 'notice');
88c7e2a9
DL
832 return $output;
833 }
cbe87543 834
2c3e2b53
DL
835 /**
836 * Output the page information
837 *
987c2d49
TH
838 * @param object $quiz the quiz settings.
839 * @param object $cm the course_module object.
840 * @param object $context the quiz context.
841 * @param array $messages any access messages that should be described.
842 * @return string HTML to output.
2c3e2b53 843 */
987c2d49 844 public function view_information($quiz, $cm, $context, $messages) {
06eb64b8 845 global $CFG;
987c2d49 846
06eb64b8 847 $output = '';
726fd6db 848
9e83f3d1 849 // Print quiz name and description.
06eb64b8 850 $output .= $this->heading(format_string($quiz->name));
726fd6db 851 $output .= $this->quiz_intro($quiz, $cm);
06eb64b8 852
726fd6db
TH
853 // Output any access messages.
854 if ($messages) {
855 $output .= $this->box($this->access_messages($messages), 'quizinfo');
856 }
06eb64b8
DL
857
858 // Show number of attempts summary to those who can view reports.
859 if (has_capability('mod/quiz:viewreports', $context)) {
fcd5e245
DL
860 if ($strattemptnum = $this->quiz_attempt_summary_link_to_reports($quiz, $cm,
861 $context)) {
37015e0c
DL
862 $output .= html_writer::tag('div', $strattemptnum,
863 array('class' => 'quizattemptcounts'));
06eb64b8
DL
864 }
865 }
06eb64b8
DL
866 return $output;
867 }
868
987c2d49
TH
869 /**
870 * Output the quiz intro.
871 * @param object $quiz the quiz settings.
872 * @param object $cm the course_module object.
873 * @return string HTML to output.
874 */
875 public function quiz_intro($quiz, $cm) {
726fd6db 876 if (html_is_blank($quiz->intro)) {
987c2d49
TH
877 return '';
878 }
726fd6db
TH
879
880 return $this->box(format_module_intro('quiz', $quiz, $cm->id), 'generalbox', 'intro');
987c2d49
TH
881 }
882
0de43939
DL
883 /**
884 * Generates the table heading.
885 */
886 public function view_table_heading() {
c544ee92 887 return $this->heading(get_string('summaryofattempts', 'quiz'), 3);
0de43939
DL
888 }
889
2c3e2b53
DL
890 /**
891 * Generates the table of data
892 *
893 * @param array $quiz Array contining quiz data
894 * @param int $context The page context ID
895 * @param mod_quiz_view_object $viewobj
896 */
8e8bd3f9 897 public function view_table($quiz, $context, $viewobj) {
da59992e 898 if (!$viewobj->attempts) {
2de9be52 899 return '';
da59992e 900 }
da59992e 901
9e83f3d1 902 // Prepare table header.
da59992e
DL
903 $table = new html_table();
904 $table->attributes['class'] = 'generaltable quizattemptsummary';
905 $table->head = array();
906 $table->align = array();
907 $table->size = array();
908 if ($viewobj->attemptcolumn) {
909 $table->head[] = get_string('attemptnumber', 'quiz');
910 $table->align[] = 'center';
911 $table->size[] = '';
912 }
2de9be52 913 $table->head[] = get_string('attemptstate', 'quiz');
da59992e
DL
914 $table->align[] = 'left';
915 $table->size[] = '';
916 if ($viewobj->markcolumn) {
917 $table->head[] = get_string('marks', 'quiz') . ' / ' .
918 quiz_format_grade($quiz, $quiz->sumgrades);
919 $table->align[] = 'center';
920 $table->size[] = '';
921 }
922 if ($viewobj->gradecolumn) {
923 $table->head[] = get_string('grade') . ' / ' .
924 quiz_format_grade($quiz, $quiz->grade);
925 $table->align[] = 'center';
926 $table->size[] = '';
927 }
928 if ($viewobj->canreviewmine) {
929 $table->head[] = get_string('review', 'quiz');
930 $table->align[] = 'center';
931 $table->size[] = '';
932 }
933 if ($viewobj->feedbackcolumn) {
934 $table->head[] = get_string('feedback', 'quiz');
06eb64b8
DL
935 $table->align[] = 'left';
936 $table->size[] = '';
da59992e 937 }
06eb64b8 938
9e83f3d1 939 // One row for each attempt.
2de9be52
TH
940 foreach ($viewobj->attemptobjs as $attemptobj) {
941 $attemptoptions = $attemptobj->get_display_options(true);
da59992e 942 $row = array();
06eb64b8 943
2de9be52 944 // Add the attempt number.
da59992e 945 if ($viewobj->attemptcolumn) {
2de9be52 946 if ($attemptobj->is_preview()) {
da59992e 947 $row[] = get_string('preview', 'quiz');
06eb64b8 948 } else {
2de9be52 949 $row[] = $attemptobj->get_attempt_number();
06eb64b8 950 }
da59992e 951 }
06eb64b8 952
2b2b6458 953 $row[] = $this->attempt_state($attemptobj);
06eb64b8 954
a47a46f1
TH
955 if ($viewobj->markcolumn) {
956 if ($attemptoptions->marks >= question_display_options::MARK_AND_MAX &&
2de9be52
TH
957 $attemptobj->is_finished()) {
958 $row[] = quiz_format_grade($quiz, $attemptobj->get_sum_marks());
da59992e
DL
959 } else {
960 $row[] = '';
06eb64b8 961 }
da59992e 962 }
06eb64b8 963
da59992e 964 // Ouside the if because we may be showing feedback but not grades.
2de9be52 965 $attemptgrade = quiz_rescale_grade($attemptobj->get_sum_marks(), $quiz, false);
06eb64b8 966
da59992e
DL
967 if ($viewobj->gradecolumn) {
968 if ($attemptoptions->marks >= question_display_options::MARK_AND_MAX &&
2de9be52
TH
969 $attemptobj->is_finished()) {
970
9e83f3d1 971 // Highlight the highest grade if appropriate.
2de9be52 972 if ($viewobj->overallstats && !$attemptobj->is_preview()
da59992e
DL
973 && $viewobj->numattempts > 1 && !is_null($viewobj->mygrade)
974 && $attemptgrade == $viewobj->mygrade
975 && $quiz->grademethod == QUIZ_GRADEHIGHEST) {
2de9be52 976 $table->rowclasses[$attemptobj->get_attempt_number()] = 'bestrow';
06eb64b8 977 }
06eb64b8 978
2de9be52 979 $row[] = quiz_format_grade($quiz, $attemptgrade);
da59992e
DL
980 } else {
981 $row[] = '';
06eb64b8 982 }
da59992e 983 }
06eb64b8 984
da59992e 985 if ($viewobj->canreviewmine) {
2de9be52 986 $row[] = $viewobj->accessmanager->make_review_link($attemptobj->get_attempt(),
d755b0f5 987 $attemptoptions, $this);
da59992e
DL
988 }
989
2de9be52 990 if ($viewobj->feedbackcolumn && $attemptobj->is_finished()) {
da59992e 991 if ($attemptoptions->overallfeedback) {
1b327dec 992 $row[] = quiz_feedback_for_grade($attemptgrade, $quiz, $context);
06eb64b8 993 } else {
da59992e 994 $row[] = '';
06eb64b8 995 }
da59992e
DL
996 }
997
2de9be52 998 if ($attemptobj->is_preview()) {
da59992e
DL
999 $table->data['preview'] = $row;
1000 } else {
2de9be52 1001 $table->data[$attemptobj->get_attempt_number()] = $row;
da59992e
DL
1002 }
1003 } // End of loop over attempts.
da59992e 1004
2de9be52
TH
1005 $output = '';
1006 $output .= $this->view_table_heading();
1007 $output .= html_writer::table($table);
06eb64b8
DL
1008 return $output;
1009 }
1010
2de9be52
TH
1011 /**
1012 * Generate a brief textual desciption of the current state of an attempt.
1013 * @param quiz_attempt $attemptobj the attempt
1014 * @param int $timenow the time to use as 'now'.
1015 * @return string the appropriate lang string to describe the state.
1016 */
2b2b6458 1017 public function attempt_state($attemptobj) {
2de9be52
TH
1018 switch ($attemptobj->get_state()) {
1019 case quiz_attempt::IN_PROGRESS:
1020 return get_string('stateinprogress', 'quiz');
1021
1022 case quiz_attempt::OVERDUE:
1023 return get_string('stateoverdue', 'quiz') . html_writer::tag('span',
1024 get_string('stateoverduedetails', 'quiz',
2b2b6458 1025 userdate($attemptobj->get_due_date())),
2de9be52
TH
1026 array('class' => 'statedetails'));
1027
1028 case quiz_attempt::FINISHED:
1029 return get_string('statefinished', 'quiz') . html_writer::tag('span',
1030 get_string('statefinisheddetails', 'quiz',
1031 userdate($attemptobj->get_submitted_date())),
1032 array('class' => 'statedetails'));
1033
1034 case quiz_attempt::ABANDONED:
1035 return get_string('stateabandoned', 'quiz');
1036 }
1037 }
1038
2c3e2b53
DL
1039 /**
1040 * Generates data pertaining to quiz results
1041 *
1042 * @param array $quiz Array containing quiz data
1043 * @param int $context The page context ID
1044 * @param int $cm The Course Module Id
1045 * @param mod_quiz_view_object $viewobj
1046 */
8e8bd3f9 1047 public function view_result_info($quiz, $context, $cm, $viewobj) {
06eb64b8 1048 $output = '';
da59992e
DL
1049 if (!$viewobj->numattempts && !$viewobj->gradecolumn && is_null($viewobj->mygrade)) {
1050 return $output;
1051 }
1052 $resultinfo = '';
1053
1054 if ($viewobj->overallstats) {
1055 if ($viewobj->moreattempts) {
1056 $a = new stdClass();
1057 $a->method = quiz_get_grading_option_name($quiz->grademethod);
1058 $a->mygrade = quiz_format_grade($quiz, $viewobj->mygrade);
1059 $a->quizgrade = quiz_format_grade($quiz, $quiz->grade);
c544ee92 1060 $resultinfo .= $this->heading(get_string('gradesofar', 'quiz', $a), 3);
da59992e
DL
1061 } else {
1062 $a = new stdClass();
1063 $a->grade = quiz_format_grade($quiz, $viewobj->mygrade);
1064 $a->maxgrade = quiz_format_grade($quiz, $quiz->grade);
1065 $a = get_string('outofshort', 'quiz', $a);
c544ee92 1066 $resultinfo .= $this->heading(get_string('yourfinalgradeis', 'quiz', $a), 3);
06eb64b8 1067 }
da59992e 1068 }
cbe87543 1069
da59992e 1070 if ($viewobj->mygradeoverridden) {
7933ab8c 1071
37015e0c 1072 $resultinfo .= html_writer::tag('p', get_string('overriddennotice', 'grades'),
4e5b9e49 1073 array('class' => 'overriddennotice'))."\n";
da59992e
DL
1074 }
1075 if ($viewobj->gradebookfeedback) {
c544ee92 1076 $resultinfo .= $this->heading(get_string('comment', 'quiz'), 3);
c9c21e16 1077 $resultinfo .= html_writer::div($viewobj->gradebookfeedback, 'quizteacherfeedback') . "\n";
da59992e
DL
1078 }
1079 if ($viewobj->feedbackcolumn) {
c544ee92 1080 $resultinfo .= $this->heading(get_string('overallfeedback', 'quiz'), 3);
c9c21e16 1081 $resultinfo .= html_writer::div(
1b327dec 1082 quiz_feedback_for_grade($viewobj->mygrade, $quiz, $context),
c9c21e16 1083 'quizgradefeedback') . "\n";
da59992e 1084 }
cbe87543 1085
da59992e
DL
1086 if ($resultinfo) {
1087 $output .= $this->box($resultinfo, 'generalbox', 'feedback');
06eb64b8
DL
1088 }
1089 return $output;
1090 }
1091
2c3e2b53 1092 /**
d755b0f5
TH
1093 * Output either a link to the review page for an attempt, or a button to
1094 * open the review in a popup window.
2c3e2b53 1095 *
d755b0f5
TH
1096 * @param moodle_url $url of the target page.
1097 * @param bool $reviewinpopup whether a pop-up is required.
1098 * @param array $popupoptions options to pass to the popup_action constructor.
1099 * @return string HTML to output.
2c3e2b53 1100 */
d755b0f5
TH
1101 public function review_link($url, $reviewinpopup, $popupoptions) {
1102 if ($reviewinpopup) {
1103 $button = new single_button($url, get_string('review', 'quiz'));
1104 $button->add_action(new popup_action('click', $url, 'quizpopup', $popupoptions));
1105 return $this->render($button);
cbe87543 1106
d755b0f5
TH
1107 } else {
1108 return html_writer::link($url, get_string('review', 'quiz'),
1109 array('title' => get_string('reviewthisattempt', 'quiz')));
06eb64b8 1110 }
d755b0f5 1111 }
06eb64b8 1112
d755b0f5
TH
1113 /**
1114 * Displayed where there might normally be a review link, to explain why the
1115 * review is not available at this time.
1116 * @param string $message optional message explaining why the review is not possible.
1117 * @return string HTML to output.
1118 */
1119 public function no_review_message($message) {
1120 return html_writer::nonempty_tag('span', $message,
1121 array('class' => 'noreviewmessage'));
06eb64b8 1122 }
da59992e
DL
1123
1124 /**
1125 * Returns the same as {@link quiz_num_attempt_summary()} but wrapped in a link
1126 * to the quiz reports.
1127 *
1128 * @param object $quiz the quiz object. Only $quiz->id is used at the moment.
fcd5e245
DL
1129 * @param object $cm the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid
1130 * fields are used at the moment.
da59992e 1131 * @param object $context the quiz context.
fcd5e245
DL
1132 * @param bool $returnzero if false (default), when no attempts have been made '' is returned
1133 * instead of 'Attempts: 0'.
1134 * @param int $currentgroup if there is a concept of current group where this method is being
1135 * called
da59992e
DL
1136 * (e.g. a report) pass it in here. Default 0 which means no current group.
1137 * @return string HTML fragment for the link.
1138 */
8e8bd3f9 1139 public function quiz_attempt_summary_link_to_reports($quiz, $cm, $context,
fcd5e245 1140 $returnzero = false, $currentgroup = 0) {
da59992e
DL
1141 global $CFG;
1142 $summary = quiz_num_attempt_summary($quiz, $cm, $returnzero, $currentgroup);
1143 if (!$summary) {
1144 return '';
1145 }
fcd5e245 1146
da59992e
DL
1147 require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
1148 $url = new moodle_url('/mod/quiz/report.php', array(
1149 'id' => $cm->id, 'mode' => quiz_report_default_report($context)));
1150 return html_writer::link($url, $summary);
1151 }
2cdcb905
TH
1152
1153 /**
1154 * Output a graph, or a message saying that GD is required.
1155 * @param moodle_url $url the URL of the graph.
1156 * @param string $title the title to display above the graph.
1157 * @return string HTML fragment for the graph.
1158 */
1159 public function graph(moodle_url $url, $title) {
1160 global $CFG;
1161
689096bc 1162 $graph = html_writer::empty_tag('img', array('src' => $url, 'alt' => $title));
2cdcb905 1163
c544ee92 1164 return $this->heading($title, 3) . html_writer::tag('div', $graph, array('class' => 'graph'));
2cdcb905 1165 }
b3782c71
TH
1166}
1167
b3782c71
TH
1168class mod_quiz_links_to_other_attempts implements renderable {
1169 /**
1170 * @var array string attempt number => url, or null for the current attempt.
1171 */
1172 public $links = array();
3b7efd6d
DL
1173}
1174
1175class mod_quiz_view_object {
d755b0f5
TH
1176 /** @var array $infomessages of messages with information to display about the quiz. */
1177 public $infomessages;
2de9be52 1178 /** @var array $attempts contains all the user's attempts at this quiz. */
3b7efd6d 1179 public $attempts;
2de9be52
TH
1180 /** @var array $attemptobjs quiz_attempt objects corresponding to $attempts. */
1181 public $attemptobjs;
d755b0f5 1182 /** @var quiz_access_manager $accessmanager contains various access rules. */
3b7efd6d 1183 public $accessmanager;
0eafc988
TH
1184 /** @var bool $canreviewmine whether the current user has the capability to
1185 * review their own attempts. */
3b7efd6d 1186 public $canreviewmine;
d755b0f5
TH
1187 /** @var bool $canedit whether the current user has the capability to edit the quiz. */
1188 public $canedit;
1189 /** @var moodle_url $editurl the URL for editing this quiz. */
1190 public $editurl;
1191 /** @var int $attemptcolumn contains the number of attempts done. */
3b7efd6d 1192 public $attemptcolumn;
d755b0f5 1193 /** @var int $gradecolumn contains the grades of any attempts. */
3b7efd6d 1194 public $gradecolumn;
d755b0f5 1195 /** @var int $markcolumn contains the marks of any attempt. */
3b7efd6d 1196 public $markcolumn;
d755b0f5 1197 /** @var int $overallstats contains all marks for any attempt. */
3b7efd6d 1198 public $overallstats;
d755b0f5 1199 /** @var string $feedbackcolumn contains any feedback for and attempt. */
3b7efd6d 1200 public $feedbackcolumn;
d755b0f5 1201 /** @var string $timenow contains a timestamp in string format. */
3b7efd6d 1202 public $timenow;
d755b0f5 1203 /** @var int $numattempts contains the total number of attempts. */
3b7efd6d 1204 public $numattempts;
d755b0f5 1205 /** @var float $mygrade contains the user's final grade for a quiz. */
3b7efd6d 1206 public $mygrade;
d755b0f5 1207 /** @var bool $moreattempts whether this user is allowed more attempts. */
3b7efd6d 1208 public $moreattempts;
d755b0f5 1209 /** @var int $mygradeoverridden contains an overriden grade. */
3b7efd6d 1210 public $mygradeoverridden;
d755b0f5 1211 /** @var string $gradebookfeedback contains any feedback for a gradebook. */
3b7efd6d 1212 public $gradebookfeedback;
d755b0f5 1213 /** @var bool $unfinished contains 1 if an attempt is unfinished. */
3b7efd6d 1214 public $unfinished;
d755b0f5 1215 /** @var object $lastfinishedattempt the last attempt from the attempts array. */
3b7efd6d 1216 public $lastfinishedattempt;
0eafc988
TH
1217 /** @var array $preventmessages of messages telling the user why they can't
1218 * attempt the quiz now. */
d755b0f5
TH
1219 public $preventmessages;
1220 /** @var string $buttontext caption for the start attempt button. If this is null, show no
1221 * button, or if it is '' show a back to the course button. */
1222 public $buttontext;
1223 /** @var string $startattemptwarning alert to show the user before starting an attempt. */
1224 public $startattemptwarning;
1225 /** @var moodle_url $startattempturl URL to start an attempt. */
1226 public $startattempturl;
1227 /** @var moodle_url $startattempturl URL for any Back to the course button. */
1228 public $backtocourseurl;
eb665c34
FM
1229 /** @var bool $showbacktocourse should we show a back to the course button? */
1230 public $showbacktocourse;
d755b0f5
TH
1231 /** @var bool whether the attempt must take place in a popup window. */
1232 public $popuprequired;
1233 /** @var array options to use for the popup window, if required. */
1234 public $popupoptions;
1235 /** @var bool $quizhasquestions whether the quiz has any questions. */
1236 public $quizhasquestions;
1b327dec 1237}