Skip to content

Commit 4dba455

Browse files
committed
Squashed commit of the following:
commit b7ff238 Author: Karin Borm <k.borm@ostfalia.de> Date: Thu Nov 14 17:46:36 2024 +0100 no handling for cbm behaviours commit d54a4e6 Author: Karin Borm <k.borm@ostfalia.de> Date: Tue Nov 12 13:36:09 2024 +0100 new deferred behaviour
1 parent a4ad80a commit 4dba455

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ following features:
77
- store extra grading information (feedback from grader)
88
- avoid regrading when finishing an attempt
99
- special handling for internal grading errors
10-
- whenever a new response is saved (without grading) fraction is set to 'null'
11-
- optional adaptivenopenalty behaviour
12-
- adaptivenopenalty behaviour: fraction cannot be negative (minimum is 0)
10+
11+
Copyright notice: The coderunner behaviour
12+
(https://moodle.org/plugins/qbehaviour_adaptive_adapted_for_coderunner) was used a starting point.
13+
14+
15+
16+
raction cannot be negative (minimum is 0)
1317

1418

1519
Copyright notice: The coderunner behaviour

behaviour.php

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,25 @@ class qbehaviour_adaptiveexternalgrading extends qbehaviour_adaptive {
4040
public $showsubmit = true;
4141
public $showcompile = false;
4242

43+
protected $preferred = null;
44+
4345
public function __construct(question_attempt $qa, $preferredbehaviour) {
44-
parent::__construct($qa, $preferredbehaviour);
46+
if ($preferredbehaviour == 'deferredcbm' || $preferredbehaviour == 'immediatecbm') {
47+
throw new moodle_exception('proforma questions are not compatible with cbm behaviour');
48+
}
4549

50+
parent::__construct($qa, $preferredbehaviour);
51+
$this->preferred = $preferredbehaviour;
4652
if (!is_string($preferredbehaviour)) {
47-
// happens if teacher calls question review
48-
// => set dummy value
53+
// happens if teacher calls question review => set dummy value
4954
$this->nopenalty = true;
5055

5156
if (!is_null($preferredbehaviour)) {
5257
if (get_class($preferredbehaviour) == "qbehaviour_adaptiveexternalgrading") {
5358
$this->nopenalty = $preferredbehaviour->nopenalty;
59+
$this->preferred = $preferredbehaviour->preferred;
60+
} else if (is_a($preferredbehaviour, 'question_behaviour')) {
61+
$this->preferred = $preferredbehaviour->get_name();
5462
} else {
5563
throw new coding_exception("preferredbehaviour is not a string, instead: " . get_class($preferredbehaviour));
5664
}
@@ -73,6 +81,7 @@ public function __construct(question_attempt $qa, $preferredbehaviour) {
7381
$this->nopenalty = true;
7482
break;
7583
case 'deferredfeedback':
84+
case 'deferredcbm':
7685
$this->nopenalty = true;
7786
$this->showsubmit = false;
7887
break;
@@ -87,7 +96,7 @@ public function __construct(question_attempt $qa, $preferredbehaviour) {
8796

8897
// TODO??
8998
public function is_compatible_question(question_definition $question) {
90-
return $question instanceof question_automatically_gradable;
99+
return $question instanceof qtype_proforma_question;
91100
}
92101

93102
private function get_result_from_grader($response, question_attempt_pending_step $pendingstep) {
@@ -107,7 +116,13 @@ private function get_result_from_grader($response, question_attempt_pending_step
107116
// - right answer with fraction 1
108117
// - new answer => unknown result
109118
public function process_save(question_attempt_pending_step $pendingstep) {
110-
$status = parent::process_save($pendingstep);
119+
if ($this->isdeferred()) {
120+
$status = question_behaviour_with_save::process_save($pendingstep);
121+
122+
} else {
123+
$status = parent::process_save($pendingstep);
124+
}
125+
111126
// + set fraction to null because we need new grading
112127
// + in case of a new response
113128
$pendingstep->set_fraction(null);
@@ -287,6 +302,7 @@ protected function adjusted_fraction($fraction, $prevtries) {
287302

288303
// +
289304
public function get_state_string($showcorrectness) {
305+
// Modify behaviour for try:
290306
$laststep = $this->qa->get_last_step();
291307
if ($laststep->has_behaviour_var('_try')) {
292308
if (is_null($laststep->get_behaviour_var('_rawfraction'))) {
@@ -295,8 +311,35 @@ public function get_state_string($showcorrectness) {
295311
$state = $laststep->get_state();
296312
return $state->default_string(true);
297313
}
314+
return parent::get_state_string($showcorrectness);
298315
}
299316

317+
if ($this->isdeferred()) {
318+
// Special treatment for deferred behaviour scenarios:
319+
// In case of no input the state string from
320+
// the deferred behaviour shall be used to be compliant with other question types.
321+
$state = $this->qa->get_state();
322+
if ($state == question_state::$todo) {
323+
return question_behaviour_with_save::get_state_string($showcorrectness);
324+
}
325+
}
300326
return parent::get_state_string($showcorrectness);
301327
}
328+
329+
/**
330+
* returns true if the preferred behaviour is a deferred one so that
331+
* the grader need not to be executed as soon as possible.
332+
* @return bool
333+
*/
334+
protected function isdeferred() : bool {
335+
if (!isset($this->preferred)) {
336+
return false;
337+
}
338+
switch ($this->preferred) {
339+
case 'deferredfeedback':
340+
case 'deferredcbm':
341+
return true;
342+
}
343+
return false;
344+
}
302345
}

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
defined('MOODLE_INTERNAL') || die();
2525

26-
$plugin->version = 2019101700;
26+
$plugin->version = 2024111200;
2727
$plugin->requires = 2016120503;
2828
$plugin->cron = 0;
2929
$plugin->component = 'qbehaviour_adaptiveexternalgrading';
3030
$plugin->maturity = MATURITY_STABLE;
31-
$plugin->release = '0.9.6';
31+
$plugin->release = '0.9.7';
3232

3333
$plugin->dependencies = array();
3434

0 commit comments

Comments
 (0)