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 310 and 311] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   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_openclosedate plugin.
  19   *
  20   * @package    quizaccess
  21   * @subpackage openclosedate
  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 enforcing open and close dates.
  34   *
  35   * @copyright  2009 Tim Hunt
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class quizaccess_openclosedate extends quiz_access_rule_base {
  39  
  40      public static function make(quiz $quizobj, $timenow, $canignoretimelimits) {
  41          // This rule is always used, even if the quiz has no open or close date.
  42          return new self($quizobj, $timenow);
  43      }
  44  
  45      public function prevent_access() {
  46          $message = get_string('notavailable', 'quizaccess_openclosedate');
  47  
  48          if ($this->timenow < $this->quiz->timeopen) {
  49              return $message;
  50          }
  51  
  52          if (!$this->quiz->timeclose) {
  53              return false;
  54          }
  55  
  56          if ($this->timenow <= $this->quiz->timeclose) {
  57              return false;
  58          }
  59  
  60          if ($this->quiz->overduehandling != 'graceperiod') {
  61              return $message;
  62          }
  63  
  64          if ($this->timenow <= $this->quiz->timeclose + $this->quiz->graceperiod) {
  65              return false;
  66          }
  67  
  68          return $message;
  69      }
  70  
  71      public function is_finished($numprevattempts, $lastattempt) {
  72          return $this->quiz->timeclose && $this->timenow > $this->quiz->timeclose;
  73      }
  74  
  75      public function end_time($attempt) {
  76          if ($this->quiz->timeclose) {
  77              return $this->quiz->timeclose;
  78          }
  79          return false;
  80      }
  81  
  82      public function time_left_display($attempt, $timenow) {
  83          // If this is a teacher preview after the close date, do not show
  84          // the time.
  85          if ($attempt->preview && $timenow > $this->quiz->timeclose) {
  86              return false;
  87          }
  88          // Otherwise, return to the time left until the close date, providing that is
  89          // less than QUIZ_SHOW_TIME_BEFORE_DEADLINE.
  90          $endtime = $this->end_time($attempt);
  91          if ($endtime !== false && $timenow > $endtime - QUIZ_SHOW_TIME_BEFORE_DEADLINE) {
  92              return $endtime - $timenow;
  93          }
  94          return false;
  95      }
  96  }