From 4517b6c8327acdf96c9ad4a4c2b3e16a6fdeaa14 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 1 Nov 2013 17:59:53 +0000 Subject: [PATCH] MDL-40481 quiz responses report needs cols need text_sorting --- lib/tablelib.php | 2 ++ mod/quiz/report/responses/responses_table.php | 29 +++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/tablelib.php b/lib/tablelib.php index 1866e2ba9b5..a4723e05a73 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -218,6 +218,8 @@ class flexible_table { /** * Use text sorting functions for this column (required for text columns with Oracle). + * Be warned that you cannot use this with column aliases. You can only do this + * with real columns. See MDL-40481 for an example. * @param string column name */ function text_sorting($column) { diff --git a/mod/quiz/report/responses/responses_table.php b/mod/quiz/report/responses/responses_table.php index 3c9c7c9f458..8d2a5ac4405 100644 --- a/mod/quiz/report/responses/responses_table.php +++ b/mod/quiz/report/responses/responses_table.php @@ -91,10 +91,16 @@ class quiz_responses_table extends quiz_attempts_report_table { $stepdata = $this->lateststeps[$attempt->usageid][$slot]; - if (is_null($stepdata->$field)) { + if (property_exists($stepdata, $field . 'full')) { + $value = $stepdata->{$field . 'full'}; + } else { + $value = $stepdata->$field; + } + + if (is_null($value)) { $summary = '-'; } else { - $summary = trim($stepdata->$field); + $summary = trim($value); } if ($this->is_downloading() && $this->is_downloading() != 'xhtml') { @@ -141,8 +147,21 @@ class quiz_responses_table extends quiz_attempts_report_table { * @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"; + 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"; + } } }