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

Standard PRT feedback should be treated as CAS text. (Issue #47)

You can use any variables from the question. You cannot use the students
response or the variables from the PRTs.
parent 6b664588
Branches
Tags
No related merge requests found
...@@ -118,15 +118,35 @@ class qtype_stack_question extends question_graded_automatically_with_countback ...@@ -118,15 +118,35 @@ class qtype_stack_question extends question_graded_automatically_with_countback
protected $questionnoteinstantiated; protected $questionnoteinstantiated;
/** /**
* @var array stack_cas_session STACK specific: session of variables. * @var string instantiated version of questiontext.
* Initialised in start_attempt / apply_attempt_state.
*/ */
public $questiontextinstantiated; public $questiontextinstantiated;
/** /**
* @var array stack_cas_session STACK specific: session of variables. * @var string instantiated version of specificfeedback.
* Initialised in start_attempt / apply_attempt_state.
*/ */
public $specificfeedbackinstantiated; public $specificfeedbackinstantiated;
/**
* @var string instantiated version of prtcorrect.
* Initialised in start_attempt / apply_attempt_state.
*/
public $prtcorrectinstantiated;
/**
* @var string instantiated version of prtpartiallycorrect.
* Initialised in start_attempt / apply_attempt_state.
*/
public $prtpartiallycorrectinstantiated;
/**
* @var string instantiated version of prtincorrect.
* Initialised in start_attempt / apply_attempt_state.
*/
public $prtincorrectinstantiated;
/** /**
* 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
...@@ -259,25 +279,18 @@ class qtype_stack_question extends question_graded_automatically_with_countback ...@@ -259,25 +279,18 @@ class qtype_stack_question extends question_graded_automatically_with_countback
$session_length = count($session->get_session()); $session_length = count($session->get_session());
// 3. CAS bits inside the question text. // 3. CAS bits inside the question text.
$questiontext = new stack_cas_text($this->questiontext, $session, $this->seed, 't', false, true); $questiontext = $this->prepare_cas_text($this->questiontext, $session);
if ($questiontext->get_errors()) {
throw new stack_exception('qtype_stack_question : Error in the question text: ' .
$questiontext->get_errors());
}
// 4. CAS bits inside the specific feedback. // 4. CAS bits inside the specific feedback.
$feedbacktext = new stack_cas_text($this->specificfeedback, $session, $this->seed, 't', false, true); $feedbacktext = $this->prepare_cas_text($this->specificfeedback, $session);
if ($questiontext->get_errors()) {
throw new stack_exception('qtype_stack_question : Error in the feedback text: ' .
$feedbacktext->get_errors());
}
// 5. CAS bits inside the question note. // 5. CAS bits inside the question note.
$notetext = new stack_cas_text($this->questionnote, $session, $this->seed, 't', false, true); $notetext = $this->prepare_cas_text($this->questionnote, $session);
if ($questiontext->get_errors()) {
throw new stack_exception('qtype_stack_question : Error in the question note: ' . // 6. The standard PRT feedback.
$notetext->get_errors()); $prtcorrect = $this->prepare_cas_text($this->prtcorrect, $session);
} $prtpartiallycorrect = $this->prepare_cas_text($this->prtpartiallycorrect, $session);
$prtincorrect = $this->prepare_cas_text($this->prtincorrect, $session);
// Now instantiate the session. // Now instantiate the session.
$session->instantiate(); $session->instantiate();
...@@ -293,6 +306,9 @@ class qtype_stack_question extends question_graded_automatically_with_countback ...@@ -293,6 +306,9 @@ class qtype_stack_question extends question_graded_automatically_with_countback
$this->questiontextinstantiated = $questiontext->get_display_castext(); $this->questiontextinstantiated = $questiontext->get_display_castext();
$this->specificfeedbackinstantiated = $feedbacktext->get_display_castext(); $this->specificfeedbackinstantiated = $feedbacktext->get_display_castext();
$this->questionnoteinstantiated = $notetext->get_display_castext(); $this->questionnoteinstantiated = $notetext->get_display_castext();
$this->prtcorrectinstantiated = $prtcorrect->get_display_castext();
$this->prtpartiallycorrectinstantiated = $prtpartiallycorrect->get_display_castext();
$this->prtincorrectinstantiated = $prtincorrect->get_display_castext();
$session->prune_session($session_length); $session->prune_session($session_length);
$this->session = $session; $this->session = $session;
...@@ -300,6 +316,21 @@ class qtype_stack_question extends question_graded_automatically_with_countback ...@@ -300,6 +316,21 @@ class qtype_stack_question extends question_graded_automatically_with_countback
$this->adapt_inputs(); $this->adapt_inputs();
} }
/**
* Helper method used by initialise_question_from_seed.
* @param string $text a textual part of the question that is CAS text.
* @param stack_cas_session $session the question's CAS session.
* @return stack_cas_text the CAS text version of $text.
*/
protected function prepare_cas_text($text, $session) {
$castext = new stack_cas_text($text, $session, $this->seed, 't', false, true);
if ($castext->get_errors()) {
throw new stack_exception('qtype_stack_question : Error part of the question: ' .
$castext->get_errors());
}
return $castext;
}
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');
$this->initialise_question_from_seed(); $this->initialise_question_from_seed();
......
...@@ -378,7 +378,7 @@ class qtype_stack_renderer extends qtype_renderer { ...@@ -378,7 +378,7 @@ class qtype_stack_renderer extends qtype_renderer {
$state = question_state::graded_state_for_fraction($result->score); $state = question_state::graded_state_for_fraction($result->score);
$class = $state->get_feedback_class(); $class = $state->get_feedback_class();
$field = 'prt' . $class; $field = 'prt' . $class . 'instantiated';
$format = 'prt' . $class . 'format'; $format = 'prt' . $class . 'format';
if ($question->$field) { if ($question->$field) {
return html_writer::tag('div', $question->format_text( return html_writer::tag('div', $question->format_text(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment