[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/quiz/accessrule/timelimit/ -> rule.php (source)

   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          return $attempt->timestart + $this->quiz->timelimit;
  57      }
  58  
  59      public function time_left_display($attempt, $timenow) {
  60          // If this is a teacher preview after the time limit expires, don't show the time_left
  61          $endtime = $this->end_time($attempt);
  62          if ($attempt->preview && $timenow > $endtime) {
  63              return false;
  64          }
  65          return $endtime - $timenow;
  66  
  67      }
  68  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1