Skip to content
Snippets Groups Projects
Commit 4473cf68 authored by Tim Hunt's avatar Tim Hunt
Browse files

Fix the quetiontype to make the deferred feedback tests pass.

parent 388520af
No related branches found
No related tags found
No related merge requests found
......@@ -345,24 +345,13 @@ class qtype_stack_question extends question_graded_automatically {
}
public function is_gradable_response(array $response) {
// The following code requires all *inputs* to be non-empty and valid.
$allblank = true;
foreach ($this->inputs as $name => $input) {
$status = $this->get_input_state($name, $response)->status;
if (stack_input::INVALID == $status) {
return false;
}
$allblank = $allblank && ($status == stack_input::BLANK);
}
return !$allblank;
/*
// I think this is closer to the mark....
$anyprtgradable = false;
// If any PRT is gradable, then we can grade the question.
foreach ($this->prts as $index => $prt) {
$anyprtgradable = $anyprtgradable || $this->can_execute_prt($prt, $response);
if ($this->can_execute_prt($prt, $response, true)) {
return true;
}
return $anyprtgradable;
*/
}
return false;
}
public function get_validation_error(array $response) {
......@@ -374,7 +363,7 @@ class qtype_stack_question extends question_graded_automatically {
$fraction = 0;
foreach ($this->prts as $index => $prt) {
$results = $this->get_prt_result($index, $response);
$results = $this->get_prt_result($index, $response, true);
$fraction += $results['fraction'];
}
return array($fraction, question_state::graded_state_for_fraction($fraction));
......@@ -384,11 +373,16 @@ class qtype_stack_question extends question_graded_automatically {
* Do we have all the necessary inputs to execute one of the potential response trees?
* @param stack_potentialresponse_tree $prt the tree in question.
* @param array $response the response.
* @param bool $acceptvalid if this is true, then we will grade things even
* if the corresponding inputs are only VALID, and not SCORE.
* @return bool can this PRT be executed for that response.
*/
protected function can_execute_prt(stack_potentialresponse_tree $prt, $response) {
protected function can_execute_prt(stack_potentialresponse_tree $prt, $response, $acceptvalid) {
foreach ($prt->get_required_variables(array_keys($this->inputs)) as $name) {
if (stack_input::SCORE != $this->get_input_state($name, $response)->status) {
$status = $this->get_input_state($name, $response)->status;
if (stack_input::SCORE == $status || ($acceptvalid && stack_input::VALID == $status)) {
// This input is in an OK state.
} else {
return false;
}
}
......@@ -399,29 +393,21 @@ class qtype_stack_question extends question_graded_automatically {
* Evaluate a PRT for a particular response.
* @param string $index the index of the PRT to evaluate.
* @param array $response the response to process.
* @param bool $acceptvalid if this is true, then we will grade things even
* if the corresponding inputs are only VALID, and not SCORE.
* @return array the result from $prt->evaluate_response(), or a fake array
* if the tree cannot be executed.
*/
public function get_prt_result($index, $response) {
public function get_prt_result($index, $response, $acceptvalid) {
$this->validate_cache($response);
if (array_key_exists($index, $this->prtresults)) {
return $this->prtresults[$index];
}
// Make sure we use modified inputs
$modifiedresponse = array();
foreach ($response as $name => $val) {
if (array_key_exists($name, $this->inputstates)) {
$modifiedresponse[$name] = $this->inputstates[$name]->contentsmodified;
}
}
$prt = $this->prts[$index];
if ($this->can_execute_prt($prt, $response)) {
$this->prtresults[$index] = $prt->evaluate_response(
$this->session, $this->options, $modifiedresponse, $this->seed);
} else {
if (!$this->can_execute_prt($prt, $response, $acceptvalid)) {
$this->prtresults[$index] = array(
'feedback' => '',
'answernote' => null,
......@@ -431,7 +417,20 @@ class qtype_stack_question extends question_graded_automatically {
'penalty' => null,
'fraction' => null,
);
return $this->prtresults[$index];
}
// Make sure we use modified inputs
$modifiedresponse = array();
foreach ($prt->get_required_variables(array_keys($this->inputs)) as $name) {
$state = $this->get_input_state($name, $response);
if (stack_input::SCORE == $state->status || ($acceptvalid && stack_input::VALID == $state->status)) {
$modifiedresponse[$name] = $state->contentsmodified;
}
}
$this->prtresults[$index] = $prt->evaluate_response(
$this->session, $this->options, $modifiedresponse, $this->seed);
return $this->prtresults[$index];
}
......
......@@ -55,11 +55,12 @@ class qtype_stack_renderer extends qtype_renderer {
}
foreach ($question->prts as $index => $prt) {
$feedback = '';
if ($options->feedback) {
$result = $question->get_prt_result($index, $response);
$result = $question->get_prt_result($index, $response, $qa->get_state()->is_finished());
if (!is_null($result['valid'])) {
$feedback = $this->prt_feedback($index, $qa, $question, $result);
} else {
$feedback = '';
}
}
$questiontext = str_replace("[[feedback:{$index}]]", $feedback, $questiontext);
}
......@@ -101,8 +102,11 @@ class qtype_stack_renderer extends qtype_renderer {
// Replace any PRT feedback.
foreach ($question->prts as $index => $prt) {
$result = $question->get_prt_result($index, $response);
$feedback = '';
$result = $question->get_prt_result($index, $response, $qa->get_state()->is_finished());
if (!is_null($result['valid'])) {
$feedback = $this->prt_feedback($index, $qa, $question, $result);
}
$feedbacktext = str_replace("[[feedback:{$index}]]", $feedback, $feedbacktext);
}
......
......@@ -85,7 +85,7 @@ class stack_question_test {
}
foreach ($this->expectedresults as $prtname => $expectedresult) {
$result = $question->get_prt_result($prtname, $response);
$result = $question->get_prt_result($prtname, $response, false);
$results->set_prt_result($prtname, new stack_potentialresponse_tree_state(
'', $result['feedback'], explode(' | ', $result['answernote']),
$result['valid'], $result['score'], $result['penalty']));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment