mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-77807 files: normalise file entity size/type column fields.
The `filename` field was only used by each to determine whether the file was itself a directory, and it's presence meant that aggregation of each column wasn't working properly.
This commit is contained in:
parent
449a8b0b31
commit
fbb6dc4ca3
@ -109,11 +109,12 @@ class file extends base {
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_INTEGER)
|
||||
->add_fields("{$filesalias}.filesize, {$filesalias}.filename")
|
||||
->add_field("{$filesalias}.filesize")
|
||||
->add_field("CASE WHEN {$filesalias}.filename = '.' THEN 1 ELSE 0 END", 'directory')
|
||||
->set_is_sortable(true)
|
||||
->add_callback(static function($filesize, stdClass $fileinfo): string {
|
||||
// Absent file size and/or directory should not return output.
|
||||
if ($fileinfo->filesize === null || $fileinfo->filename === '.') {
|
||||
if ($fileinfo->filesize === null || $fileinfo->directory) {
|
||||
return '';
|
||||
}
|
||||
return display_size($fileinfo->filesize);
|
||||
@ -138,20 +139,21 @@ class file extends base {
|
||||
))
|
||||
->add_joins($this->get_joins())
|
||||
->set_type(column::TYPE_TEXT)
|
||||
->add_fields("{$filesalias}.mimetype, {$filesalias}.filename")
|
||||
->add_field("{$filesalias}.mimetype")
|
||||
->add_field("CASE WHEN {$filesalias}.filename = '.' THEN 1 ELSE 0 END", 'directory')
|
||||
->set_is_sortable(true)
|
||||
->add_callback(static function($mimetype, stdClass $fileinfo): string {
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/filelib.php");
|
||||
|
||||
// Absent mime type and/or directory has pre-determined output.
|
||||
if ($fileinfo->filename === '.') {
|
||||
return get_string('directory');
|
||||
} else if ($fileinfo->mimetype === null) {
|
||||
if ($fileinfo->mimetype === null && !$fileinfo->directory) {
|
||||
return '';
|
||||
} else if ($fileinfo->directory) {
|
||||
return get_string('directory');
|
||||
}
|
||||
|
||||
return get_mimetype_description($fileinfo, true);
|
||||
return get_mimetype_description($fileinfo->mimetype);
|
||||
});
|
||||
|
||||
// Author.
|
||||
|
Loading…
x
Reference in New Issue
Block a user