$params = array('aid' => $state->attempt);
if (isset($question->randomquestionid)) {
$params['qid'] = $question->randomquestionid;
+ $randomprefix = 'random' . $question->id . '-';
} else {
$params['qid'] = $question->id;
+ $randomprefix = '';
}
if ($options->history == 'all') {
$eventtest = 'event > 0';
}
$states = $DB->get_records_select('question_states',
'attempt = :aid AND question = :qid AND ' . $eventtest, $params, 'seq_number ASC');
- if (empty($states)) {
+ if (count($states) <= 1) {
return '';
}
}
foreach ($states as $st) {
+ if ($randomprefix && strpos($st->answer, $randomprefix) === 0) {
+ $st->answer = substr($st->answer, strlen($randomprefix));
+ }
$st->responses[''] = $st->answer;
$this->restore_session_and_responses($question, $st);