Skip to content
Snippets Groups Projects
Commit 0603c08a authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Fixed input test page in the light of changes to interactionelement.class.php

parent d3dfb470
No related branches found
No related tags found
No related merge requests found
...@@ -271,3 +271,4 @@ $string['ATSysEquiv_SA_system_overdetermined'] = 'The entries in red below are ...@@ -271,3 +271,4 @@ $string['ATSysEquiv_SA_system_overdetermined'] = 'The entries in red below are
$string['studentValidation_yourLastAnswer'] = 'Your last answer was interpreted as '; $string['studentValidation_yourLastAnswer'] = 'Your last answer was interpreted as ';
$string['studentValidation_invalidAnswer'] = 'This answer is invalid. '; $string['studentValidation_invalidAnswer'] = 'This answer is invalid. ';
$string['stackQuestion_noQuestionParts'] = 'This item has no question parts for you to answer.';
...@@ -37,22 +37,64 @@ class qtype_stack_renderer extends qtype_renderer { ...@@ -37,22 +37,64 @@ class qtype_stack_renderer extends qtype_renderer {
$question = $qa->get_question(); $question = $qa->get_question();
$questiontext = $question->questiontext; $questiontext = $question->questiontext;
if (empty($question->interactions)) {
$xhtml = '<div class="secondaryFeedback">'.stack_string('stackQuestion_noQuestionParts').'</div>'.$questiontext;
} else {
foreach ($question->interactions as $name => $interaction) { foreach ($question->interactions as $name => $interaction) {
// TODO: get the value of the current answer to put into the html. // TODO: get the value of the current answer to put into the html.
$currentanswer = ''; //$qa->get_last_qt_var('answer'); $currentanswer = ''; //$qa->get_last_qt_var('answer');
$questiontext = str_replace("#{$name}#", $questiontext = str_replace("#{$name}#",
$interaction->get_xhtml($currentanswer, $options->readonly), $questiontext); $interaction->get_xhtml($currentanswer, $options->readonly), $questiontext);
// TODO see stack_old/lib/ui/DisplayItem.php. list ($status, $iefeedback) = $interaction->validate_student_response($currentanswer, $question->options);
$questiontext = str_replace("<IEfeedback>{$name}</IEfeedback>", '', $questiontext); $questiontext = str_replace("<IEfeedback>{$name}</IEfeedback>", $iefeedback, $questiontext);
$attemptstatus[$name] = $status;
} }
foreach ($question->prts as $index => $prt) { foreach ($question->prts as $index => $prt) {
// TODO see stack_old/lib/ui/DisplayItem.php. // TODO see stack_old/lib/ui/DisplayItem.php.
$questiontext = str_replace("<PRTfeedback>{$index}</PRTfeedback>", '', $questiontext); $requirednames = $prt->get_required_variables(array_keys($question->interactions));
if ($this->execute_prt($requirednames, $attemptstatus)) {
list($feedback, $answernote, $errors, $valid, $mark, $penalty) = $prt->evaluate_response($questionvars, $options, $answers, $seed);
if (!$valid) {
$penalty = 0;
}
// TODO store the outcomes of the attempt..
// TODO update the mark....
} else { // TODO...
$feedback = '';
}
$questiontext = str_replace("<PRTfeedback>{$index}</PRTfeedback>", $feedback, $questiontext);
}
} }
return $question->format_text($questiontext, $question->questiontextformat, return $question->format_text($questiontext, $question->questiontextformat,
$qa, 'question', 'questiontext', $question->id); $qa, 'question', 'questiontext', $question->id);
} }
/**
* Decides if the potential response tree should be executed.
*/
private function execute_prt($requirednames, $attemptstatus) {
$execute = true;
foreach ($requirednames as $name) {
if (array_key_exists ($name, $attemptstatus)) {
if ('score' != $attemptstatus[$name]) {
$execute = false;
}
} else {
$execute = false;
}
}
return $execute;
}
/**
* Tests whether the interaction element exists inside a math region.
*/
private function is_inside_maths($ie, $string) {
// remove all delimited regions and see if $ie remains in $string
$patterns = array('/\\$\\$(.+?)\\$\\$/', '/\\$(.+?)\\$/', '/\\\\\[(.+?)\\\\\]/', '/\\\\\((.+?)\\\\\)/');
$string = preg_replace($patterns, '', $string);
return strpos($string, $ie) === true;
}
} }
...@@ -210,6 +210,11 @@ class stack_interaction_element { ...@@ -210,6 +210,11 @@ class stack_interaction_element {
throw new Exception('stack_interaction_element: validate_student_response: options not of class stack_options'); throw new Exception('stack_interaction_element: validate_student_response: options not of class stack_options');
} }
if ('' == $sans) {
$status = '';
$feedback = '';
return array($status, $feedback);
}
$transformedanswer = $this->transform($sans); $transformedanswer = $this->transform($sans);
if (array_key_exists('insertStars', $this->parameters)) { if (array_key_exists('insertStars', $this->parameters)) {
...@@ -225,6 +230,7 @@ class stack_interaction_element { ...@@ -225,6 +230,7 @@ class stack_interaction_element {
$answer = new stack_cas_casstring($transformedanswer, $security='s', $syntax, $insertstars); $answer = new stack_cas_casstring($transformedanswer, $security='s', $syntax, $insertstars);
// TODO: we need to run this check over the names of the question variables....
if (array_key_exists('forbidWords', $this->parameters)) { if (array_key_exists('forbidWords', $this->parameters)) {
if ('' != $this->parameters['forbidWords']) { if ('' != $this->parameters['forbidWords']) {
$keywords = explode(',', $this->parameters['forbidWords']); $keywords = explode(',', $this->parameters['forbidWords']);
...@@ -272,7 +278,15 @@ class stack_interaction_element { ...@@ -272,7 +278,15 @@ class stack_interaction_element {
} }
$feedback = $this->generate_validation_feedback($valid, $display, $errors); $feedback = $this->generate_validation_feedback($valid, $display, $errors);
return array($valid, $feedback); // TODO - deal with status.....
if ($valid) {
$status = 'valid';
$status = 'score'; //TODO status transitions.
} else {
$status = 'invalid';
}
$status = $valid;
return array($status, $feedback);
} }
private function generate_validation_feedback($valid, $display, $errors) { private function generate_validation_feedback($valid, $display, $errors) {
......
...@@ -315,12 +315,16 @@ class stack_inputvalidation_test_data { ...@@ -315,12 +315,16 @@ class stack_inputvalidation_test_data {
} }
public static function run_test($test) { public static function run_test($test) {
$el = stack_interaction_controller::make_element('algebraic', 'sans1', 'x'); // Note: we would really like to do this, but want to pull apart the bits to
// TODO: expose these options to the teacher> // expose where the various errors occur.
$el->set_parameter('insertStars', true); //$el = stack_interaction_controller::make_element('algebraic', 'sans1', 'x');
$el->set_parameter('strictSyntax', false); //$el->set_parameter('insertStars', true);
$el->set_parameter('sameType', false); //$el->set_parameter('strictSyntax', false);
$cs = $el->validate_student_response($test->rawstring); //$el->set_parameter('sameType', false);
//$cs = $el->validate_student_response($test->rawstring);
$cs= new stack_cas_casstring($test->rawstring, $security='s', false, true);
$cs->set_cas_validation_casstring('sans1', true, true, null);
$phpvalid = $cs->get_valid(); $phpvalid = $cs->get_valid();
if ($phpvalid) { if ($phpvalid) {
...@@ -349,7 +353,7 @@ class stack_inputvalidation_test_data { ...@@ -349,7 +353,7 @@ class stack_inputvalidation_test_data {
} }
if ($phpvalid && $phpcasstring != $test->phpcasstring) { if ($phpvalid && $phpcasstring != $test->phpcasstring) {
$passed = false; $passed = false;
$errors .= ' '.stack_maxima_format_casstring($phpcasstring).' \(\neq \) '.stack_maxima_format_casstring($test); $errors .= ' '.stack_maxima_format_casstring($phpcasstring).' \(\neq \) '.stack_maxima_format_casstring($test->phpcasstring);
} }
$casvalid = ''; $casvalid = '';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment