MDL-40863 mod_resource: Add option to show modified date

This commit is contained in:
Andrew Hancox
2015-10-23 11:25:07 +01:00
committed by Dan Poltawski
parent d9b60d6f25
commit ba8b641dce
6 changed files with 51 additions and 9 deletions
+10
View File
@@ -63,6 +63,7 @@ $string['framesize'] = 'Frame height';
$string['legacyfiles'] = 'Migration of old course file';
$string['legacyfilesactive'] = 'Active';
$string['legacyfilesdone'] = 'Finished';
$string['modifieddate'] = 'Modified on {$a}';
$string['modulename'] = 'File';
$string['modulename_help'] = 'The file module enables a teacher to provide a file as a course resource. Where possible, the file will be displayed within the course interface; otherwise students will be prompted to download it. The file may include supporting files, for example an HTML page may have embedded images or Flash objects.
@@ -91,9 +92,17 @@ $string['printintroexplain'] = 'Display resource description below content? Some
$string['resource:addinstance'] = 'Add a new resource';
$string['resourcecontent'] = 'Files and subfolders';
$string['resourcedetails_sizetype'] = '{$a->size} {$a->type}';
$string['resourcedetails_sizedate'] = '{$a->size} {$a->date}';
$string['resourcedetails_typedate'] = '{$a->type} {$a->date}';
$string['resourcedetails_sizetypedate'] = '{$a->size} {$a->type} {$a->date}';
$string['resource:exportresource'] = 'Export resource';
$string['resource:view'] = 'View resource';
$string['selectmainfile'] = 'Please select the main file by clicking the icon next to file name.';
$string['showdate'] = 'Show upload/modified date';
$string['showdate_desc'] = 'Display upload/modified date on course page?';
$string['showdate_help'] = 'Displays the upload/modified date beside links to the file.
If there are multiple files in this resource, the start file upload/modified date is displayed.';
$string['showsize'] = 'Show size';
$string['showsize_help'] = 'Displays the file size, such as \'3.1 MB\', beside links to the file.
@@ -106,3 +115,4 @@ $string['showtype_help'] = 'Displays the type of the file, such as \'Word docume
If there are multiple files in this resource, the start file type is displayed.
If the file type is not known to the system, it will not display.';
$string['uploadeddate'] = 'Uploaded on {$a}';
+4
View File
@@ -154,6 +154,9 @@ function resource_set_display_options($data) {
if (!empty($data->showtype)) {
$displayoptions['showtype'] = 1;
}
if (!empty($data->showdate)) {
$displayoptions['showdate'] = 1;
}
$data->displayoptions = serialize($displayoptions);
}
@@ -471,6 +474,7 @@ function resource_dndupload_handle($uploadinfo) {
$data->printintro = $config->printintro;
$data->showsize = (isset($config->showsize)) ? $config->showsize : 0;
$data->showtype = (isset($config->showtype)) ? $config->showtype : 0;
$data->showdate = (isset($config->showdate)) ? $config->showdate : 0;
$data->filterfiles = $config->filterfiles;
return resource_add_instance($data, null);
+26 -8
View File
@@ -286,10 +286,13 @@ function resource_get_optional_details($resource, $cm) {
$details = '';
$options = empty($resource->displayoptions) ? array() : unserialize($resource->displayoptions);
if (!empty($options['showsize']) || !empty($options['showtype'])) {
if (!empty($options['showsize']) || !empty($options['showtype']) || !empty($options['showdate'])) {
$context = context_module::instance($cm->id);
$size = '';
$type = '';
$date = '';
$langstring = '';
$infodisplayed = 0;
$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)) {
@@ -301,6 +304,8 @@ function resource_get_optional_details($resource, $cm) {
if ($sizebytes) {
$size = display_size($sizebytes);
}
$langstring .= 'size';
$infodisplayed += 1;
}
if (!empty($options['showtype']) && count($files)) {
// For a typical file resource, the sortorder is 1 for the main file
@@ -312,16 +317,29 @@ function resource_get_optional_details($resource, $cm) {
if ($type === get_mimetype_description('document/unknown')) {
$type = '';
}
$langstring .= 'type';
$infodisplayed += 1;
}
if (!empty($options['showdate'])) {
$mainfile = reset($files);
$uploaddate = $mainfile->get_timecreated();
$modifieddate = $mainfile->get_timemodified();
if ($modifieddate > $uploaddate) {
$date = get_string('modifieddate', 'mod_resource', userdate($modifieddate));
} else {
$date = get_string('uploadeddate', 'mod_resource', userdate($uploaddate));
}
$langstring .= 'date';
$infodisplayed += 1;
}
if ($size && $type) {
// Depending on language it may be necessary to show both options in
// different order, so use a lang string
$details = get_string('resourcedetails_sizetype', 'resource',
(object)array('size'=>$size, 'type'=>$type));
if ($infodisplayed > 1) {
$details = get_string("resourcedetails_{$langstring}", 'resource',
(object)array('size' => $size, 'type' => $type, 'date' => $date));
} else {
// Either size or type is set, but not both, so just append
$details = $size . $type;
// Only one of size, type and date is set, so just append.
$details = $size . $type . $date;
}
}
+8
View File
@@ -102,6 +102,9 @@ class mod_resource_mod_form extends moodleform_mod {
$mform->addElement('checkbox', 'showtype', get_string('showtype', 'resource'));
$mform->setDefault('showtype', $config->showtype);
$mform->addHelpButton('showtype', 'showtype', 'resource');
$mform->addElement('checkbox', 'showdate', get_string('showdate', 'resource'));
$mform->setDefault('showdate', $config->showdate);
$mform->addHelpButton('showdate', 'showdate', 'resource');
if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) {
$mform->addElement('text', 'popupwidth', get_string('popupwidth', 'resource'), array('size'=>3));
@@ -178,6 +181,11 @@ class mod_resource_mod_form extends moodleform_mod {
} else {
$default_values['showtype'] = 0;
}
if (!empty($displayoptions['showdate'])) {
$default_values['showdate'] = $displayoptions['showdate'];
} else {
$default_values['showdate'] = 0;
}
}
}
+2
View File
@@ -62,6 +62,8 @@ if ($ADMIN->fulltree) {
get_string('showsize', 'resource'), get_string('showsize_desc', 'resource'), 0));
$settings->add(new admin_setting_configcheckbox('resource/showtype',
get_string('showtype', 'resource'), get_string('showtype_desc', 'resource'), 0));
$settings->add(new admin_setting_configcheckbox('resource/showdate',
get_string('showdate', 'resource'), get_string('showdate_desc', 'resource'), 0));
$settings->add(new admin_setting_configtext('resource/popupwidth',
get_string('popupwidth', 'resource'), get_string('popupwidthexplain', 'resource'), 620, PARAM_INT, 7));
$settings->add(new admin_setting_configtext('resource/popupheight',
+1 -1
View File
@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2015051101; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2015051104; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2015050500; // Requires this Moodle version
$plugin->component = 'mod_resource'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;