Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

   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   * This page prints a summary of a quiz attempt before it is submitted.
  19   *
  20   * @package   mod_quiz
  21   * @copyright 2009 The Open University
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  use mod_quiz\output\navigation_panel_attempt;
  26  use mod_quiz\output\renderer;
  27  
  28  require_once(__DIR__ . '/../../config.php');
  29  require_once($CFG->dirroot . '/mod/quiz/locallib.php');
  30  
  31  $attemptid = required_param('attempt', PARAM_INT); // The attempt to summarise.
  32  $cmid = optional_param('cmid', null, PARAM_INT);
  33  
  34  $PAGE->set_url('/mod/quiz/summary.php', ['attempt' => $attemptid]);
  35  // During quiz attempts, the browser back/forwards buttons should force a reload.
  36  $PAGE->set_cacheable(false);
  37  $PAGE->set_secondary_active_tab("modulepage");
  38  
  39  $attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
  40  
  41  // Check login.
  42  require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
  43  
  44  // Check that this attempt belongs to this user.
  45  if ($attemptobj->get_userid() != $USER->id) {
  46      if ($attemptobj->has_capability('mod/quiz:viewreports')) {
  47          redirect($attemptobj->review_url(null));
  48      } else {
  49          throw new moodle_exception('notyourattempt', 'quiz', $attemptobj->view_url());
  50      }
  51  }
  52  
  53  // Check capabilites.
  54  if (!$attemptobj->is_preview_user()) {
  55      $attemptobj->require_capability('mod/quiz:attempt');
  56  }
  57  
  58  if ($attemptobj->is_preview_user()) {
  59      navigation_node::override_active_url($attemptobj->start_attempt_url());
  60  }
  61  
  62  // Check access.
  63  $accessmanager = $attemptobj->get_access_manager(time());
  64  $accessmanager->setup_attempt_page($PAGE);
  65  /** @var renderer $output */
  66  $output = $PAGE->get_renderer('mod_quiz');
  67  $messages = $accessmanager->prevent_access();
  68  if (!$attemptobj->is_preview_user() && $messages) {
  69      throw new \moodle_exception('attempterror', 'quiz', $attemptobj->view_url(),
  70              $output->access_messages($messages));
  71  }
  72  if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) {
  73      redirect($attemptobj->start_attempt_url(null));
  74  }
  75  
  76  $displayoptions = $attemptobj->get_display_options(false);
  77  
  78  // If the attempt is now overdue, or abandoned, deal with that.
  79  $attemptobj->handle_if_time_expired(time(), true);
  80  
  81  // If the attempt is already closed, redirect them to the review page.
  82  if ($attemptobj->is_finished()) {
  83      redirect($attemptobj->review_url());
  84  }
  85  
  86  \core\session\manager::keepalive(); // Try to prevent sessions expiring during quiz attempts.
  87  
  88  // Arrange for the navigation to be displayed.
  89  if (empty($attemptobj->get_quiz()->showblocks)) {
  90      $PAGE->blocks->show_only_fake_blocks();
  91  }
  92  
  93  $navbc = $attemptobj->get_navigation_panel($output, navigation_panel_attempt::class, -1);
  94  $regions = $PAGE->blocks->get_regions();
  95  $PAGE->blocks->add_fake_block($navbc, reset($regions));
  96  
  97  $PAGE->navbar->add(get_string('summaryofattempt', 'quiz'));
  98  $PAGE->set_title($attemptobj->summary_page_title());
  99  $PAGE->set_heading($attemptobj->get_course()->fullname);
 100  $PAGE->activityheader->disable();
 101  // Display the page.
 102  echo $output->summary_page($attemptobj, $displayoptions);
 103  
 104  // Log this page view.
 105  $attemptobj->fire_attempt_summary_viewed_event();