MDL-67002 quiz reports: fix sorting on Oracle in the responses report

This commit is contained in:
Tim Hunt 2019-10-23 22:27:05 +01:00
parent 94fdac9117
commit 45722f4188
2 changed files with 9 additions and 23 deletions

View File

@ -385,8 +385,13 @@ abstract class quiz_attempts_report_table extends table_sql {
/**
* Get any fields that might be needed when sorting on date for a particular slot.
*
* Note: these values are only used for sorting. The values displayed are taken
* from $this->lateststeps loaded in load_extra_data().
*
* @param int $slot the slot for the column we want.
* @param string $alias the table alias for latest state information relating to that slot.
* @return string definitions of extra fields to add to the SELECT list of the query.
*/
protected function get_required_latest_state_fields($slot, $alias) {
return '';

View File

@ -114,14 +114,7 @@ class quiz_last_responses_table extends quiz_attempts_report_table {
if (!isset($this->lateststeps[$attempt->usageid][$slot])) {
return '-';
}
$stepdata = $this->lateststeps[$attempt->usageid][$slot];
if (property_exists($stepdata, $field . 'full')) {
$value = $stepdata->{$field . 'full'};
} else {
$value = $stepdata->$field;
}
return $value;
return $this->lateststeps[$attempt->usageid][$slot]->$field;
}
public function other_cols($colname, $attempt) {
@ -158,20 +151,8 @@ class quiz_last_responses_table extends quiz_attempts_report_table {
*/
protected function get_required_latest_state_fields($slot, $alias) {
global $DB;
$sortableresponse = $DB->sql_order_by_text("{$alias}.questionsummary");
if ($sortableresponse === "{$alias}.questionsummary") {
// Can just order by text columns. No complexity needed.
return "{$alias}.questionsummary AS question{$slot},
{$alias}.rightanswer AS right{$slot},
{$alias}.responsesummary AS response{$slot}";
} else {
// Work-around required.
return $DB->sql_order_by_text("{$alias}.questionsummary") . " AS question{$slot},
{$alias}.questionsummary AS question{$slot}full,
" . $DB->sql_order_by_text("{$alias}.rightanswer") . " AS right{$slot},
{$alias}.rightanswer AS right{$slot}full,
" . $DB->sql_order_by_text("{$alias}.responsesummary") . " AS response{$slot},
{$alias}.responsesummary AS response{$slot}full";
}
return $DB->sql_order_by_text("{$alias}.questionsummary") . " AS question{$slot},
" . $DB->sql_order_by_text("{$alias}.rightanswer") . " AS right{$slot},
" . $DB->sql_order_by_text("{$alias}.responsesummary") . " AS response{$slot}";
}
}