first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for quizaccess_delaybetweenattempts.
*
* @package quizaccess_delaybetweenattempts
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_delaybetweenattempts\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for quizaccess_delaybetweenattempts implementing null_provider.
*
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
@@ -0,0 +1,33 @@
<?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/>.
/**
* Strings for the quizaccess_delaybetweenattempts plugin.
*
* @package quizaccess
* @subpackage delaybetweenattempts
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['pluginname'] = 'Delay between attempts quiz access rule';
$string['privacy:metadata'] = 'The Delay between attempts quiz access rule plugin does not store any personal data.';
$string['youcannotwait'] = 'This quiz closes before you will be allowed to start another attempt.';
$string['youmustwait'] = 'You must wait before you may re-attempt this quiz. You will be allowed to start another attempt after {$a}.';
@@ -0,0 +1,89 @@
<?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/>.
use mod_quiz\local\access_rule_base;
use mod_quiz\quiz_settings;
/**
* A rule imposing the delay between attempts settings.
*
* @package quizaccess_delaybetweenattempts
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_delaybetweenattempts extends access_rule_base {
public static function make(quiz_settings $quizobj, $timenow, $canignoretimelimits) {
if (empty($quizobj->get_quiz()->delay1) && empty($quizobj->get_quiz()->delay2)) {
return null;
}
return new self($quizobj, $timenow);
}
public function prevent_new_attempt($numprevattempts, $lastattempt) {
if ($this->quiz->attempts > 0 && $numprevattempts >= $this->quiz->attempts) {
// No more attempts allowed anyway.
return false;
}
if ($this->quiz->timeclose != 0 && $this->timenow > $this->quiz->timeclose) {
// No more attempts allowed anyway.
return false;
}
$nextstarttime = $this->compute_next_start_time($numprevattempts, $lastattempt);
if ($this->timenow < $nextstarttime) {
if ($this->quiz->timeclose == 0 || $nextstarttime <= $this->quiz->timeclose) {
return get_string('youmustwait', 'quizaccess_delaybetweenattempts',
userdate($nextstarttime));
} else {
return get_string('youcannotwait', 'quizaccess_delaybetweenattempts');
}
}
return false;
}
/**
* Compute the next time a student would be allowed to start an attempt,
* according to this rule.
* @param int $numprevattempts number of previous attempts.
* @param stdClass $lastattempt information about the previous attempt.
* @return number the time.
*/
protected function compute_next_start_time($numprevattempts, $lastattempt) {
if ($numprevattempts == 0) {
return 0;
}
$lastattemptfinish = $lastattempt->timefinish;
if ($this->quiz->timelimit > 0) {
$lastattemptfinish = min($lastattemptfinish,
$lastattempt->timestart + $this->quiz->timelimit);
}
if ($numprevattempts == 1 && $this->quiz->delay1) {
return $lastattemptfinish + $this->quiz->delay1;
} else if ($numprevattempts > 1 && $this->quiz->delay2) {
return $lastattemptfinish + $this->quiz->delay2;
}
return 0;
}
public function is_finished($numprevattempts, $lastattempt) {
$nextstarttime = $this->compute_next_start_time($numprevattempts, $lastattempt);
return $this->timenow <= $nextstarttime &&
$this->quiz->timeclose != 0 && $nextstarttime >= $this->quiz->timeclose;
}
}
@@ -0,0 +1,286 @@
<?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/>.
namespace quizaccess_delaybetweenattempts;
use mod_quiz\quiz_settings;
use quizaccess_delaybetweenattempts;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/accessrule/delaybetweenattempts/rule.php');
/**
* Unit tests for the quizaccess_delaybetweenattempts plugin.
*
* @package quizaccess_delaybetweenattempts
* @category test
* @copyright 2008 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class rule_test extends \basic_testcase {
public function test_just_first_delay(): void {
$quiz = new \stdClass();
$quiz->attempts = 3;
$quiz->timelimit = 0;
$quiz->delay1 = 1000;
$quiz->delay2 = 0;
$quiz->timeclose = 0;
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz_settings($quiz, $cm, null);
$attempt = new \stdClass();
$attempt->timefinish = 10000;
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
$this->assertEmpty($rule->description());
$this->assertFalse($rule->prevent_access());
$this->assertFalse($rule->is_finished(0, $attempt));
$this->assertFalse($rule->end_time($attempt));
$this->assertFalse($rule->time_left_display($attempt, 0));
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000)));
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$attempt->timefinish = 9000;
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$attempt->timefinish = 9001;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001)));
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
}
public function test_just_second_delay(): void {
$quiz = new \stdClass();
$quiz->attempts = 5;
$quiz->timelimit = 0;
$quiz->delay1 = 0;
$quiz->delay2 = 1000;
$quiz->timeclose = 0;
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz_settings($quiz, $cm, null);
$attempt = new \stdClass();
$attempt->timefinish = 10000;
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
$this->assertEmpty($rule->description());
$this->assertFalse($rule->prevent_access());
$this->assertFalse($rule->is_finished(0, $attempt));
$this->assertFalse($rule->end_time($attempt));
$this->assertFalse($rule->time_left_display($attempt, 0));
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
$this->assertFalse($rule->prevent_new_attempt(5, $attempt));
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
$this->assertEquals($rule->prevent_new_attempt(2, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000)));
$this->assertEquals($rule->prevent_new_attempt(3, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000)));
$attempt->timefinish = 9000;
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
$attempt->timefinish = 9001;
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
$this->assertEquals($rule->prevent_new_attempt(2, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001)));
$this->assertEquals($rule->prevent_new_attempt(4, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001)));
}
public function test_just_both_delays(): void {
$quiz = new \stdClass();
$quiz->attempts = 5;
$quiz->timelimit = 0;
$quiz->delay1 = 2000;
$quiz->delay2 = 1000;
$quiz->timeclose = 0;
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz_settings($quiz, $cm, null);
$attempt = new \stdClass();
$attempt->timefinish = 10000;
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
$this->assertEmpty($rule->description());
$this->assertFalse($rule->prevent_access());
$this->assertFalse($rule->is_finished(0, $attempt));
$this->assertFalse($rule->end_time($attempt));
$this->assertFalse($rule->time_left_display($attempt, 0));
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
$this->assertFalse($rule->prevent_new_attempt(5, $attempt));
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(12000)));
$this->assertEquals($rule->prevent_new_attempt(2, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000)));
$this->assertEquals($rule->prevent_new_attempt(3, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000)));
$attempt->timefinish = 8000;
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
$attempt->timefinish = 8001;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001)));
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$this->assertFalse($rule->prevent_new_attempt(4, $attempt));
$attempt->timefinish = 9000;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000)));
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
$attempt->timefinish = 9001;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11001)));
$this->assertEquals($rule->prevent_new_attempt(2, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001)));
$this->assertEquals($rule->prevent_new_attempt(4, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001)));
}
public function test_with_close_date(): void {
$quiz = new \stdClass();
$quiz->attempts = 5;
$quiz->timelimit = 0;
$quiz->delay1 = 2000;
$quiz->delay2 = 1000;
$quiz->timeclose = 15000;
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz_settings($quiz, $cm, null);
$attempt = new \stdClass();
$attempt->timefinish = 13000;
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
$this->assertEmpty($rule->description());
$this->assertFalse($rule->prevent_access());
$this->assertFalse($rule->is_finished(0, $attempt));
$this->assertFalse($rule->end_time($attempt));
$this->assertFalse($rule->time_left_display($attempt, 0));
$attempt->timefinish = 13000;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(15000)));
$attempt->timefinish = 13001;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youcannotwait', 'quizaccess_delaybetweenattempts'));
$attempt->timefinish = 14000;
$this->assertEquals($rule->prevent_new_attempt(2, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(15000)));
$attempt->timefinish = 14001;
$this->assertEquals($rule->prevent_new_attempt(2, $attempt),
get_string('youcannotwait', 'quizaccess_delaybetweenattempts'));
$rule = new quizaccess_delaybetweenattempts($quizobj, 15000);
$attempt->timefinish = 13000;
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
$attempt->timefinish = 13001;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youcannotwait', 'quizaccess_delaybetweenattempts'));
$attempt->timefinish = 14000;
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$attempt->timefinish = 14001;
$this->assertEquals($rule->prevent_new_attempt(2, $attempt),
get_string('youcannotwait', 'quizaccess_delaybetweenattempts'));
$rule = new quizaccess_delaybetweenattempts($quizobj, 15001);
$attempt->timefinish = 13000;
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
$attempt->timefinish = 13001;
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
$attempt->timefinish = 14000;
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$attempt->timefinish = 14001;
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
}
public function test_time_limit_and_overdue(): void {
$quiz = new \stdClass();
$quiz->attempts = 5;
$quiz->timelimit = 100;
$quiz->delay1 = 2000;
$quiz->delay2 = 1000;
$quiz->timeclose = 0;
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz_settings($quiz, $cm, null);
$attempt = new \stdClass();
$attempt->timestart = 9900;
$attempt->timefinish = 10100;
$rule = new quizaccess_delaybetweenattempts($quizobj, 10000);
$this->assertEmpty($rule->description());
$this->assertFalse($rule->prevent_access());
$this->assertFalse($rule->is_finished(0, $attempt));
$this->assertFalse($rule->end_time($attempt));
$this->assertFalse($rule->time_left_display($attempt, 0));
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
$this->assertFalse($rule->prevent_new_attempt(5, $attempt));
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(12000)));
$this->assertEquals($rule->prevent_new_attempt(2, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000)));
$this->assertEquals($rule->prevent_new_attempt(3, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000)));
$attempt->timestart = 7950;
$attempt->timefinish = 8000;
$this->assertFalse($rule->prevent_new_attempt(1, $attempt));
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
$attempt->timestart = 7950;
$attempt->timefinish = 8001;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001)));
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$this->assertFalse($rule->prevent_new_attempt(4, $attempt));
$attempt->timestart = 8950;
$attempt->timefinish = 9000;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000)));
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
$attempt->timestart = 8950;
$attempt->timefinish = 9001;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11001)));
$this->assertEquals($rule->prevent_new_attempt(2, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001)));
$this->assertEquals($rule->prevent_new_attempt(4, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001)));
$attempt->timestart = 8900;
$attempt->timefinish = 9100;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11000)));
$this->assertFalse($rule->prevent_new_attempt(2, $attempt));
$this->assertFalse($rule->prevent_new_attempt(3, $attempt));
$attempt->timestart = 8901;
$attempt->timefinish = 9100;
$this->assertEquals($rule->prevent_new_attempt(1, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(11001)));
$this->assertEquals($rule->prevent_new_attempt(2, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001)));
$this->assertEquals($rule->prevent_new_attempt(4, $attempt),
get_string('youmustwait', 'quizaccess_delaybetweenattempts', userdate(10001)));
}
}
@@ -0,0 +1,32 @@
<?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/>.
/**
* Version information for the quizaccess_delaybetweenattempts plugin.
*
* @package quizaccess
* @subpackage delaybetweenattempts
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600;
$plugin->component = 'quizaccess_delaybetweenattempts';