Skip to content

Commit a4ad80a

Browse files
committed
bugfix: when a new answer is saved set fraction to 'null',
fraction cannot be negative (minimum is 0)
1 parent 6a8677c commit a4ad80a

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ 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'
1011
- optional adaptivenopenalty behaviour
12+
- adaptivenopenalty behaviour: fraction cannot be negative (minimum is 0)
13+
1114

1215
Copyright notice: The coderunner behaviour
1316
(https://moodle.org/plugins/qbehaviour_adaptive_adapted_for_coderunner) was used a starting point.

behaviour.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ private function get_result_from_grader($response, question_attempt_pending_step
102102
return $gradedata;
103103
}
104104

105+
// we set fraction to null:
106+
// scenario to handle:
107+
// - right answer with fraction 1
108+
// - new answer => unknown result
109+
public function process_save(question_attempt_pending_step $pendingstep) {
110+
$status = parent::process_save($pendingstep);
111+
// + set fraction to null because we need new grading
112+
// + in case of a new response
113+
$pendingstep->set_fraction(null);
114+
return $status;
115+
}
116+
117+
105118
public function process_submit(question_attempt_pending_step $pendingstep, $compile = false) {
106119
$status = $this->process_save($pendingstep);
107120

@@ -263,7 +276,8 @@ protected function adjusted_fraction($fraction, $prevtries) {
263276
return $fraction;
264277
} else {
265278
if (!is_null($fraction)) {
266-
return parent::adjusted_fraction($fraction, $prevtries);
279+
// + if adjusted fraction is negative than it is set to 0
280+
return max(0, parent::adjusted_fraction($fraction, $prevtries));
267281
} else {
268282
// ???
269283
return $fraction;
@@ -285,5 +299,4 @@ public function get_state_string($showcorrectness) {
285299

286300
return parent::get_state_string($showcorrectness);
287301
}
288-
289302
}

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 = 2019091700;
26+
$plugin->version = 2019101700;
2727
$plugin->requires = 2016120503;
2828
$plugin->cron = 0;
2929
$plugin->component = 'qbehaviour_adaptiveexternalgrading';
3030
$plugin->maturity = MATURITY_STABLE;
31-
$plugin->release = '0.9.5';
31+
$plugin->release = '0.9.6';
3232

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

0 commit comments

Comments
 (0)