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

Further work on plugging STACK into Moodle.

parent 32f56ce8
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,11 @@ require_once(dirname(__FILE__) . '/stack/potentialresponsetree.class.php');
*/
class qtype_stack_question extends question_graded_automatically {
/**
* @var int STACK specific: seeds Maxima's random number generator.
*/
public $seed;
/**
* @var array STACK specific: string name as it appears in the question text => stack_interaction_element
*/
......@@ -54,6 +59,11 @@ class qtype_stack_question extends question_graded_automatically {
*/
public $prts;
/**
* @var array stack_cas_session STACK specific: session of variables.
*/
public $session;
/**
* @var stack_options STACK specific: question-level options.
*/
......@@ -67,20 +77,24 @@ class qtype_stack_question extends question_graded_automatically {
$questionvars = new stack_cas_keyval($this->questionvariables, $this->options, $seed, 't');
$qtext = new stack_cas_text($this->questiontext, $questionvars->get_session(), $seed, 't', false, true);
//HACK - this represents my confusion between "question" and "render"...
$this->questiontext = $qtext->get_display_castext();
$this->session = $qtext->get_session();
$step->set_qt_var('_questiontext', $qtext->get_display_castext());
$step->set_qt_var('_questiontext', $qtext->get_display_castext());
$step->set_qt_var('_session', $qtext->get_session());
if ($qtext->get_errors()) {
//TODO better error trapping that this.
throw new Exception('Error rendering question text: ' . $qtext->get_errors());
}
//$generalfeedback = new stack_cas_text($this->generalfeedback, $this->session, $seed, 't', false, true);
//$this->generalfeedback = $generalfeedback->get_display_castext();
}
public function apply_attempt_state(question_attempt_step $step) {
// TODO
$this->seed = $step->get_qt_var('_seed');
$this->questiontext = $step->get_qt_var('_questiontext');
$this->session = $step->get_qt_var('_session');
}
public function get_expected_data() {
......@@ -96,7 +110,7 @@ class qtype_stack_question extends question_graded_automatically {
}
public function get_correct_response() {
return null; // TODO can we implement this?
return null; // TODO can we implement this? Yes! Take the teacher's answer from each interaction element.
}
public function is_same_response(array $prevresponse, array $newresponse) {
......
......@@ -33,15 +33,18 @@ defined('MOODLE_INTERNAL') || die();
class qtype_stack_renderer extends qtype_renderer {
public function formulation_and_controls(question_attempt $qa, question_display_options $options) {
$question = $qa->get_question();
//$response = $question->get_response($qa);
$questiontext = $question->questiontext; //$question->get_qt_var('_questiontext');
$questiontext = $question->questiontext;
$seed = 0; // $question->seed;
$session = null; // $question->session;
if (empty($question->interactions)) {
$xhtml = '<div class="secondaryFeedback">'.stack_string('stackQuestion_noQuestionParts').'</div>'.$questiontext;
} else {
foreach ($question->interactions as $name => $interaction) {
// TODO: get the value of the current answer to put into the html.
$currentanswer = ''; //$qa->get_last_qt_var('answer');
$fieldname = $qa->get_qt_field_name($name);
$currentanswer = $qa->get_last_qt_var($name);
$answers[$name] = $currentanswer;
$questiontext = str_replace("#{$name}#",
$interaction->get_xhtml($currentanswer, $fieldname, $options->readonly), $questiontext);
......@@ -54,15 +57,12 @@ class qtype_stack_renderer extends qtype_renderer {
// TODO see stack_old/lib/ui/DisplayItem.php.
$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....
$results = $prt->evaluate_response($session, $question->options, $answers, $seed);
} else { // TODO...
$feedback = '';
$results['feedback'] = '';
}
$feedback = $this->format_prt_feedback($results['feedback']);
$questiontext = str_replace("<PRTfeedback>{$index}</PRTfeedback>", $feedback, $questiontext);
}
}
......@@ -70,6 +70,10 @@ class qtype_stack_renderer extends qtype_renderer {
$qa, 'question', 'questiontext', $question->id);
}
private function format_prt_feedback($feedback) {
return '<div class="PRTFeedback">'.$feedback.'</div>';
}
/**
* Decides if the potential response tree should be executed.
*/
......
......@@ -25,10 +25,10 @@ class stack_interaction_algebra extends stack_interaction_element {
public function get_xhtml($studentanswer, $fieldname, $readonly) {
$value = '';
if ($studentanswer) {
$value = ' value="' . htmlspecialchars($studentanswer) . '"';
} else {
if (''===trim($studentanswer)) {
$value = ' value="' . htmlspecialchars($this->parameters['syntaxHint']) . '"';
} else {
$value = ' value="' . htmlspecialchars($studentanswer) . '"';
}
$disabled = '';
......
......@@ -47,6 +47,12 @@ class stack_interaction_algebra_test extends UnitTestCase {
$el->get_xhtml('', 'stack1__ans1', false));
}
public function test_get_xhtml_zero() {
$el = stack_interaction_controller::make_element('algebraic', 'ans1', '0');
$this->assertEqual('<input type="text" name="stack1__ans1" size="15" value="0" />',
$el->get_xhtml('0', 'stack1__ans1', false));
}
public function test_get_xhtml_pre_filled() {
$el = stack_interaction_controller::make_element('algebraic', 'test', 'x^2');
$this->assertEqual('<input type="text" name="stack1__test" size="15" value="x+y" />',
......
......@@ -152,7 +152,6 @@ class stack_potentialresponse_node {
$feedback[] = $resultbranch['feedback'];
}
$this->result = $result;
return array(
'result' => $result,
'valid' => $at->get_at_valid(),
......@@ -236,7 +235,7 @@ class stack_potentialresponse_node {
default:
throw new Exception('stack_potentialresponse_node: update_mark called ' .
'with invalid mark modificiation method: ' . $markmodification);
'with invalid mark modificiation method: ' . $resultbranch['markmodification']);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment