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

Proposed solution 2. Just rely on the CAS cache.

parent e69abb7d
Branches
No related tags found
No related merge requests found
...@@ -117,6 +117,16 @@ class qtype_stack_question extends question_graded_automatically_with_countback ...@@ -117,6 +117,16 @@ class qtype_stack_question extends question_graded_automatically_with_countback
*/ */
protected $questionnoteinstantiated; protected $questionnoteinstantiated;
/**
* @var array stack_cas_session STACK specific: session of variables.
*/
public $questiontextinstantiated;
/**
* @var array stack_cas_session STACK specific: session of variables.
*/
public $specificfeedbackinstantiated;
/** /**
* The next three fields cache the results of some expensive computations. * The next three fields cache the results of some expensive computations.
* The chache is only vaid for a particular response, so we store the current * The chache is only vaid for a particular response, so we store the current
...@@ -225,6 +235,13 @@ class qtype_stack_question extends question_graded_automatically_with_countback ...@@ -225,6 +235,13 @@ class qtype_stack_question extends question_graded_automatically_with_countback
} }
$step->set_qt_var('_seed', $this->seed); $step->set_qt_var('_seed', $this->seed);
$this->initialise_question_from_seed();
}
/**
* Once we know the random seed, we can initialise all the other parts of the question.
*/
public function initialise_question_from_seed() {
// Build up the question session out of all the bits that need to go into it. // Build up the question session out of all the bits that need to go into it.
// 1. question variables. // 1. question variables.
$questionvars = new stack_cas_keyval($this->questionvariables, $this->options, $this->seed, 't'); $questionvars = new stack_cas_keyval($this->questionvariables, $this->options, $this->seed, 't');
...@@ -272,14 +289,10 @@ class qtype_stack_question extends question_graded_automatically_with_countback ...@@ -272,14 +289,10 @@ class qtype_stack_question extends question_graded_automatically_with_countback
$session->get_errors($this->user_can_edit())); $session->get_errors($this->user_can_edit()));
} }
// Now store the values that depend on the instantiated session.
$step->set_qt_var('_questionvars', $session->get_keyval_representation());
$step->set_qt_var('_questiontext', $questiontext->get_display_castext());
$step->set_qt_var('_feedback', $feedbacktext->get_display_castext());
$this->questionnoteinstantiated = $notetext->get_display_castext();
$step->set_qt_var('_questionnote', $this->questionnoteinstantiated);
// Finally, store only those values really needed for later. // Finally, store only those values really needed for later.
$this->questiontextinstantiated = $questiontext->get_display_castext();
$this->specificfeedbackinstantiated = $feedbacktext->get_display_castext();
$this->questionnoteinstantiated = $notetext->get_display_castext();
$session->prune_session($session_length); $session->prune_session($session_length);
$this->session = $session; $this->session = $session;
...@@ -289,10 +302,7 @@ class qtype_stack_question extends question_graded_automatically_with_countback ...@@ -289,10 +302,7 @@ class qtype_stack_question extends question_graded_automatically_with_countback
public function apply_attempt_state(question_attempt_step $step) { public function apply_attempt_state(question_attempt_step $step) {
$this->seed = (int) $step->get_qt_var('_seed'); $this->seed = (int) $step->get_qt_var('_seed');
$questionvars = new stack_cas_keyval($step->get_qt_var('_questionvars'), $this->options, $this->seed, 't'); $this->initialise_question_from_seed();
$this->session = $questionvars->get_session();
$this->questionnoteinstantiated = $step->get_qt_var('_questionnote');
$this->adapt_inputs();
} }
/** /**
......
...@@ -37,7 +37,7 @@ class qtype_stack_renderer extends qtype_renderer { ...@@ -37,7 +37,7 @@ class qtype_stack_renderer extends qtype_renderer {
$response = $qa->get_last_qt_data(); $response = $qa->get_last_qt_data();
$questiontext = $qa->get_last_qt_var('_questiontext'); $questiontext = $question->questiontextinstantiated;
$questiontext = $question->format_text( $questiontext = $question->format_text(
stack_maths::process_display_castext($questiontext), stack_maths::process_display_castext($questiontext),
$question->questiontextformat, $question->questiontextformat,
...@@ -164,7 +164,7 @@ class qtype_stack_renderer extends qtype_renderer { ...@@ -164,7 +164,7 @@ class qtype_stack_renderer extends qtype_renderer {
protected function stack_specific_feedback_errors_only(question_attempt $qa) { protected function stack_specific_feedback_errors_only(question_attempt $qa) {
$question = $qa->get_question(); $question = $qa->get_question();
$response = $qa->get_last_qt_data(); $response = $qa->get_last_qt_data();
$feedbacktext = $qa->get_last_qt_var('_feedback'); $feedbacktext = $question->specificfeedbackinstantiated;
if (!$feedbacktext) { if (!$feedbacktext) {
return ''; return '';
} }
...@@ -204,7 +204,7 @@ class qtype_stack_renderer extends qtype_renderer { ...@@ -204,7 +204,7 @@ class qtype_stack_renderer extends qtype_renderer {
$question = $qa->get_question(); $question = $qa->get_question();
$response = $qa->get_last_qt_data(); $response = $qa->get_last_qt_data();
$feedbacktext = $qa->get_last_qt_var('_feedback'); $feedbacktext = $question->specificfeedbackinstantiated;
if (!$feedbacktext) { if (!$feedbacktext) {
return ''; return '';
} }
......
...@@ -50,7 +50,6 @@ $questionfields = array('questiontext', 'generalfeedback'); ...@@ -50,7 +50,6 @@ $questionfields = array('questiontext', 'generalfeedback');
$qtypestackfields = array('specificfeedback', 'prtcorrect', 'prtpartiallycorrect', 'prtincorrect', 'questionnote'); $qtypestackfields = array('specificfeedback', 'prtcorrect', 'prtpartiallycorrect', 'prtincorrect', 'questionnote');
$prtnodefields = array('truefeedback', 'falsefeedback'); $prtnodefields = array('truefeedback', 'falsefeedback');
$qafields = array('questionsummary', 'rightanswer', 'responsesummary'); $qafields = array('questionsummary', 'rightanswer', 'responsesummary');
$stepdatanames = "'_questiontext', '_feedback', '_questionnote'";
$anychanges = false; $anychanges = false;
// Display. // Display.
...@@ -128,23 +127,6 @@ foreach ($categories as $key => $category) { ...@@ -128,23 +127,6 @@ foreach ($categories as $key => $category) {
} }
$anychanges = $anychanges || $changes; $anychanges = $anychanges || $changes;
} }
// Fields in the question_attempt_step_data table.
$attemptdata = $DB->get_records_sql("
SELECT qasd.*
FROM {question_attempt_step_data} qasd
JOIN {question_attempt_steps} qas ON qasd.attemptstepid = qas.id
JOIN {question_attempts} qa ON qa.id = qas.questionattemptid
WHERE qa.questionid = :questionid
AND qasd.name IN ({$stepdatanames})
", array('questionid' => $question->id));
foreach ($attemptdata as $data) {
$changes = $fixer->fix_question_field($data, 'value');
if ($changes && $confirm) {
$DB->update_record('question_attempt_step_data', $data);
}
$anychanges = $anychanges || $changes;
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment