mirror of
https://github.com/moodle/moodle.git
synced 2025-02-13 12:34:28 +01:00
Merge branch 'MDL-31121-master' of git://github.com/sammarshallou/moodle
This commit is contained in:
commit
8300d8894c
@ -82,6 +82,19 @@ $string['printheadingexplain'] = 'Display resource name above content? Some disp
|
||||
$string['printintro'] = 'Display resource description';
|
||||
$string['printintroexplain'] = 'Display resource description bellow content? Some display types may not display description even if enabled.';
|
||||
$string['resourcecontent'] = 'Files and subfolders';
|
||||
$string['resourcedetails_sizetype'] = '{$a->size} {$a->type}';
|
||||
$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['showsize'] = 'Show size';
|
||||
$string['showsize_help'] = 'Displays the file size, such as \'3.1 MB\', beside links to the file.
|
||||
|
||||
If there are multiple files in this resource, the total size of all files is displayed.';
|
||||
$string['showsize_desc'] = 'Display file size on course page?';
|
||||
$string['showtype'] = 'Show type';
|
||||
$string['showtype_desc'] = 'Display file type (e.g. \'Word document\') on course page?';
|
||||
$string['showtype_help'] = 'Displays the type of the file, such as \'Word document\', beside links to the file.
|
||||
|
||||
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.';
|
||||
|
@ -90,16 +90,8 @@ function resource_add_instance($data, $mform) {
|
||||
require_once("$CFG->libdir/resourcelib.php");
|
||||
$cmid = $data->coursemodule;
|
||||
$data->timemodified = time();
|
||||
$displayoptions = array();
|
||||
if ($data->display == RESOURCELIB_DISPLAY_POPUP) {
|
||||
$displayoptions['popupwidth'] = $data->popupwidth;
|
||||
$displayoptions['popupheight'] = $data->popupheight;
|
||||
}
|
||||
if (in_array($data->display, array(RESOURCELIB_DISPLAY_AUTO, RESOURCELIB_DISPLAY_EMBED, RESOURCELIB_DISPLAY_FRAME))) {
|
||||
$displayoptions['printheading'] = (int)!empty($data->printheading);
|
||||
$displayoptions['printintro'] = (int)!empty($data->printintro);
|
||||
}
|
||||
$data->displayoptions = serialize($displayoptions);
|
||||
|
||||
resource_set_display_options($data);
|
||||
|
||||
$data->id = $DB->insert_record('resource', $data);
|
||||
|
||||
@ -122,6 +114,21 @@ function resource_update_instance($data, $mform) {
|
||||
$data->id = $data->instance;
|
||||
$data->revision++;
|
||||
|
||||
resource_set_display_options($data);
|
||||
|
||||
$DB->update_record('resource', $data);
|
||||
resource_set_mainfile($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates display options based on form input.
|
||||
*
|
||||
* Shared code used by resource_add_instance and resource_update_instance.
|
||||
*
|
||||
* @param object $data Data object
|
||||
*/
|
||||
function resource_set_display_options($data) {
|
||||
$displayoptions = array();
|
||||
if ($data->display == RESOURCELIB_DISPLAY_POPUP) {
|
||||
$displayoptions['popupwidth'] = $data->popupwidth;
|
||||
@ -131,11 +138,13 @@ function resource_update_instance($data, $mform) {
|
||||
$displayoptions['printheading'] = (int)!empty($data->printheading);
|
||||
$displayoptions['printintro'] = (int)!empty($data->printintro);
|
||||
}
|
||||
if (!empty($data->showsize)) {
|
||||
$displayoptions['showsize'] = 1;
|
||||
}
|
||||
if (!empty($data->showtype)) {
|
||||
$displayoptions['showtype'] = 1;
|
||||
}
|
||||
$data->displayoptions = serialize($displayoptions);
|
||||
|
||||
$DB->update_record('resource', $data);
|
||||
resource_set_mainfile($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -302,9 +311,25 @@ function resource_get_coursemodule_info($coursemodule) {
|
||||
$info->onclick = "window.open('$fullurl'); return false;";
|
||||
}
|
||||
|
||||
// If any optional extra details are turned on, store in custom data
|
||||
$info->customdata = resource_get_optional_details($resource, $coursemodule);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when viewing course page. Shows extra details after the link if
|
||||
* enabled.
|
||||
*
|
||||
* @param cm_info $cm Course module information
|
||||
*/
|
||||
function resource_cm_info_view(cm_info $cm) {
|
||||
$details = $cm->get_custom_data();
|
||||
if ($details) {
|
||||
$cm->set_after_link(' ' . html_writer::tag('span', $details,
|
||||
array('class' => 'resourcelinkdetails')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all browsable file areas
|
||||
|
@ -291,6 +291,61 @@ function resource_print_heading($resource, $cm, $course, $ignoresettings=false)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets optional details for a resource, depending on resource settings.
|
||||
*
|
||||
* Result may include the file size and type if those settings are chosen,
|
||||
* or blank if none.
|
||||
*
|
||||
* @param object $resource Resource table row
|
||||
* @param object $cm Course-module table row
|
||||
* @return string Size and type or empty string if show options are not enabled
|
||||
*/
|
||||
function resource_get_optional_details($resource, $cm) {
|
||||
global $DB;
|
||||
|
||||
$details = '';
|
||||
|
||||
$options = empty($resource->displayoptions) ? array() : unserialize($resource->displayoptions);
|
||||
if (!empty($options['showsize']) || !empty($options['showtype'])) {
|
||||
$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)));
|
||||
}
|
||||
if (!empty($options['showtype'])) {
|
||||
// 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
|
||||
$mimetype = $DB->get_field_sql(
|
||||
'SELECT mimetype FROM {files} WHERE contextid=? ORDER BY sortorder DESC',
|
||||
array($context->id), IGNORE_MULTIPLE);
|
||||
// Only show type if it is not unknown
|
||||
if ($mimetype && $mimetype !== 'document/unknown') {
|
||||
$type = get_mimetype_description($mimetype);
|
||||
// There are some known mimetypes which don't have descriptions
|
||||
if ($type === get_string('document/unknown','mimetypes')) {
|
||||
$type = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
} else {
|
||||
// Either size or type is set, but not both, so just append
|
||||
$details = $size . $type;
|
||||
}
|
||||
}
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print resource introduction.
|
||||
* @param object $resource
|
||||
@ -303,10 +358,21 @@ function resource_print_intro($resource, $cm, $course, $ignoresettings=false) {
|
||||
global $OUTPUT;
|
||||
|
||||
$options = empty($resource->displayoptions) ? array() : unserialize($resource->displayoptions);
|
||||
if ($ignoresettings or !empty($options['printintro'])) {
|
||||
if (trim(strip_tags($resource->intro))) {
|
||||
|
||||
$extraintro = resource_get_optional_details($resource, $cm);
|
||||
if ($extraintro) {
|
||||
// Put a paragaph tag around the details
|
||||
$extraintro = html_writer::tag('p', $extraintro, array('class' => 'resourcedetails'));
|
||||
}
|
||||
|
||||
if ($ignoresettings || !empty($options['printintro']) || $extraintro) {
|
||||
$gotintro = trim(strip_tags($resource->intro));
|
||||
if ($gotintro || $extraintro) {
|
||||
echo $OUTPUT->box_start('mod_introbox', 'resourceintro');
|
||||
echo format_module_intro('resource', $resource, $cm->id);
|
||||
if ($gotintro) {
|
||||
echo format_module_intro('resource', $resource, $cm->id);
|
||||
}
|
||||
echo $extraintro;
|
||||
echo $OUTPUT->box_end();
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,15 @@ class mod_resource_mod_form extends moodleform_mod {
|
||||
$mform->addHelpButton('display', 'displayselect', 'resource');
|
||||
}
|
||||
|
||||
$mform->addElement('checkbox', 'showsize', get_string('showsize', 'resource'));
|
||||
$mform->setDefault('showsize', $config->showsize);
|
||||
$mform->setAdvanced('showsize', $config->showsize_adv);
|
||||
$mform->addHelpButton('showsize', 'showsize', 'resource');
|
||||
$mform->addElement('checkbox', 'showtype', get_string('showtype', 'resource'));
|
||||
$mform->setDefault('showtype', $config->showtype);
|
||||
$mform->setAdvanced('showtype', $config->showtype_adv);
|
||||
$mform->addHelpButton('showtype', 'showtype', 'resource');
|
||||
|
||||
if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) {
|
||||
$mform->addElement('text', 'popupwidth', get_string('popupwidth', 'resource'), array('size'=>3));
|
||||
if (count($options) > 1) {
|
||||
@ -175,6 +184,18 @@ class mod_resource_mod_form extends moodleform_mod {
|
||||
if (!empty($displayoptions['popupheight'])) {
|
||||
$default_values['popupheight'] = $displayoptions['popupheight'];
|
||||
}
|
||||
if (!empty($displayoptions['showsize'])) {
|
||||
$default_values['showsize'] = $displayoptions['showsize'];
|
||||
} else {
|
||||
// Must set explicitly to 0 here otherwise it will use system
|
||||
// default which may be 1.
|
||||
$default_values['showsize'] = 0;
|
||||
}
|
||||
if (!empty($displayoptions['showtype'])) {
|
||||
$default_values['showtype'] = $displayoptions['showtype'];
|
||||
} else {
|
||||
$default_values['showtype'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,12 @@ if ($ADMIN->fulltree) {
|
||||
$settings->add(new admin_setting_configselect_with_advanced('resource/display',
|
||||
get_string('displayselect', 'resource'), get_string('displayselectexplain', 'resource'),
|
||||
array('value'=>RESOURCELIB_DISPLAY_AUTO, 'adv'=>false), $displayoptions));
|
||||
$settings->add(new admin_setting_configcheckbox_with_advanced('resource/showsize',
|
||||
get_string('showsize', 'resource'), get_string('showsize_desc', 'resource'),
|
||||
array('value'=>0, 'adv'=>false)));
|
||||
$settings->add(new admin_setting_configcheckbox_with_advanced('resource/showtype',
|
||||
get_string('showtype', 'resource'), get_string('showtype_desc', 'resource'),
|
||||
array('value'=>0, 'adv'=>false)));
|
||||
$settings->add(new admin_setting_configtext_with_advanced('resource/popupwidth',
|
||||
get_string('popupwidth', 'resource'), get_string('popupwidthexplain', 'resource'),
|
||||
array('value'=>620, 'adv'=>true), PARAM_INT, 7));
|
||||
|
@ -1 +1,5 @@
|
||||
.path-mod-resource .resourcecontent {text-align: center;}
|
||||
|
||||
.path-mod-resource .resourcedetails {font-size: 0.8em; color: #555;}
|
||||
|
||||
.resourcelinkdetails {font-size: 0.8em; color: #555;}
|
||||
|
Loading…
x
Reference in New Issue
Block a user