Skip to content

Commit 7ad73bf

Browse files
committed
Bug fix: the downloadquizattempts.php script was broken, and had never worked on pgsql databases either. It does now.
1 parent ca0d93f commit 7ad73bf

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

downloadquizattempts.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use context_course;
3434
use html_writer;
3535
use moodle_url;
36+
use html_table;
3637

3738
require_once(__DIR__ . '/../../../config.php');
3839
require_once($CFG->libdir . '/questionlib.php');

getallattempts.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public function add_data($row) {
5252
}
5353
}
5454

55+
// A version of Moodle's table_sql that handles the screw up with formatting
56+
// of code (converting it all to HTML, stripping newlines etc - stupid, stupid, stupid -
57+
// and which formats the datetime field (a Unix timestamp) in a DB independent manner.
5558
class UnscrewedSqlTable extends table_sql {
5659
/**
5760
* Get, and optionally set, the export class.
@@ -75,6 +78,22 @@ function export_class_instance($exportclass = null) {
7578
}
7679
return $this->exportclass;
7780
}
81+
82+
/**
83+
* Format Unix timestamp into readable date/time
84+
* This method will be automatically called for the 'datetime' column
85+
*
86+
* @param object $row The row of data
87+
* @return string Formatted date
88+
*/
89+
public function col_datetime($row) {
90+
if (empty($row->datetime)) {
91+
return '-';
92+
}
93+
94+
// Use Moodle's built-in time formatting function
95+
return userdate($row->datetime);
96+
}
7897
//phpcs:enable
7998
}
8099

@@ -125,7 +144,7 @@ function export_class_instance($exportclass = null) {
125144
quest.name as qname,
126145
slot.maxmark as mark,
127146
qattsteps.timecreated as timestamp,
128-
FROM_UNIXTIME(qattsteps.timecreated,'%Y/%m/%d %H:%i:%s') as datetime,
147+
qattsteps.timecreated as datetime,
129148
qattsteps.fraction,
130149
qattsteps.state,
131150
qasd.attemptstepid,

0 commit comments

Comments
 (0)