. /** * This file defines the quiz responses report class. * * @package quiz * @subpackage responses * @copyright 2008 Jean-Michel Vedrine * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); /** * This is a table subclass for displaying the quiz responses report. * * @copyright 2008 Jean-Michel Vedrine * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class quiz_report_responses_table extends quiz_attempt_report_table { public function __construct($quiz, $context, $qmsubselect, $qmfilter, $attemptsmode, $groupstudents, $students, $questions, $includecheckboxes, $reporturl, $displayoptions) { parent::__construct('mod-quiz-report-responses-report', $quiz, $context, $qmsubselect, $qmfilter, $attemptsmode, $groupstudents, $students, $questions, $includecheckboxes, $reporturl, $displayoptions); } public function build_table() { if ($this->rawdata) { $this->strtimeformat = str_replace(',', ' ', get_string('strftimedatetime')); parent::build_table(); } } public function col_sumgrades($attempt) { if (!$attempt->timefinish) { return '-'; } $grade = quiz_rescale_grade($attempt->sumgrades, $this->quiz); if ($this->is_downloading()) { return $grade; } $gradehtml = '' . $grade . ''; return $gradehtml; } public function data_col($slot, $field, $attempt) { global $CFG; if ($attempt->usageid == 0) { return '-'; } $question = $this->questions[$slot]; if (!isset($this->lateststeps[$attempt->usageid][$slot])) { return '-'; } $stepdata = $this->lateststeps[$attempt->usageid][$slot]; if (is_null($stepdata->$field)) { $summary = '-'; } else { $summary = trim($stepdata->$field); } if ($this->is_downloading() || $field != 'responsesummary') { return $summary; } return $this->make_review_link($summary, $attempt, $slot); } public function other_cols($colname, $attempt) { if (preg_match('/^question(\d+)$/', $colname, $matches)) { return $this->data_col($matches[1], 'questionsummary', $attempt); } else if (preg_match('/^response(\d+)$/', $colname, $matches)) { return $this->data_col($matches[1], 'responsesummary', $attempt); } else if (preg_match('/^right(\d+)$/', $colname, $matches)) { return $this->data_col($matches[1], 'rightanswer', $attempt); } else { return null; } } protected function requires_latest_steps_loaded() { return true; } protected function is_latest_step_column($column) { if (preg_match('/^(?:question|response|right)([0-9]+)/', $column, $matches)) { return $matches[1]; } return false; } /** * Get any fields that might be needed when sorting on date for a particular slot. * @param int $slot the slot for the column we want. * @param string $alias the table alias for latest state information relating to that slot. */ protected function get_required_latest_state_fields($slot, $alias) { return "$alias.questionsummary AS question$slot, $alias.rightanswer AS right$slot, $alias.responsesummary AS response$slot"; } }