mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'wip-MDL-33550-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
4585e6ac98
18 changed files with 366 additions and 323 deletions
|
@ -295,23 +295,27 @@ function resource_get_optional_details($resource, $cm) {
|
|||
$context = context_module::instance($cm->id);
|
||||
$size = '';
|
||||
$type = '';
|
||||
if (!empty($options['showsize'])) {
|
||||
$size = display_size($DB->get_field_sql(
|
||||
'SELECT SUM(filesize) FROM {files} WHERE contextid=?', array($context->id)));
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false);
|
||||
if (!empty($options['showsize']) && count($files)) {
|
||||
$sizebytes = 0;
|
||||
foreach ($files as $file) {
|
||||
// this will also synchronize the file size for external files if needed
|
||||
$sizebytes += $file->get_filesize();
|
||||
}
|
||||
if ($sizebytes) {
|
||||
$size = display_size($sizebytes);
|
||||
}
|
||||
}
|
||||
if (!empty($options['showtype'])) {
|
||||
if (!empty($options['showtype']) && count($files)) {
|
||||
// For a typical file resource, the sortorder is 1 for the main file
|
||||
// and 0 for all other files. This sort approach is used just in case
|
||||
// there are situations where the file has a different sort order
|
||||
$record = $DB->get_record_sql(
|
||||
'SELECT filename, mimetype FROM {files} WHERE contextid=? ORDER BY sortorder DESC',
|
||||
array($context->id), IGNORE_MULTIPLE);
|
||||
$mainfile = reset($files);
|
||||
$type = get_mimetype_description($mainfile);
|
||||
// Only show type if it is not unknown
|
||||
if ($record) {
|
||||
$type = get_mimetype_description($record);
|
||||
if ($type === get_mimetype_description('document/unknown')) {
|
||||
$type = '';
|
||||
}
|
||||
if ($type === get_mimetype_description('document/unknown')) {
|
||||
$type = '';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue