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

Refactor context session filtering out of the cassession2 method.

parent c12c7bf6
No related branches found
No related tags found
No related merge requests found
......@@ -117,6 +117,12 @@ class qtype_stack_question extends question_graded_automatically_with_countback
*/
protected $session;
/**
* Special variables in the question which should be exposed to the inputs and answer tests.
* @var cas_evaluatable[]
*/
protected $contextsession;
/**
* @var stack_ast_container[] STACK specific: the teacher's answers for each input.
*/
......@@ -415,7 +421,15 @@ class qtype_stack_question extends question_graded_automatically_with_countback
$this->runtimeerrors[$s] = true;
}
$contextsession = $this->session->get_contextsession();
// Set up the context session for this question.
$contextsession = array();
foreach ($this->session->get_session() as $statement) {
if (method_exists($statement, 'is_toplevel_property') && $statement->is_toplevel_property('contextvariable')) {
$contextsession[] = $statement;
}
}
$this->contextsession = $contextsession;
foreach ($this->prts as $name => $prt) {
$prt->add_contextsession($contextsession);
}
......@@ -463,7 +477,6 @@ class qtype_stack_question extends question_graded_automatically_with_countback
* teacher's model answers.
*/
protected function adapt_inputs() {
$contextsession = $this->session->get_contextsession();
foreach ($this->inputs as $name => $input) {
// TODO: again should we give the whole thing to the input.
$teacheranswer = '';
......@@ -471,7 +484,7 @@ class qtype_stack_question extends question_graded_automatically_with_countback
$teacheranswer = $this->tas[$name]->get_value();
}
$input->adapt_to_model_answer($teacheranswer);
$input->add_contextsession($contextsession);
$input->add_contextsession($this->contextsession);
}
}
......
......@@ -328,7 +328,7 @@ class stack_cas_session2 {
$line .= stack_utils::php_string_to_maxima_string($statement->get_source_context());
$line .= ')';
if ($statement->is_toplevel_property('blockexternal')) {
if (method_exists($statement, 'is_toplevel_property') && $statement->is_toplevel_property('blockexternal')) {
$preblock .= $line . "$\n";
} else {
$command .= self::SEP . $line;
......@@ -534,20 +534,6 @@ class stack_cas_session2 {
return trim($keyvals);
}
/*
* This is used to extract all the expressions for which "blockexternal" is true.
* This enables some context variables to communicate between the castext parts and the inputs.
*/
public function get_contextsession() {
$contextsession = array();
foreach ($this->statements as $statement) {
if ($statement->is_toplevel_property('contextvariable')) {
$contextsession[] = $statement;
}
}
return $contextsession;
}
public function get_debuginfo() {
if (trim($this->timeouterrmessage) !== '') {
return $this->timeouterrmessage;
......
......@@ -52,7 +52,7 @@ abstract class stack_input {
protected $name;
/**
* Special variables in the question which should be exposed to the inputs.
* Special variables in the question which should be exposed to the inputs and answer tests.
* @var cas_evaluatable[]
*/
protected $contextsession = array();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment