MDL-37455 Allow mod_folder to display the content inline on course page instead of on separate page
This commit is contained in:
@@ -39,7 +39,7 @@ class backup_folder_activity_structure_step extends backup_activity_structure_st
|
||||
// Define each element separated
|
||||
$folder = new backup_nested_element('folder', array('id'), array(
|
||||
'name', 'intro', 'introformat', 'revision',
|
||||
'timemodified'));
|
||||
'timemodified', 'display'));
|
||||
|
||||
// Build the tree
|
||||
// (nice mono-tree, lol)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="mod/folder/db" VERSION="20120122" COMMENT="XMLDB file for Folder module"
|
||||
<XMLDB PATH="mod/folder/db" VERSION="20130121" COMMENT="XMLDB file for Folder module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -13,6 +13,7 @@
|
||||
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="revision" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="incremented when after each file changes, solves browser caching issues"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="display" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Display type of folder contents - on a separate page or inline"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
|
||||
@@ -62,6 +62,20 @@ function xmldb_folder_upgrade($oldversion) {
|
||||
// Moodle v2.4.0 release upgrade line
|
||||
// Put any upgrade step following this
|
||||
|
||||
if ($oldversion < 2013012100) {
|
||||
|
||||
// Define field display to be added to folder
|
||||
$table = new xmldb_table('folder');
|
||||
$field = new xmldb_field('display', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'timemodified');
|
||||
|
||||
// Conditionally launch add field display
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// folder savepoint reached
|
||||
upgrade_mod_savepoint(true, 2013012100, 'folder');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+8
-3
@@ -31,7 +31,7 @@ require_once("$CFG->dirroot/repository/lib.php");
|
||||
|
||||
$id = required_param('id', PARAM_INT); // Course module ID
|
||||
|
||||
$cm = get_coursemodule_from_id('folder', $id, 0, false, MUST_EXIST);
|
||||
$cm = get_coursemodule_from_id('folder', $id, 0, true, MUST_EXIST);
|
||||
$context = context_module::instance($cm->id, MUST_EXIST);
|
||||
$folder = $DB->get_record('folder', array('id'=>$cm->instance), '*', MUST_EXIST);
|
||||
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
|
||||
@@ -52,14 +52,19 @@ $options = array('subdirs'=>1, 'maxbytes'=>$CFG->maxbytes, 'maxfiles'=>-1, 'acce
|
||||
file_prepare_standard_filemanager($data, 'files', $options, $context, 'mod_folder', 'content', 0);
|
||||
|
||||
$mform = new mod_folder_edit_form(null, array('data'=>$data, 'options'=>$options));
|
||||
if (!empty($folder->display) && $folder->display == FOLDER_DISPLAY_INLINE) {
|
||||
$redirecturl = course_get_url($cm->course, $cm->sectionnum);
|
||||
} else {
|
||||
$redirecturl = new moodle_url('/mod/folder/view.php', array('id' => $cm->id));
|
||||
}
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect(new moodle_url('/mod/folder/view.php', array('id'=>$cm->id)));
|
||||
redirect($redirecturl);
|
||||
|
||||
} else if ($formdata = $mform->get_data()) {
|
||||
$formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'mod_folder', 'content', 0);
|
||||
$DB->set_field('folder', 'revision', $folder->revision+1, array('id'=>$folder->id));
|
||||
redirect(new moodle_url('/mod/folder/view.php', array('id'=>$cm->id)));
|
||||
redirect($redirecturl);
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
@@ -44,3 +44,12 @@ $string['page-mod-folder-x'] = 'Any folder module page';
|
||||
$string['page-mod-folder-view'] = 'Folder module main page';
|
||||
$string['pluginadministration'] = 'Folder administration';
|
||||
$string['pluginname'] = 'Folder';
|
||||
$string['display'] = 'Display folder contents';
|
||||
$string['display_help'] = 'If you choose to display the folder contents on a course page, there '.
|
||||
'will be no link to a separate page and the title will not be displayed. The '.
|
||||
'description will be displayed only if "Display description on course page" '.
|
||||
'is checked.<br />'.
|
||||
'Also note that participants view actions can not be logged in this case.';
|
||||
$string['displaypage'] = 'On a separate page';
|
||||
$string['displayinline'] = 'Inline on a course page';
|
||||
$string['noautocompletioninline'] = 'Automatic completion on viewing of activity can not be selected together with "Display inline" option';
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/** Display folder contents on a separate page */
|
||||
define('FOLDER_DISPLAY_PAGE', 0);
|
||||
/** Display folder contents inline in a course */
|
||||
define('FOLDER_DISPLAY_INLINE', 1);
|
||||
|
||||
/**
|
||||
* List of features supported in Folder module
|
||||
* @param string $feature FEATURE_xx constant for requested feature
|
||||
@@ -406,3 +411,36 @@ function folder_dndupload_handle($uploadinfo) {
|
||||
$DB->delete_records('folder', array('id' => $data->id));
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets dynamic information about a course module
|
||||
*
|
||||
* This function is called from cm_info when displaying the module
|
||||
* mod_folder can be displayed inline on course page and therefore have no course link
|
||||
*
|
||||
* @param cm_info $cm
|
||||
*/
|
||||
function folder_cm_info_dynamic(cm_info $cm) {
|
||||
global $DB;
|
||||
$folder = $DB->get_record('folder', array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
if ($folder->display == FOLDER_DISPLAY_INLINE) {
|
||||
$cm->set_no_view_link();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds information about unread messages, that is only required for the course
|
||||
* view page (and similar), to the course-module object.
|
||||
*
|
||||
* @param cm_info $cm
|
||||
*/
|
||||
function folder_cm_info_view(cm_info $cm) {
|
||||
global $PAGE, $DB;
|
||||
if ($cm->uservisible && has_capability('mod/folder:view', $cm->context)) {
|
||||
$folder = $DB->get_record('folder', array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
if ($folder->display == FOLDER_DISPLAY_INLINE) {
|
||||
$renderer = $PAGE->get_renderer('mod_folder');
|
||||
$cm->set_content($renderer->display_folder($folder));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ class mod_folder_mod_form extends moodleform_mod {
|
||||
//-------------------------------------------------------
|
||||
$mform->addElement('header', 'content', get_string('contentheader', 'folder'));
|
||||
$mform->addElement('filemanager', 'files', get_string('files'), null, array('subdirs'=>1, 'accepted_types'=>'*'));
|
||||
$mform->addElement('select', 'display', get_string('display', 'mod_folder'),
|
||||
array(FOLDER_DISPLAY_PAGE => get_string('displaypage', 'mod_folder'),
|
||||
FOLDER_DISPLAY_INLINE => get_string('displayinline', 'mod_folder')));
|
||||
$mform->addHelpButton('display', 'display', 'mod_folder');
|
||||
$mform->setExpanded('content');
|
||||
|
||||
|
||||
@@ -72,4 +76,20 @@ class mod_folder_mod_form extends moodleform_mod {
|
||||
$default_values['files'] = $draftitemid;
|
||||
}
|
||||
}
|
||||
|
||||
function validation($data, $files) {
|
||||
$errors = parent::validation($data, $files);
|
||||
|
||||
// Completion: Automatic on-view completion can not work together with
|
||||
// "display inline" option
|
||||
if (empty($errors['completion']) &&
|
||||
array_key_exists('completion', $data) &&
|
||||
$data['completion'] == COMPLETION_TRACKING_AUTOMATIC &&
|
||||
!empty($data['completionview']) &&
|
||||
$data['display'] == FOLDER_DISPLAY_INLINE) {
|
||||
$errors['completion'] = get_string('noautocompletioninline', 'mod_folder');
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
|
||||
M.mod_folder = {};
|
||||
|
||||
M.mod_folder.init_tree = function(Y, expand_all) {
|
||||
M.mod_folder.init_tree = function(Y, id, expand_all) {
|
||||
Y.use('yui2-treeview', function(Y) {
|
||||
var tree = new Y.YUI2.widget.TreeView("folder_tree");
|
||||
var tree = new Y.YUI2.widget.TreeView(id);
|
||||
|
||||
tree.subscribe("clickEvent", function(node, event) {
|
||||
// we want normal clicking which redirects to url
|
||||
|
||||
+47
-15
@@ -28,23 +28,57 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class mod_folder_renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Prints file folder tree view
|
||||
* @param object $folder instance
|
||||
* @param object $cm instance
|
||||
* @param object $course
|
||||
* @return void
|
||||
* Returns html to display the content of mod_folder
|
||||
* (Description, folder files and optionally Edit button)
|
||||
*
|
||||
* @param stdClass $folder record from 'folder' table
|
||||
* @return string
|
||||
*/
|
||||
public function folder_tree($folder, $cm, $course) {
|
||||
$this->render(new folder_tree($folder, $cm, $course));
|
||||
public function display_folder(stdClass $folder) {
|
||||
$output = '';
|
||||
$folderinstances = get_fast_modinfo($folder->course)->get_instances_of('folder');
|
||||
if (!isset($folderinstances[$folder->id]) ||
|
||||
!($cm = $folderinstances[$folder->id]) ||
|
||||
!$cm->uservisible ||
|
||||
!($context = context_module::instance($cm->id)) ||
|
||||
!has_capability('mod/folder:view', $context)) {
|
||||
// some error in parameters or module is not visible to the user
|
||||
// don't throw any errors in renderer, just return empty string
|
||||
return $output;
|
||||
}
|
||||
|
||||
if (trim($folder->intro)) {
|
||||
if ($folder->display != FOLDER_DISPLAY_INLINE) {
|
||||
$output .= $this->output->box(format_module_intro('folder', $folder, $cm->id),
|
||||
'generalbox', 'intro');
|
||||
} else if ($cm->showdescription) {
|
||||
// for "display inline" do not filter, filters run at display time.
|
||||
$output .= format_module_intro('folder', $folder, $cm->id, false);
|
||||
}
|
||||
}
|
||||
|
||||
$output .= $this->output->box($this->render(new folder_tree($folder, $cm)),
|
||||
'generalbox foldertree');
|
||||
|
||||
if (has_capability('mod/folder:managefiles', $context)) {
|
||||
$output .= $this->output->container(
|
||||
$this->output->single_button(new moodle_url('/mod/folder/edit.php',
|
||||
array('id' => $cm->id)), get_string('edit')),
|
||||
'mdl-align folder-edit-button');
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function render_folder_tree(folder_tree $tree) {
|
||||
global $PAGE;
|
||||
static $treecounter = 0;
|
||||
|
||||
echo '<div id="folder_tree" class="filemanager">';
|
||||
echo $this->htmllize_tree($tree, array('files' => array(), 'subdirs' => array($tree->dir)));
|
||||
echo '</div>';
|
||||
$this->page->requires->js_init_call('M.mod_folder.init_tree', array(true));
|
||||
$content = '';
|
||||
$id = 'folder_tree'. ($treecounter++);
|
||||
$content .= '<div id="'.$id.'" class="filemanager">';
|
||||
$content .= $this->htmllize_tree($tree, array('files' => array(), 'subdirs' => array($tree->dir)));
|
||||
$content .= '</div>';
|
||||
$this->page->requires->js_init_call('M.mod_folder.init_tree', array($id, true));
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,13 +125,11 @@ class folder_tree implements renderable {
|
||||
public $context;
|
||||
public $folder;
|
||||
public $cm;
|
||||
public $course;
|
||||
public $dir;
|
||||
|
||||
public function __construct($folder, $cm, $course) {
|
||||
public function __construct($folder, $cm) {
|
||||
$this->folder = $folder;
|
||||
$this->cm = $cm;
|
||||
$this->course = $course;
|
||||
|
||||
$this->context = context_module::instance($cm->id);
|
||||
$fs = get_file_storage();
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$module->version = 2012112900; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->version = 2013012100; // The current module version (Date: YYYYMMDDXX)
|
||||
$module->requires = 2012112900; // Requires this Moodle version
|
||||
$module->component = 'mod_folder'; // Full name of the plugin (used for diagnostics)
|
||||
$module->cron = 0;
|
||||
|
||||
+6
-17
@@ -34,10 +34,10 @@ $f = optional_param('f', 0, PARAM_INT); // Folder instance id
|
||||
|
||||
if ($f) { // Two ways to specify the module
|
||||
$folder = $DB->get_record('folder', array('id'=>$f), '*', MUST_EXIST);
|
||||
$cm = get_coursemodule_from_instance('folder', $folder->id, $folder->course, false, MUST_EXIST);
|
||||
$cm = get_coursemodule_from_instance('folder', $folder->id, $folder->course, true, MUST_EXIST);
|
||||
|
||||
} else {
|
||||
$cm = get_coursemodule_from_id('folder', $id, 0, false, MUST_EXIST);
|
||||
$cm = get_coursemodule_from_id('folder', $id, 0, true, MUST_EXIST);
|
||||
$folder = $DB->get_record('folder', array('id'=>$cm->instance), '*', MUST_EXIST);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
|
||||
require_course_login($course, true, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
require_capability('mod/folder:view', $context);
|
||||
if ($folder->display == FOLDER_DISPLAY_INLINE) {
|
||||
redirect(course_get_url($folder->course, $cm->sectionnum));
|
||||
}
|
||||
|
||||
add_to_log($course->id, 'folder', 'view', 'view.php?id='.$cm->id, $folder->id, $cm->id);
|
||||
|
||||
@@ -66,20 +69,6 @@ echo $output->header();
|
||||
|
||||
echo $output->heading(format_string($folder->name), 2);
|
||||
|
||||
if (trim(strip_tags($folder->intro))) {
|
||||
echo $output->box_start('mod_introbox', 'pageintro');
|
||||
echo format_module_intro('folder', $folder, $cm->id);
|
||||
echo $output->box_end();
|
||||
}
|
||||
|
||||
echo $output->box_start('generalbox foldertree');
|
||||
echo $output->folder_tree($folder, $cm, $course);
|
||||
echo $output->box_end();
|
||||
|
||||
if (has_capability('mod/folder:managefiles', $context)) {
|
||||
echo $output->container_start('mdl-align');
|
||||
echo $output->single_button(new moodle_url('/mod/folder/edit.php', array('id'=>$id)), get_string('edit'));
|
||||
echo $output->container_end();
|
||||
}
|
||||
echo $output->display_folder($folder);
|
||||
|
||||
echo $output->footer();
|
||||
|
||||
Reference in New Issue
Block a user