mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 08:09:47 +02:00
"MDL-23308, bring course files back"
This commit is contained in:
parent
b3dbdce822
commit
e921afa874
6 changed files with 123 additions and 40 deletions
64
files/coursefilesedit.php
Normal file
64
files/coursefilesedit.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
require_once('../config.php');
|
||||||
|
require_once(dirname(__FILE__) . '/coursefilesedit_form.php');
|
||||||
|
require_once($CFG->dirroot . '/repository/lib.php');
|
||||||
|
|
||||||
|
// current context
|
||||||
|
$contextid = required_param('contextid', PARAM_INT);
|
||||||
|
$component = 'course';
|
||||||
|
$filearea = 'legacy';
|
||||||
|
$itemid = 0;
|
||||||
|
|
||||||
|
list($context, $course, $cm) = get_context_info_array($contextid);
|
||||||
|
|
||||||
|
$url = new moodle_url('/files/coursefilesedit.php', array('contextid'=>$contextid));
|
||||||
|
|
||||||
|
require_login($course);
|
||||||
|
require_capability('moodle/course:managefiles', $context);
|
||||||
|
|
||||||
|
$heading = get_string('coursefiles') . ': ' . $course->fullname;
|
||||||
|
$PAGE->set_url($url);
|
||||||
|
$PAGE->set_context($context);
|
||||||
|
$PAGE->set_title($heading);
|
||||||
|
$PAGE->set_heading($heading);
|
||||||
|
$PAGE->set_pagelayout('admin');
|
||||||
|
|
||||||
|
$data = new object();
|
||||||
|
$options = array('subdirs'=>1, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
|
||||||
|
file_prepare_standard_filemanager($data, 'files', $options, $context, $component, $filearea, $itemid);
|
||||||
|
$form = new coursefiles_edit_form(null, array('data'=>$data, 'contextid'=>$contextid));
|
||||||
|
|
||||||
|
$returnurl = new moodle_url('/files/index.php', array('contextid'=>$contextid));
|
||||||
|
|
||||||
|
if ($form->is_cancelled()) {
|
||||||
|
redirect($returnurl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($data = $form->get_data()) {
|
||||||
|
$data = file_postupdate_standard_filemanager($data, 'files', $options, $context, $component, $filearea, $itemid);
|
||||||
|
redirect($returnurl);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $OUTPUT->header();
|
||||||
|
|
||||||
|
echo $OUTPUT->container_start();
|
||||||
|
$form->display();
|
||||||
|
echo $OUTPUT->container_end();
|
||||||
|
|
||||||
|
echo $OUTPUT->footer();
|
30
files/coursefilesedit_form.php
Normal file
30
files/coursefilesedit_form.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
require_once($CFG->libdir.'/formslib.php');
|
||||||
|
|
||||||
|
class coursefiles_edit_form extends moodleform {
|
||||||
|
function definition() {
|
||||||
|
$mform =& $this->_form;
|
||||||
|
$contextid = $this->_customdata['contextid'];
|
||||||
|
$options = array('subdirs'=>1, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
|
||||||
|
$mform->addElement('filemanager', 'files_filemanager', get_string('files'), null, $options);
|
||||||
|
$mform->addElement('hidden', 'contextid', $this->_customdata['contextid']);
|
||||||
|
$this->set_data($this->_customdata['data']);
|
||||||
|
$this->add_action_buttons(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,25 +27,14 @@
|
||||||
require('../config.php');
|
require('../config.php');
|
||||||
|
|
||||||
$contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
|
$contextid = optional_param('contextid', SYSCONTEXTID, PARAM_INT);
|
||||||
$component = optional_param('component', '', PARAM_ALPHAEXT);
|
|
||||||
$filearea = optional_param('filearea', '', PARAM_ALPHAEXT);
|
|
||||||
$itemid = optional_param('itemid', -1, PARAM_INT);
|
|
||||||
$filepath = optional_param('filepath', '', PARAM_PATH);
|
$filepath = optional_param('filepath', '', PARAM_PATH);
|
||||||
$filename = optional_param('filename', '', PARAM_FILE);
|
$filename = optional_param('filename', '', PARAM_FILE);
|
||||||
|
// hard-coded to course legacy area
|
||||||
|
$component = 'course';
|
||||||
|
$filearea = 'legacy';
|
||||||
|
$itemid = 0;
|
||||||
|
|
||||||
$PAGE->set_url('/files/index.php', array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename));
|
$PAGE->set_url('/files/index.php', array('contextid'=>$contextid, 'filepath'=>$filepath, 'filename'=>$filename));
|
||||||
|
|
||||||
if ($component === '') {
|
|
||||||
$component = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($filearea === '') {
|
|
||||||
$filearea = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($itemid < 0) {
|
|
||||||
$itemid = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($filepath === '') {
|
if ($filepath === '') {
|
||||||
$filepath = null;
|
$filepath = null;
|
||||||
|
@ -72,16 +61,9 @@ if ($node = $PAGE->settingsnav->find('coursefiles', navigation_node::TYPE_SETTIN
|
||||||
$PAGE->navbar->add($strfiles);
|
$PAGE->navbar->add($strfiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
$PAGE->set_title("$SITE->shortname: $strfiles");
|
$PAGE->set_title("$course->shortname: $strfiles");
|
||||||
$PAGE->set_heading($SITE->fullname);
|
$PAGE->set_heading($course->fullname);
|
||||||
|
$PAGE->set_pagelayout('course');
|
||||||
if ($context->contextlevel == CONTEXT_MODULE) {
|
|
||||||
$PAGE->set_pagelayout('incourse');
|
|
||||||
} else if ($context->contextlevel == CONTEXT_COURSE) {
|
|
||||||
$PAGE->set_pagelayout('course');
|
|
||||||
} else {
|
|
||||||
$PAGE->set_pagelayout('admin');
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = $PAGE->get_renderer('core', 'files');
|
$output = $PAGE->get_renderer('core', 'files');
|
||||||
|
|
||||||
|
@ -90,6 +72,7 @@ echo $output->box_start();
|
||||||
|
|
||||||
if ($file_info) {
|
if ($file_info) {
|
||||||
$options = array();
|
$options = array();
|
||||||
|
$options['context'] = $context;
|
||||||
//$options['visible_areas'] = array('backup'=>array('section', 'course'), 'course'=>array('legacy'), 'user'=>array('backup'));
|
//$options['visible_areas'] = array('backup'=>array('section', 'course'), 'course'=>array('legacy'), 'user'=>array('backup'));
|
||||||
echo $output->files_tree_viewer($file_info, $options);
|
echo $output->files_tree_viewer($file_info, $options);
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,6 +80,4 @@ if ($file_info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $output->box_end();
|
echo $output->box_end();
|
||||||
|
|
||||||
echo $output->footer();
|
echo $output->footer();
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File manager render
|
* File browser render
|
||||||
*
|
*
|
||||||
* @copyright 2010 Dongsheng Cai
|
* @copyright 2010 Dongsheng Cai
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
@ -46,7 +46,8 @@ class core_files_renderer extends plugin_renderer_base {
|
||||||
|
|
||||||
public function render_files_tree_viewer(files_tree_viewer $tree) {
|
public function render_files_tree_viewer(files_tree_viewer $tree) {
|
||||||
|
|
||||||
$html = '<div>';
|
$html = $this->output->notification(get_string('coursefileswarning'), 'notifyproblem');
|
||||||
|
$html .= '<div class="file-tree-breadcrumb">';
|
||||||
foreach($tree->path as $path) {
|
foreach($tree->path as $path) {
|
||||||
$html .= $path;
|
$html .= $path;
|
||||||
$html .= ' / ';
|
$html .= ' / ';
|
||||||
|
@ -74,6 +75,7 @@ class core_files_renderer extends plugin_renderer_base {
|
||||||
$html .= '</ul>';
|
$html .= '</ul>';
|
||||||
}
|
}
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
$html .= $this->output->single_button(new moodle_url('/files/coursefilesedit.php', array('contextid'=>$tree->context->id)), get_string('coursefilesedit'), 'get');
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +91,7 @@ class core_files_renderer extends plugin_renderer_base {
|
||||||
class files_tree_viewer implements renderable {
|
class files_tree_viewer implements renderable {
|
||||||
public $tree;
|
public $tree;
|
||||||
public $path;
|
public $path;
|
||||||
|
public $context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of moodle_file_tree_viewer class
|
* Constructor of moodle_file_tree_viewer class
|
||||||
|
@ -99,8 +102,9 @@ class files_tree_viewer implements renderable {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
//note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
//note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
$this->options = (array)$options;
|
$this->options = (array)$options;
|
||||||
|
$this->context = $options['context'];
|
||||||
|
|
||||||
if (isset($this->options['visible_areas'])) {
|
if (isset($this->options['visible_areas'])) {
|
||||||
$visible_areas = (array)$this->options['visible_areas'];
|
$visible_areas = (array)$this->options['visible_areas'];
|
||||||
} else {
|
} else {
|
||||||
|
@ -110,18 +114,20 @@ class files_tree_viewer implements renderable {
|
||||||
$this->tree = array();
|
$this->tree = array();
|
||||||
$children = $file_info->get_children();
|
$children = $file_info->get_children();
|
||||||
$parent_info = $file_info->get_parent();
|
$parent_info = $file_info->get_parent();
|
||||||
|
|
||||||
$level = $parent_info;
|
$level = $parent_info;
|
||||||
$this->path = array();
|
$this->path = array();
|
||||||
while ($level) {
|
while ($level) {
|
||||||
$params = $level->get_params();
|
$params = $level->get_params();
|
||||||
$context = get_context_instance_by_id($params['contextid']);
|
$context = get_context_instance_by_id($params['contextid']);
|
||||||
// lock user in course level
|
if ($context->id != $this->context->id) {
|
||||||
if ($context->contextlevel == CONTEXT_COURSECAT or $context->contextlevel == CONTEXT_SYSTEM) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// unset unused parameters
|
||||||
|
unset($params['component']);
|
||||||
|
unset($params['filearea']);
|
||||||
|
unset($params['itemid']);
|
||||||
$url = new moodle_url('/files/index.php', $params);
|
$url = new moodle_url('/files/index.php', $params);
|
||||||
$this->path[] = html_writer::link($url->out(false), $level->get_visible_name());
|
$this->path[] = html_writer::link($url, $level->get_visible_name());
|
||||||
$level = $level->get_parent();
|
$level = $level->get_parent();
|
||||||
}
|
}
|
||||||
$this->path = array_reverse($this->path);
|
$this->path = array_reverse($this->path);
|
||||||
|
@ -132,13 +138,13 @@ class files_tree_viewer implements renderable {
|
||||||
$filesize = $child->get_filesize();
|
$filesize = $child->get_filesize();
|
||||||
$mimetype = $child->get_mimetype();
|
$mimetype = $child->get_mimetype();
|
||||||
$params = $child->get_params();
|
$params = $child->get_params();
|
||||||
$url = new moodle_url('/files/index.php', $params);
|
|
||||||
$fileitem = array(
|
$fileitem = array(
|
||||||
'params' => $params,
|
'params' => $params,
|
||||||
'filename' => $child->get_visible_name(),
|
'filename' => $child->get_visible_name(),
|
||||||
'filedate' => $filedate ? userdate($filedate) : '',
|
'filedate' => $filedate ? userdate($filedate) : '',
|
||||||
'filesize' => $filesize ? display_size($filesize) : ''
|
'filesize' => $filesize ? display_size($filesize) : ''
|
||||||
);
|
);
|
||||||
|
$url = new moodle_url('/files/index.php', $params);
|
||||||
if ($child->is_directory()) {
|
if ($child->is_directory()) {
|
||||||
$fileitem['isdir'] = true;
|
$fileitem['isdir'] = true;
|
||||||
$fileitem['url'] = $url->out(false);
|
$fileitem['url'] = $url->out(false);
|
||||||
|
|
|
@ -293,6 +293,8 @@ $string['coursecreators'] = 'Course creator';
|
||||||
$string['coursecreatorsdescription'] = 'Course creators can create new courses.';
|
$string['coursecreatorsdescription'] = 'Course creators can create new courses.';
|
||||||
$string['coursedeleted'] = 'Deleted course {$a}';
|
$string['coursedeleted'] = 'Deleted course {$a}';
|
||||||
$string['coursefiles'] = 'Course files';
|
$string['coursefiles'] = 'Course files';
|
||||||
|
$string['coursefilesedit'] = 'Edit course files';
|
||||||
|
$string['coursefileswarning'] = 'Course files are deprecated since Moodle 2.0, please use external repositories instead as much as possible.';
|
||||||
$string['courseformatdata'] = 'Course format data';
|
$string['courseformatdata'] = 'Course format data';
|
||||||
$string['courseformats'] = 'Course formats';
|
$string['courseformats'] = 'Course formats';
|
||||||
$string['coursegrades'] = 'Course grades';
|
$string['coursegrades'] = 'Course grades';
|
||||||
|
|
|
@ -2905,9 +2905,9 @@ class settings_navigation extends navigation_node {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manage files
|
// Manage files
|
||||||
if ($course->legacyfiles == 2 and has_capability('moodle/course:managefiles', $coursecontext)) {
|
if (has_capability('moodle/course:managefiles', $coursecontext)) {
|
||||||
// hidden in new courses and courses where legacy files were turned off
|
// hidden in new courses and courses where legacy files were turned off
|
||||||
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id, 'itemid'=>0, 'component' => 'course', 'filearea'=>'legacy'));
|
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id));
|
||||||
$coursenode->add(get_string('courselegacyfiles'), $url, self::TYPE_SETTING, null, 'coursefiles', new pix_icon('i/files', ''));
|
$coursenode->add(get_string('courselegacyfiles'), $url, self::TYPE_SETTING, null, 'coursefiles', new pix_icon('i/files', ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3582,9 +3582,9 @@ class settings_navigation extends navigation_node {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manage files
|
// Manage files
|
||||||
if ($course->legacyfiles == 2 and has_capability('moodle/course:managefiles', $this->context)) {
|
if (has_capability('moodle/course:managefiles', $this->context)) {
|
||||||
//hiden in new installs
|
//hiden in new installs
|
||||||
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id, 'itemid'=>0, 'component' => 'course', 'filearea'=>'legacy'));
|
$url = new moodle_url('/files/index.php', array('contextid'=>$coursecontext->id));
|
||||||
$frontpage->add(get_string('sitelegacyfiles'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/files', ''));
|
$frontpage->add(get_string('sitelegacyfiles'), $url, self::TYPE_SETTING, null, null, new pix_icon('i/files', ''));
|
||||||
}
|
}
|
||||||
return $frontpage;
|
return $frontpage;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue