[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * This file defines the quiz responses table for showing last try at question. 19 * 20 * @package quiz_responses 21 * @copyright 2008 Jean-Michel Vedrine 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_table.php'); 29 30 31 /** 32 * This is a table subclass for displaying the quiz responses report. 33 * 34 * @copyright 2008 Jean-Michel Vedrine 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class quiz_last_responses_table extends quiz_attempts_report_table { 38 39 /** 40 * Constructor 41 * @param object $quiz 42 * @param context $context 43 * @param string $qmsubselect 44 * @param quiz_responses_options $options 45 * @param array $groupstudents 46 * @param array $students 47 * @param array $questions 48 * @param moodle_url $reporturl 49 */ 50 public function __construct($quiz, $context, $qmsubselect, quiz_responses_options $options, 51 $groupstudents, $students, $questions, $reporturl) { 52 parent::__construct('mod-quiz-report-responses-report', $quiz, $context, 53 $qmsubselect, $options, $groupstudents, $students, $questions, $reporturl); 54 } 55 56 public function build_table() { 57 if (!$this->rawdata) { 58 return; 59 } 60 61 $this->strtimeformat = str_replace(',', ' ', get_string('strftimedatetime')); 62 parent::build_table(); 63 } 64 65 public function col_sumgrades($attempt) { 66 if ($attempt->state != quiz_attempt::FINISHED) { 67 return '-'; 68 } 69 70 $grade = quiz_rescale_grade($attempt->sumgrades, $this->quiz); 71 if ($this->is_downloading()) { 72 return $grade; 73 } 74 75 $gradehtml = '<a href="review.php?q=' . $this->quiz->id . '&attempt=' . 76 $attempt->attempt . '">' . $grade . '</a>'; 77 return $gradehtml; 78 } 79 80 public function data_col($slot, $field, $attempt) { 81 if ($attempt->usageid == 0) { 82 return '-'; 83 } 84 85 $value = $this->field_from_extra_data($attempt, $slot, $field); 86 87 if (is_null($value)) { 88 $summary = '-'; 89 } else { 90 $summary = trim($value); 91 } 92 93 if ($this->is_downloading() && $this->is_downloading() != 'xhtml') { 94 return $summary; 95 } 96 $summary = s($summary); 97 98 if ($this->is_downloading() || $field != 'responsesummary') { 99 return $summary; 100 } 101 102 return $this->make_review_link($summary, $attempt, $slot); 103 } 104 105 /** 106 * Column text from the extra data loaded in load_extra_data(), before html formatting etc. 107 * 108 * @param object $attempt 109 * @param int $slot 110 * @param string $field 111 * @return string 112 */ 113 protected function field_from_extra_data($attempt, $slot, $field) { 114 if (!isset($this->lateststeps[$attempt->usageid][$slot])) { 115 return '-'; 116 } 117 $stepdata = $this->lateststeps[$attempt->usageid][$slot]; 118 119 if (property_exists($stepdata, $field . 'full')) { 120 $value = $stepdata->{$field . 'full'}; 121 } else { 122 $value = $stepdata->$field; 123 } 124 return $value; 125 } 126 127 public function other_cols($colname, $attempt) { 128 if (preg_match('/^question(\d+)$/', $colname, $matches)) { 129 return $this->data_col($matches[1], 'questionsummary', $attempt); 130 131 } else if (preg_match('/^response(\d+)$/', $colname, $matches)) { 132 return $this->data_col($matches[1], 'responsesummary', $attempt); 133 134 } else if (preg_match('/^right(\d+)$/', $colname, $matches)) { 135 return $this->data_col($matches[1], 'rightanswer', $attempt); 136 137 } else { 138 return null; 139 } 140 } 141 142 protected function requires_extra_data() { 143 return true; 144 } 145 146 protected function is_latest_step_column($column) { 147 if (preg_match('/^(?:question|response|right)([0-9]+)/', $column, $matches)) { 148 return $matches[1]; 149 } 150 return false; 151 } 152 153 /** 154 * Get any fields that might be needed when sorting on date for a particular slot. 155 * @param int $slot the slot for the column we want. 156 * @param string $alias the table alias for latest state information relating to that slot. 157 * @return string sql fragment to alias fields. 158 */ 159 protected function get_required_latest_state_fields($slot, $alias) { 160 global $DB; 161 $sortableresponse = $DB->sql_order_by_text("{$alias}.questionsummary"); 162 if ($sortableresponse === "{$alias}.questionsummary") { 163 // Can just order by text columns. No complexity needed. 164 return "{$alias}.questionsummary AS question{$slot}, 165 {$alias}.rightanswer AS right{$slot}, 166 {$alias}.responsesummary AS response{$slot}"; 167 } else { 168 // Work-around required. 169 return $DB->sql_order_by_text("{$alias}.questionsummary") . " AS question{$slot}, 170 {$alias}.questionsummary AS question{$slot}full, 171 " . $DB->sql_order_by_text("{$alias}.rightanswer") . " AS right{$slot}, 172 {$alias}.rightanswer AS right{$slot}full, 173 " . $DB->sql_order_by_text("{$alias}.responsesummary") . " AS response{$slot}, 174 {$alias}.responsesummary AS response{$slot}full"; 175 } 176 } 177 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |