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_numattempts plugin. 19 * 20 * @package quizaccess 21 * @subpackage numattempts 22 * @copyright 2011 The Open University 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 27defined('MOODLE_INTERNAL') || die(); 28 29require_once($CFG->dirroot . '/mod/quiz/accessrule/accessrulebase.php'); 30 31 32/** 33 * A rule controlling the number of attempts allowed. 34 * 35 * @copyright 2009 Tim Hunt 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38class quizaccess_numattempts extends quiz_access_rule_base { 39 40 public static function make(quiz $quizobj, $timenow, $canignoretimelimits) { 41 42 if ($quizobj->get_num_attempts_allowed() == 0) { 43 return null; 44 } 45 46 return new self($quizobj, $timenow); 47 } 48 49 public function description() { 50 return get_string('attemptsallowedn', 'quizaccess_numattempts', $this->quiz->attempts); 51 } 52 53 public function prevent_new_attempt($numprevattempts, $lastattempt) { 54 if ($numprevattempts >= $this->quiz->attempts) { 55 return get_string('nomoreattempts', 'quiz'); 56 } 57 return false; 58 } 59 60 public function is_finished($numprevattempts, $lastattempt) { 61 return $numprevattempts >= $this->quiz->attempts; 62 } 63} 64