|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 require_once($CFG->dirroot . '/mod/quiz/accessrule/accessrulebase.php'); 00030 00031 00038 class quizaccess_openclosedate extends quiz_access_rule_base { 00039 00040 public static function make(quiz $quizobj, $timenow, $canignoretimelimits) { 00041 // This rule is always used, even if the quiz has no open or close date. 00042 return new self($quizobj, $timenow); 00043 } 00044 00045 public function description() { 00046 $result = array(); 00047 if ($this->timenow < $this->quiz->timeopen) { 00048 $result[] = get_string('quiznotavailable', 'quizaccess_openclosedate', 00049 userdate($this->quiz->timeopen)); 00050 00051 } else if ($this->quiz->timeclose && $this->timenow > $this->quiz->timeclose) { 00052 $result[] = get_string('quizclosed', 'quiz', userdate($this->quiz->timeclose)); 00053 00054 } else { 00055 if ($this->quiz->timeopen) { 00056 $result[] = get_string('quizopenedon', 'quiz', userdate($this->quiz->timeopen)); 00057 } 00058 if ($this->quiz->timeclose) { 00059 $result[] = get_string('quizcloseson', 'quiz', userdate($this->quiz->timeclose)); 00060 } 00061 } 00062 00063 return $result; 00064 } 00065 00066 public function prevent_access() { 00067 if ($this->timenow < $this->quiz->timeopen || 00068 ($this->quiz->timeclose && $this->timenow > $this->quiz->timeclose)) { 00069 return get_string('notavailable', 'quizaccess_openclosedate'); 00070 } 00071 return false; 00072 } 00073 00074 public function is_finished($numprevattempts, $lastattempt) { 00075 return $this->quiz->timeclose && $this->timenow > $this->quiz->timeclose; 00076 } 00077 00078 public function time_left($attempt, $timenow) { 00079 // If this is a teacher preview after the close date, do not show 00080 // the time. 00081 if ($attempt->preview && $timenow > $this->quiz->timeclose) { 00082 return false; 00083 } 00084 00085 // Otherwise, return to the time left until the close date, providing 00086 // that is less than QUIZ_SHOW_TIME_BEFORE_DEADLINE 00087 if ($this->quiz->timeclose) { 00088 $timeleft = $this->quiz->timeclose - $timenow; 00089 if ($timeleft < QUIZ_SHOW_TIME_BEFORE_DEADLINE) { 00090 return $timeleft; 00091 } 00092 } 00093 return false; 00094 } 00095 }