From 052714bff72ebc90d79dae73f1e8200518b7cf73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20B=C3=B6sch?= Date: Tue, 4 Jul 2023 08:00:53 +0200 Subject: [PATCH] 4.2 compatibility done otherwise. --- rule.php | 18 +++++++----------- tests/rule_test.php | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/rule.php b/rule.php index 857406a..8a9a915 100644 --- a/rule.php +++ b/rule.php @@ -26,31 +26,27 @@ // This work-around is required until Moodle 4.2 is the lowest version we support. if (class_exists('\mod_quiz\local\access_rule_base')) { - class_alias('\mod_quiz\local\access_rule_base', '\quizaccess_honestycheck_parent_class_alias'); - class_alias('\mod_quiz\form\preflight_check_form', '\quizaccess_honestycheck_preflight_form_alias'); - class_alias('\mod_quiz\quiz_settings', '\quizaccess_honestycheck_quiz_settings_class_alias'); + // Use aliases at class_loader level to maintain compatibility. + \class_alias(mod_quiz\local\access_rule_base::class, quiz_access_rule_base::class); + \class_alias(mod_quiz\form\preflight_check_form::class, mod_quiz_preflight_check_form::class); + \class_alias(mod_quiz\quiz_settings::class, quiz::class); } else { require_once($CFG->dirroot . '/mod/quiz/accessrule/accessrulebase.php'); - class_alias('\quiz_access_rule_base', '\quizaccess_honestycheck_parent_class_alias'); - class_alias('\mod_quiz_preflight_check_form', '\quizaccess_honestycheck_preflight_form_alias'); - class_alias('\quiz', '\quizaccess_honestycheck_quiz_settings_class_alias'); } - - /** * A rule requiring the student to promise not to cheat. * * @copyright 2011 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class quizaccess_honestycheck extends quizaccess_honestycheck_parent_class_alias { +class quizaccess_honestycheck extends quiz_access_rule_base { public function is_preflight_check_required($attemptid) { return empty($attemptid); } - public function add_preflight_check_form_fields(quizaccess_honestycheck_preflight_form_alias $quizform, + public function add_preflight_check_form_fields(mod_quiz_preflight_check_form $quizform, MoodleQuickForm $mform, $attemptid) { $mform->addElement('header', 'honestycheckheader', @@ -69,7 +65,7 @@ public function validate_preflight_check($data, $files, $errors, $attemptid) { return $errors; } - public static function make(quizaccess_honestycheck_quiz_settings_class_alias $quizobj, $timenow, $canignoretimelimits) { + public static function make(quiz $quizobj, $timenow, $canignoretimelimits) { if (empty($quizobj->get_quiz()->honestycheckrequired)) { return null; diff --git a/tests/rule_test.php b/tests/rule_test.php index e378500..c2f9e28 100644 --- a/tests/rule_test.php +++ b/tests/rule_test.php @@ -40,7 +40,7 @@ public function test_honestycheck_rule() { $quiz->questions = ''; $cm = new stdClass(); $cm->id = 0; - $quizobj = new \quizaccess_honestycheck_quiz_settings_class_alias($quiz, $cm, null); + $quizobj = new \quiz($quiz, $cm, null); $rule = quizaccess_honestycheck::make($quizobj, 0, false); $this->assertNull($rule);