Skip to content

Commit d1c4c58

Browse files
committed
fix: increase Moodle compatibility to 4.2+
1 parent dc388b5 commit d1c4c58

File tree

4 files changed

+63
-79
lines changed

4 files changed

+63
-79
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ Students will now be restricted to starting a new attempt only within the define
4040

4141
## Requirements
4242

43-
- Moodle 3.11 or higher
44-
- PHP 7.4 or higher
43+
- Moodle 4.2 or higher
44+
- PHP 8.0 or higher
4545

4646

4747
## Translations available

rule.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@
2424
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2525
*/
2626

27-
defined('MOODLE_INTERNAL') || die();
28-
29-
require_once($CFG->dirroot . '/mod/quiz/accessrule/accessrulebase.php');
27+
use mod_quiz\local\access_rule_base;
28+
use mod_quiz\quiz_settings;
3029

3130
/**
3231
* Quiz access rule to enforce a time limit for starting an attempt.
3332
*
3433
* This rule restricts students from starting an attempt after a specified period
3534
* from when the quiz is opened.
3635
*/
37-
class quizaccess_startlimit extends quiz_access_rule_base {
36+
class quizaccess_startlimit extends access_rule_base {
3837
/** @var int $startlimit The maximum allowed time (in seconds) to start the attempt after the quiz opens. */
3938
protected int $startlimit;
4039

@@ -43,12 +42,12 @@ class quizaccess_startlimit extends quiz_access_rule_base {
4342
*
4443
* Returns null if the rule does not apply (quiz time not set or user can ignore time limits).
4544
*
46-
* @param quiz $quizobj The quiz object.
45+
* @param quiz_settings $quizobj The quiz object.
4746
* @param int $timenow Current timestamp.
4847
* @param bool $canignoretimelimits Whether the user can ignore time limits.
4948
* @return self|null
5049
*/
51-
public static function make(quiz $quizobj, $timenow, $canignoretimelimits): ?self {
50+
public static function make(quiz_settings $quizobj, $timenow, $canignoretimelimits): ?self {
5251
global $DB;
5352

5453
if (empty($quizobj->get_quiz()->timeopen) || $canignoretimelimits) {
@@ -66,7 +65,7 @@ public static function make(quiz $quizobj, $timenow, $canignoretimelimits): ?sel
6665
/**
6766
* Constructor.
6867
*
69-
* @param quiz $quizobj The quiz object.
68+
* @param quiz_settings $quizobj The quiz object.
7069
* @param int $timenow Current timestamp.
7170
* @param int $startlimit The maximum allowed start time in seconds.
7271
*/
@@ -84,7 +83,7 @@ public function __construct($quizobj, $timenow, $startlimit) {
8483
* @return string false if access should be allowed, a message explaining the
8584
* reason if access should be prevented.
8685
*/
87-
public function prevent_new_attempt($numprevattempts, $lastattempt) {
86+
public function prevent_new_attempt($numprevattempts, $lastattempt): false|string {
8887
$quiz = $this->quiz;
8988

9089
if (empty($quiz->timeopen) || empty($this->startlimit)) {
@@ -128,7 +127,7 @@ public function is_finished($numprevattempts, $lastattempt): bool {
128127
*
129128
* {@inheritdoc}
130129
*/
131-
public function description() {
130+
public function description(): lang_string|string|null {
132131
$quiz = $this->quizobj->get_quiz();
133132
$limit = (int) $quiz->startlimit;
134133

@@ -144,7 +143,7 @@ public function description() {
144143
* @param mod_quiz_mod_form $quizform the quiz settings form that is being built.
145144
* @param MoodleQuickForm $mform the wrapped MoodleQuickForm.
146145
*/
147-
public static function add_settings_form_fields(mod_quiz_mod_form $quizform, MoodleQuickForm $mform) {
146+
public static function add_settings_form_fields(mod_quiz_mod_form $quizform, MoodleQuickForm $mform): void {
148147
$mform->addElement('duration', 'startlimit', get_string('startlimit', 'quizaccess_startlimit'), [
149148
'optional' => true,
150149
]);
@@ -156,7 +155,7 @@ public static function add_settings_form_fields(mod_quiz_mod_form $quizform, Moo
156155
* @param int $quizid the id of the quiz we are loading settings for. This
157156
* can also be accessed as quiz.id in the SQL. (quiz is a table alisas for {quiz}.)
158157
*/
159-
public static function get_settings_sql($quizid) {
158+
public static function get_settings_sql($quizid): array {
160159
return ['qa_sl.startlimit', 'LEFT JOIN {quizaccess_startlimit} qa_sl ON qa_sl.quizid = quiz.id', []];
161160
}
162161

@@ -165,7 +164,7 @@ public static function get_settings_sql($quizid) {
165164
* @param object $quiz the data from the quiz form, including $quiz->id
166165
* which is the id of the quiz being saved.
167166
*/
168-
public static function save_settings($quiz) {
167+
public static function save_settings($quiz): void {
169168
global $DB;
170169

171170
$record = $DB->get_record('quizaccess_startlimit', ['quizid' => $quiz->id]);
@@ -186,7 +185,7 @@ public static function save_settings($quiz) {
186185
* @param object $quiz the data from the database, including $quiz->id
187186
* which is the id of the quiz being deleted.
188187
*/
189-
public static function delete_settings($quiz) {
188+
public static function delete_settings($quiz): void {
190189
global $DB;
191190
$DB->delete_records('quizaccess_startlimit', ['quizid' => $quiz->id]);
192191
}

0 commit comments

Comments
 (0)