Skip to content

Commit 738a254

Browse files
committed
GH-791 Make first question selector and page reload check normal methods
1 parent a53da03 commit 738a254

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed

classes/teststrategy/preselect_task/firstquestionselector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class firstquestionselector extends preselect_task implements wb_middleware {
9494
*/
9595
public function run(array &$context, callable $next): result {
9696
$this->progress = $context['progress'];
97+
$this->context = $context;
9798
// Don't do anything if this is not the first question of the current attempt.
9899
if (!$this->progress->is_first_question()) {
99100
return $next($context);

classes/teststrategy/strategy.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,28 @@ public function return_next_testitem(array $context) {
179179
return $checkbreakres;
180180
}
181181

182+
if ($this->pre_check_page_reload()) {
183+
$res = $this->check_page_reload();
184+
if ($res->unwrap()) {
185+
return $res;
186+
}
187+
}
188+
189+
if ($this->pre_check_first_question_selector()) {
190+
$res = $this->first_question_selector();
191+
if ($res->iserr()) {
192+
return $res;
193+
}
194+
$val = $res->unwrap();
195+
// If the result contains a single object, this is the question to be returned.
196+
// Othewise, it contains the updated $context array with the ability and standarderror set in such a way, that the
197+
// teststrategy will return the correct question (e.g. the question corresponding to mean ability of all students).
198+
if (is_object($val)) {
199+
return $res;
200+
}
201+
$this->context = $val;
202+
}
203+
182204
foreach ($this->get_preselecttasks() as $modifier) {
183205
// When this is called for running tests, check if there is a
184206
// X_testing class and if so, use that one.
@@ -230,6 +252,28 @@ public function return_next_testitem(array $context) {
230252
return result::ok($selectedquestion);
231253
}
232254

255+
/**
256+
* If true, the check page reload is called before updating the ability.
257+
*
258+
* Quickfix, could probabily be removed.
259+
*
260+
* @return bool
261+
*/
262+
protected function pre_check_page_reload(): bool {
263+
return false;
264+
}
265+
266+
/**
267+
* If true, the first question selector is called before updating the ability.
268+
*
269+
* Quickfix, could probabily be removed.
270+
*
271+
* @return bool
272+
*/
273+
protected function pre_check_first_question_selector(): bool {
274+
return false;
275+
}
276+
233277
/**
234278
* Helper method to update attempt feedback data
235279
*
@@ -524,8 +568,7 @@ protected function maybereturnpilot(): result {
524568
*/
525569
protected function first_question_selector(): result {
526570
$firstquestionselector = new firstquestionselector();
527-
$result = $firstquestionselector->run($this->context, fn ($context) => result::ok($context));
528-
return $result;
571+
return $firstquestionselector->run($this->context, fn ($context) => result::ok($context));
529572
}
530573

531574
/**

classes/teststrategy/strategy/classicalcat.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class classicalcat extends strategy {
7575
*/
7676
public function get_preselecttasks(): array {
7777
return [
78-
checkpagereload::class,
7978
updatepersonability::class,
8079
addscalestandarderror::class,
8180
maximumquestionscheck::class,
@@ -87,6 +86,18 @@ public function get_preselecttasks(): array {
8786
strategyclassicscore::class,
8887
];
8988
}
89+
90+
/**
91+
* If true, the check page reload is called before updating the ability.
92+
*
93+
* Quickfix, could probabily be removed.
94+
*
95+
* @return bool
96+
*/
97+
protected function pre_check_page_reload(): bool {
98+
return false;
99+
}
100+
90101
/**
91102
* Returns feedback generators.
92103
*

classes/teststrategy/strategy/teststrategy_fastest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ class teststrategy_fastest extends strategy {
7979
*/
8080
public function get_preselecttasks(): array {
8181
return [
82-
checkpagereload::class,
83-
firstquestionselector::class,
8482
updatepersonability::class,
8583
fisherinformation::class,
8684
addscalestandarderror::class,
@@ -96,6 +94,28 @@ public function get_preselecttasks(): array {
9694
];
9795
}
9896

97+
/**
98+
* If true, the check page reload is called before updating the ability.
99+
*
100+
* Quickfix, could probabily be removed.
101+
*
102+
* @return bool
103+
*/
104+
protected function pre_check_page_reload(): bool {
105+
return true;
106+
}
107+
108+
/**
109+
* If true, the first question selector is called before updating the ability.
110+
*
111+
* Quickfix, could probabily be removed.
112+
*
113+
* @return bool
114+
*/
115+
protected function pre_check_first_question_selector(): bool {
116+
return true;
117+
}
118+
99119
/**
100120
* Get feedback generators.
101121
*

0 commit comments

Comments
 (0)