Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

   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 review of a particular question attempt.
  19   * This page is expected to only be used in a popup window.
  20   *
  21   * @package   mod_quiz
  22   * @copyright 1999 onwards Martin Dougiamas  {@link http://moodle.com}
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  
  27  require_once(__DIR__ . '/../../config.php');
  28  require_once ('locallib.php');
  29  
  30  $attemptid = required_param('attempt', PARAM_INT);
  31  $slot = required_param('slot', PARAM_INT);
  32  $seq = optional_param('step', null, PARAM_INT);
  33  $cmid = optional_param('cmid', null, PARAM_INT);
  34  
  35  $baseurl = new moodle_url('/mod/quiz/reviewquestion.php',
  36          array('attempt' => $attemptid, 'slot' => $slot));
  37  $currenturl = new moodle_url($baseurl);
  38  if (!is_null($seq)) {
  39      $currenturl->param('step', $seq);
  40  }
  41  $PAGE->set_url($currenturl);
  42  
  43  $attemptobj = quiz_create_attempt_handling_errors($attemptid, $cmid);
  44  
  45  // Check login.
  46  require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
  47  $attemptobj->check_review_capability();
  48  $student = $DB->get_record('user', array('id' => $attemptobj->get_userid()));
  49  
  50  $accessmanager = $attemptobj->get_access_manager(time());
  51  $options = $attemptobj->get_display_options(true);
  52  
  53  $PAGE->set_pagelayout('popup');
  54  $PAGE->set_title(get_string('reviewofquestion', 'quiz', array(
  55          'question' => format_string($attemptobj->get_question_name($slot)),
  56          'quiz' => format_string($attemptobj->get_quiz_name()), 'user' => fullname($student))));
  57  $PAGE->set_heading($attemptobj->get_course()->fullname);
  58  $output = $PAGE->get_renderer('mod_quiz');
  59  
  60  // Check permissions - warning there is similar code in review.php and
  61  // quiz_attempt::check_file_access. If you change on, change them all.
  62  if ($attemptobj->is_own_attempt()) {
  63      if (!$attemptobj->is_finished()) {
  64          echo $output->review_question_not_allowed($attemptobj, get_string('cannotreviewopen', 'quiz'));
  65          die();
  66      } else if (!$options->attempt) {
  67          echo $output->review_question_not_allowed($attemptobj,
  68                  $attemptobj->cannot_review_message());
  69          die();
  70      }
  71  
  72  } else if (!$attemptobj->is_review_allowed()) {
  73      throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noreviewattempt');
  74  }
  75  
  76  // Prepare summary informat about this question attempt.
  77  $summarydata = array();
  78  
  79  // Student name.
  80  $userpicture = new user_picture($student);
  81  $userpicture->courseid = $attemptobj->get_courseid();
  82  $summarydata['user'] = array(
  83      'title'   => $userpicture,
  84      'content' => new action_link(new moodle_url('/user/view.php', array(
  85              'id' => $student->id, 'course' => $attemptobj->get_courseid())),
  86              fullname($student, true)),
  87  );
  88  
  89  // Quiz name.
  90  $summarydata['quizname'] = array(
  91      'title'   => get_string('modulename', 'quiz'),
  92      'content' => format_string($attemptobj->get_quiz_name()),
  93  );
  94  
  95  // Question name.
  96  $summarydata['questionname'] = array(
  97      'title'   => get_string('question', 'quiz'),
  98      'content' => $attemptobj->get_question_name($slot),
  99  );
 100  
 101  // Other attempts at the quiz.
 102  if ($attemptobj->has_capability('mod/quiz:viewreports')) {
 103      $attemptlist = $attemptobj->links_to_other_attempts($baseurl);
 104      if ($attemptlist) {
 105          $summarydata['attemptlist'] = array(
 106              'title'   => get_string('attempts', 'quiz'),
 107              'content' => $attemptlist,
 108          );
 109      }
 110  }
 111  
 112  // Timestamp of this action.
 113  $timestamp = $attemptobj->get_question_action_time($slot);
 114  if ($timestamp) {
 115      $summarydata['timestamp'] = array(
 116          'title'   => get_string('completedon', 'quiz'),
 117          'content' => userdate($timestamp),
 118      );
 119  }
 120  
 121  echo $output->review_question_page($attemptobj, $slot, $seq,
 122          $attemptobj->get_display_options(true), $summarydata);