From 5c86dc7c72022b1af53a71c2c19ebf88b6262036 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 19 Nov 2009 19:03:55 +0000 Subject: [PATCH] =?utf8?q?question=20history:=20MDL-20776=20state=20histor?= =?utf8?q?y=20was=20not=20shown=20for=20random=20questions=20I=20took=20th?= =?utf8?q?e=20opportunity=20to=20clean=20up=20the=20code=20that=20generate?= =?utf8?q?s=20the=20history.=20Thanks=20to=20G=E1bor=20Katona=20for=20help?= =?utf8?q?ing=20to=20find=20the=20problem.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- question/type/questiontype.php | 133 ++++++++++++++++----------------- 1 file changed, 66 insertions(+), 67 deletions(-) diff --git a/question/type/questiontype.php b/question/type/questiontype.php index d803a97e90..fe277f44b5 100644 --- a/question/type/questiontype.php +++ b/question/type/questiontype.php @@ -1079,81 +1079,80 @@ class default_questiontype { */ function history($question, $state, $number, $cmoptions, $options) { global $DB, $OUTPUT; - $history = ''; - if(isset($options->history) and $options->history) { - if ($options->history == 'all') { - // show all states - $states = $DB->get_records_select('question_states', "attempt = ? AND question = ? AND event > '0'", array($state->attempt, $question->id), 'seq_number ASC'); + + if (empty($options->history)) { + return ''; + } + + $params = array('aid' => $state->attempt); + if (isset($question->randomquestionid)) { + $params['qid'] = $question->randomquestionid; + } else { + $params['qid'] = $question->id; + } + if ($options->history == 'all') { + $eventtest = 'event > 0'; + } else { + $eventtest = 'event IN (' . QUESTION_EVENTS_GRADED . ')'; + } + $states = $DB->get_records_select('question_states', + 'attempt = :aid AND question = :qid AND ' . $eventtest, $params, 'seq_number ASC'); + if (empty($states)) { + return ''; + } + + $strreviewquestion = get_string('reviewresponse', 'quiz'); + $table = new html_table(); + $table->width = '100%'; + $table->head = array ( + get_string('numberabbr', 'quiz'), + get_string('action', 'quiz'), + get_string('response', 'quiz'), + get_string('time'), + ); + if ($options->scores) { + $table->head[] = get_string('score', 'quiz'); + $table->head[] = get_string('grade', 'quiz'); + } + + foreach ($states as $st) { + $st->responses[''] = $st->answer; + $this->restore_session_and_responses($question, $st); + + if ($state->id == $st->id) { + $link = '' . $st->seq_number . ''; + } else if (isset($options->questionreviewlink)) { + $link = html_link::make("$options->questionreviewlink?state=$st->id&question=$question->id", $st->seq_number); + $link->add_action(new popup_action('click', $link->url, 'reviewquestion', array('height' => 450, 'width' => 650))); + $link->title = $strreviewquestion; + $link = $OUTPUT->link($link); } else { - // show only graded states - $states = $DB->get_records_select('question_states', "attempt = ? AND question = ? AND event IN (".QUESTION_EVENTS_GRADED.")", array($state->attempt, $question->id), 'seq_number ASC'); + $link = $st->seq_number; } - if (count($states) > 1) { - $strreviewquestion = get_string('reviewresponse', 'quiz'); - $table = new html_table(); - $table->width = '100%'; - if ($options->scores) { - $table->head = array ( - get_string('numberabbr', 'quiz'), - get_string('action', 'quiz'), - get_string('response', 'quiz'), - get_string('time'), - get_string('score', 'quiz'), - //get_string('penalty', 'quiz'), - get_string('grade', 'quiz'), - ); - } else { - $table->head = array ( - get_string('numberabbr', 'quiz'), - get_string('action', 'quiz'), - get_string('response', 'quiz'), - get_string('time'), - ); - } - foreach ($states as $st) { - $st->responses[''] = $st->answer; - $this->restore_session_and_responses($question, $st); - $b = ($state->id == $st->id) ? '' : ''; - $be = ($state->id == $st->id) ? '' : ''; - if ($state->id == $st->id) { - $link = ''.$st->seq_number.''; - } else { - if(isset($options->questionreviewlink)) { - $link = html_link::make("$options->questionreviewlink?state=$st->id&question=$question->id", $st->seq_number); - $link->add_action(new popup_action('click', $link->url, 'reviewquestion', array('height' => 450, 'width' => 650))); - $link->title = $strreviewquestion; - $link = $OUTPUT->link($link); + if ($state->id == $st->id) { + $b = ''; + $be = ''; + } else { + $b = ''; + $be = ''; + } - } else { - $link = $st->seq_number; - } - } - if ($options->scores) { - $table->data[] = array ( - $link, - $b.get_string('event'.$st->event, 'quiz').$be, - $b.$this->response_summary($question, $st).$be, - $b.userdate($st->timestamp, get_string('timestr', 'quiz')).$be, - $b.question_format_grade($cmoptions, $st->raw_grade).$be, - $b.question_format_grade($cmoptions, $st->grade).$be - ); - } else { - $table->data[] = array ( - $link, - $b.get_string('event'.$st->event, 'quiz').$be, - $b.$this->response_summary($question, $st).$be, - $b.userdate($st->timestamp, get_string('timestr', 'quiz')).$be, - ); - } - } - $history = $OUTPUT->table($table); + $data = array ( + $link, + $b.get_string('event'.$st->event, 'quiz').$be, + $b.$this->response_summary($question, $st).$be, + $b.userdate($st->timestamp, get_string('timestr', 'quiz')).$be, + ); + if ($options->scores) { + $data[] = $b.question_format_grade($cmoptions, $st->raw_grade).$be; + $data[] = $b.question_format_grade($cmoptions, $st->raw_grade).$be; } + $table->data[] = $data; } - return $history; + return $OUTPUT->table($table); } - /** * Prints the score obtained and maximum score available plus any penalty * information -- 2.39.5