From 7699ded56d46d0bd2a813f5624720faad5e9f07e Mon Sep 17 00:00:00 2001 From: David Szkiba Date: Fri, 10 Jan 2025 16:58:10 +0100 Subject: [PATCH] GH-791 Make update personability a regular method --- .../preselect_task/updatepersonability.php | 1 + classes/teststrategy/strategy.php | 12 ++++++++++++ classes/teststrategy/strategy/classicalcat.php | 1 - classes/teststrategy/strategy/inferallsubscales.php | 1 - .../teststrategy/strategy/infergreateststrength.php | 1 - .../teststrategy/strategy/inferlowestskillgap.php | 1 - classes/teststrategy/strategy/relevantscales.php | 1 - .../teststrategy/strategy/teststrategy_fastest.php | 1 - 8 files changed, 13 insertions(+), 6 deletions(-) diff --git a/classes/teststrategy/preselect_task/updatepersonability.php b/classes/teststrategy/preselect_task/updatepersonability.php index e519b1674..679b5a87d 100644 --- a/classes/teststrategy/preselect_task/updatepersonability.php +++ b/classes/teststrategy/preselect_task/updatepersonability.php @@ -167,6 +167,7 @@ public function set_context(array $context): self { */ public function run(array &$context, callable $next): result { $this->progress = $context['progress']; + $this->context = $context; // If we do not know the answer to the last question, we do not have to // update the person ability. Also, pilot questions should not be used diff --git a/classes/teststrategy/strategy.php b/classes/teststrategy/strategy.php index a6475a63f..9ce16236c 100644 --- a/classes/teststrategy/strategy.php +++ b/classes/teststrategy/strategy.php @@ -51,6 +51,7 @@ use local_catquiz\teststrategy\preselect_task\remove_uncalculated; use local_catquiz\teststrategy\preselect_task\removeplayedquestions; use local_catquiz\teststrategy\preselect_task\updatepersonability; +use local_catquiz\teststrategy\preselect_task\updatepersonability_testing; use local_catquiz\teststrategy\progress; use local_catquiz\wb_middleware_runner; use moodle_exception; @@ -201,6 +202,13 @@ public function return_next_testitem(array $context) { $this->context = $val; } + // Core methods called in every strategy. + $res = $this->update_personability(); + if ($res->iserr()) { + return $res; + } + $context = $res->unwrap(); + foreach ($this->get_preselecttasks() as $modifier) { // When this is called for running tests, check if there is a // X_testing class and if so, use that one. @@ -480,6 +488,10 @@ protected function check_page_reload(): result { */ protected function update_personability(): result { $updateabilitytask = new updatepersonability(); + // When this is called for running tests, use the testing class. + if (getenv('USE_TESTING_CLASS_FOR')) { + $updateabilitytask = new updatepersonability_testing(); + } $result = $updateabilitytask->run($this->context, fn ($context) => result::ok($context)); return $result; } diff --git a/classes/teststrategy/strategy/classicalcat.php b/classes/teststrategy/strategy/classicalcat.php index 7703cedcd..ba9f88ec8 100644 --- a/classes/teststrategy/strategy/classicalcat.php +++ b/classes/teststrategy/strategy/classicalcat.php @@ -75,7 +75,6 @@ class classicalcat extends strategy { */ public function get_preselecttasks(): array { return [ - updatepersonability::class, addscalestandarderror::class, maximumquestionscheck::class, removeplayedquestions::class, diff --git a/classes/teststrategy/strategy/inferallsubscales.php b/classes/teststrategy/strategy/inferallsubscales.php index ce82ed31a..4dc5be578 100644 --- a/classes/teststrategy/strategy/inferallsubscales.php +++ b/classes/teststrategy/strategy/inferallsubscales.php @@ -85,7 +85,6 @@ class inferallsubscales extends strategy { */ public function get_preselecttasks(): array { return [ - updatepersonability::class, firstquestionselector::class, // If this is the first question of this attempt, return it here. addscalestandarderror::class, maximumquestionscheck::class, // Cancel quiz attempt if we reached maximum of questions. diff --git a/classes/teststrategy/strategy/infergreateststrength.php b/classes/teststrategy/strategy/infergreateststrength.php index 3b8a92f82..fb8804ee7 100644 --- a/classes/teststrategy/strategy/infergreateststrength.php +++ b/classes/teststrategy/strategy/infergreateststrength.php @@ -90,7 +90,6 @@ class infergreateststrength extends strategy { */ public function get_preselecttasks(): array { return [ - updatepersonability::class, firstquestionselector::class, // If this is the first question of this attempt, return it here. addscalestandarderror::class, maximumquestionscheck::class, // Cancel quiz attempt if we reached maximum of questions. diff --git a/classes/teststrategy/strategy/inferlowestskillgap.php b/classes/teststrategy/strategy/inferlowestskillgap.php index c6ee63323..1f0d3434f 100644 --- a/classes/teststrategy/strategy/inferlowestskillgap.php +++ b/classes/teststrategy/strategy/inferlowestskillgap.php @@ -84,7 +84,6 @@ class inferlowestskillgap extends strategy { */ public function get_preselecttasks(): array { return [ - updatepersonability::class, firstquestionselector::class, // If this is the first question of this attempt, return it here. addscalestandarderror::class, maximumquestionscheck::class, // Cancel quiz attempt if we reached maximum of questions. diff --git a/classes/teststrategy/strategy/relevantscales.php b/classes/teststrategy/strategy/relevantscales.php index b2310b02e..b5b05c8cb 100644 --- a/classes/teststrategy/strategy/relevantscales.php +++ b/classes/teststrategy/strategy/relevantscales.php @@ -84,7 +84,6 @@ class relevantscales extends strategy { */ public function get_preselecttasks(): array { return [ - updatepersonability::class, firstquestionselector::class, // If this is the first question of this attempt, return it here. addscalestandarderror::class, maximumquestionscheck::class, // Cancel quiz attempt if we reached maximum of questions. diff --git a/classes/teststrategy/strategy/teststrategy_fastest.php b/classes/teststrategy/strategy/teststrategy_fastest.php index 86301fc66..b3e6ae78b 100644 --- a/classes/teststrategy/strategy/teststrategy_fastest.php +++ b/classes/teststrategy/strategy/teststrategy_fastest.php @@ -79,7 +79,6 @@ class teststrategy_fastest extends strategy { */ public function get_preselecttasks(): array { return [ - updatepersonability::class, fisherinformation::class, addscalestandarderror::class, maximumquestionscheck::class,