Skip to content

Commit

Permalink
MDL-40863 mod_resource: Add option to show modified date
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhancox authored and danpoltawski committed Oct 23, 2015
1 parent d9b60d6 commit ba8b641
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
10 changes: 10 additions & 0 deletions mod/resource/lang/en/resource.php
Expand Up @@ -63,6 +63,7 @@
$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.
Expand Down Expand Up @@ -91,9 +92,17 @@
$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.
Expand All @@ -106,3 +115,4 @@
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 changes: 4 additions & 0 deletions mod/resource/lib.php
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
34 changes: 26 additions & 8 deletions mod/resource/locallib.php
Expand Up @@ -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)) {
Expand All @@ -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
Expand All @@ -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;
}
}

Expand Down
8 changes: 8 additions & 0 deletions mod/resource/mod_form.php
Expand Up @@ -102,6 +102,9 @@ function definition() {
$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));
Expand Down Expand Up @@ -178,6 +181,11 @@ function data_preprocessing(&$default_values) {
} else {
$default_values['showtype'] = 0;
}
if (!empty($displayoptions['showdate'])) {
$default_values['showdate'] = $displayoptions['showdate'];
} else {
$default_values['showdate'] = 0;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions mod/resource/settings.php
Expand Up @@ -62,6 +62,8 @@
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',
Expand Down
2 changes: 1 addition & 1 deletion mod/resource/version.php
Expand Up @@ -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;

0 comments on commit ba8b641

Please sign in to comment.