mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
109 lines
4.4 KiB
PHP
109 lines
4.4 KiB
PHP
<?php
|
|
// This file is part of Moodle - http://moodle.org/
|
|
//
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
/**
|
|
* Base class for rules that restrict the ability to attempt a quiz.
|
|
*
|
|
* @package mod
|
|
* @subpackage quiz
|
|
* @copyright 2011 The Open University
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
|
|
/**
|
|
* A base class that defines the interface for the various quiz access rules.
|
|
* Most of the methods are defined in a slightly unnatural way because we either
|
|
* want to say that access is allowed, or explain the reason why it is block.
|
|
* Therefore instead of is_access_allowed(...) we have prevent_access(...) that
|
|
* return false if access is permitted, or a string explanation (which is treated
|
|
* as true) if access should be blocked. Slighly unnatural, but acutally the easist
|
|
* way to implement this.
|
|
*
|
|
* @copyright 2009 Tim Hunt
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
abstract class quiz_access_rule_base {
|
|
protected $_quiz;
|
|
protected $_quizobj;
|
|
protected $_timenow;
|
|
/**
|
|
* Create an instance of this rule for a particular quiz.
|
|
* @param object $quiz the quiz we will be controlling access to.
|
|
*/
|
|
public function __construct($quizobj, $timenow) {
|
|
$this->_quizobj = $quizobj;
|
|
$this->_quiz = $quizobj->get_quiz();
|
|
$this->_timenow = $timenow;
|
|
}
|
|
/**
|
|
* Whether or not a user should be allowed to start a new attempt at this quiz now.
|
|
* @param int $numattempts the number of previous attempts this user has made.
|
|
* @param object $lastattempt information about the user's last completed attempt.
|
|
* @return string false if access should be allowed, a message explaining the
|
|
* reason if access should be prevented.
|
|
*/
|
|
public function prevent_new_attempt($numprevattempts, $lastattempt) {
|
|
return false;
|
|
}
|
|
/**
|
|
* Whether or not a user should be allowed to start a new attempt at this quiz now.
|
|
* @return string false if access should be allowed, a message explaining the
|
|
* reason if access should be prevented.
|
|
*/
|
|
public function prevent_access() {
|
|
return false;
|
|
}
|
|
/**
|
|
* Information, such as might be shown on the quiz view page, relating to this restriction.
|
|
* There is no obligation to return anything. If it is not appropriate to tell students
|
|
* about this rule, then just return ''.
|
|
* @return mixed a message, or array of messages, explaining the restriction
|
|
* (may be '' if no message is appropriate).
|
|
*/
|
|
public function description() {
|
|
return '';
|
|
}
|
|
/**
|
|
* If this rule can determine that this user will never be allowed another attempt at
|
|
* this quiz, then return true. This is used so we can know whether to display a
|
|
* final grade on the view page. This will only be called if there is not a currently
|
|
* active attempt for this user.
|
|
* @param int $numattempts the number of previous attempts this user has made.
|
|
* @param object $lastattempt information about the user's last completed attempt.
|
|
* @return bool true if this rule means that this user will never be allowed another
|
|
* attempt at this quiz.
|
|
*/
|
|
public function is_finished($numprevattempts, $lastattempt) {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* If, because of this rule, the user has to finish their attempt by a certain time,
|
|
* you should override this method to return the amount of time left in seconds.
|
|
* @param object $attempt the current attempt
|
|
* @param int $timenow the time now. We don't use $this->_timenow, so we can
|
|
* give the user a more accurate indication of how much time is left.
|
|
* @return mixed false if there is no deadline, of the time left in seconds if there is one.
|
|
*/
|
|
public function time_left($attempt, $timenow) {
|
|
return false;
|
|
}
|
|
}
|