Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 402] [Versions 311 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   * Implementaton of the quizaccess_timelimit plugin.
  19   *
  20   * @package    quizaccess
  21   * @subpackage timelimit
  22   * @copyright  2011 The Open University
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  require_once($CFG->dirroot . '/mod/quiz/accessrule/accessrulebase.php');
  30  
  31  
  32  /**
  33   * A rule representing the time limit. It does not actually restrict access, but we use this
  34   * class to encapsulate some of the relevant code.
  35   *
  36   * @copyright  2009 Tim Hunt
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class quizaccess_timelimit extends quiz_access_rule_base {
  40  
  41      public static function make(quiz $quizobj, $timenow, $canignoretimelimits) {
  42  
  43          if (empty($quizobj->get_quiz()->timelimit) || $canignoretimelimits) {
  44              return null;
  45          }
  46  
  47          return new self($quizobj, $timenow);
  48      }
  49  
  50      public function description() {
  51          return get_string('quiztimelimit', 'quizaccess_timelimit',
  52                  format_time($this->quiz->timelimit));
  53      }
  54  
  55      public function end_time($attempt) {
  56          $timedue = $attempt->timestart + $this->quiz->timelimit;
  57          if ($this->quiz->timeclose) {
  58              $timedue = min($timedue, $this->quiz->timeclose);
  59          }
  60          return $timedue;
  61      }
  62  
  63      public function time_left_display($attempt, $timenow) {
  64          // If this is a teacher preview after the time limit expires, don't show the time_left
  65          $endtime = $this->end_time($attempt);
  66          if ($attempt->preview && $timenow > $endtime) {
  67              return false;
  68          }
  69          return $endtime - $timenow;
  70      }
  71  
  72      public function is_preflight_check_required($attemptid) {
  73          // Warning only required if the attempt is not already started.
  74          return $attemptid === null;
  75      }
  76  
  77      public function add_preflight_check_form_fields(mod_quiz_preflight_check_form $quizform,
  78              MoodleQuickForm $mform, $attemptid) {
  79          $mform->addElement('header', 'honestycheckheader',
  80                  get_string('confirmstartheader', 'quizaccess_timelimit'));
  81          $mform->addElement('static', 'honestycheckmessage', '',
  82                  get_string('confirmstart', 'quizaccess_timelimit', format_time($this->quiz->timelimit)));
  83      }
  84  }