From 82af55d7e3602ac960bf98491b04610ac0175ff2 Mon Sep 17 00:00:00 2001 From: Martin Dougiamas Date: Mon, 19 Jul 2010 13:21:16 +0000 Subject: [PATCH] MDL-23367 First cut at moving the private files interface under /user. Has a few small bugs, working on them. --- blocks/private_files/block_private_files.php | 5 +- lang/en/moodle.php | 2 + lib/navigationlib.php | 4 +- user/files.php | 57 +++++++++++++ user/filesedit.php | 65 +++++++++++++++ user/filesedit_form.php | 43 ++++++++++ user/module.js | 17 ++++ user/renderer.php | 87 ++++++++++++++++++++ 8 files changed, 276 insertions(+), 4 deletions(-) create mode 100644 user/files.php create mode 100644 user/filesedit.php create mode 100644 user/filesedit_form.php create mode 100644 user/renderer.php diff --git a/blocks/private_files/block_private_files.php b/blocks/private_files/block_private_files.php index 855bc674f32..1f2189a9809 100755 --- a/blocks/private_files/block_private_files.php +++ b/blocks/private_files/block_private_files.php @@ -27,11 +27,12 @@ class block_private_files extends block_base { function init() { - $this->title = get_string('areauserpersonal', 'repository'); + $this->title = get_string('myfiles'); } function specialization() { } + function applicable_formats() { return array('all' => true); } @@ -59,7 +60,7 @@ class block_private_files extends block_base { $renderer = $this->page->get_renderer('block_private_files'); $this->content->text = $renderer->private_files_tree(); - $this->content->text .= $OUTPUT->single_button(new moodle_url('/blocks/private_files/edit.php'), get_string('managemyfiles', 'block_private_files'), 'get'); + $this->content->text .= $OUTPUT->single_button(new moodle_url('/user/filesedit.php'), get_string('myfilesmanage'), 'get'); $this->content->footer = ''; } diff --git a/lang/en/moodle.php b/lang/en/moodle.php index f2d7ff7bf94..262c5d03328 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1054,6 +1054,8 @@ $string['msnid'] = 'MSN ID'; $string['mustconfirm'] = 'You need to confirm your login'; $string['mustchangepassword'] = 'The new password must be different than the current one'; $string['mycourses'] = 'My courses'; +$string['myfiles'] = 'My private files'; +$string['myfilesmanage'] = 'Manage my private files'; $string['myhome'] = 'My home'; $string['mymoodledashboard'] = 'My Moodle dashboard'; $string['myprofile'] = 'My profile'; diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 57548f4e1fd..1cbe8b3786a 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1532,8 +1532,8 @@ class global_navigation extends navigation_node { // TODO: Private file capability check if ($iscurrentuser) { - $url = new moodle_url('/blocks/private_files/edit.php'); - $usernode->add(get_string('privatefiles', 'block_private_files'), $url, self::TYPE_SETTING); + $url = new moodle_url('/user/files.php'); + $usernode->add(get_string('myfiles'), $url, self::TYPE_SETTING); } // Add a node to view the users notes if permitted diff --git a/user/files.php b/user/files.php new file mode 100644 index 00000000000..5092d597784 --- /dev/null +++ b/user/files.php @@ -0,0 +1,57 @@ +. + +/** + * Manage files in folder in private area - to be replaced by something better hopefully.... + * + * @package block_private_files + * @copyright 2010 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require('../config.php'); + +require_login(); +if (isguestuser()) { + die(); +} +//TODO: add capability check here! + +$context = get_context_instance(CONTEXT_USER, $USER->id); +$title = get_string('myfiles'); +$struser = get_string('user'); + +$PAGE->set_url('/user/files.php'); +$PAGE->set_context($context); +$PAGE->set_title($title); +$PAGE->set_heading($title); +$PAGE->set_pagelayout('mydashboard'); +$PAGE->set_pagetype('user-files'); + +$module = array('name'=>'core_user', 'fullpath'=>'/user/module.js'); +$PAGE->requires->js_init_call('M.core_user.init_tree', null, false, $module); + +echo $OUTPUT->header(); +echo $OUTPUT->box_start('generalbox'); + +$renderer = $PAGE->get_renderer('core', 'user'); +echo $renderer->user_files_tree(); + +echo $OUTPUT->single_button(new moodle_url('/user/filesedit.php'), get_string('myfilesmanage'), 'get'); + +echo $OUTPUT->box_end(); +echo $OUTPUT->footer(); diff --git a/user/filesedit.php b/user/filesedit.php new file mode 100644 index 00000000000..139c1a3892c --- /dev/null +++ b/user/filesedit.php @@ -0,0 +1,65 @@ +. + +/** + * Manage files in folder in private area. + * + * @package moodle + * @copyright 2010 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require('../config.php'); +require_once("$CFG->dirroot/user/filesedit_form.php"); +require_once("$CFG->dirroot/repository/lib.php"); + +require_login(); +if (isguestuser()) { + die(); +} +//TODO: add capability check here! + +$context = get_context_instance(CONTEXT_USER, $USER->id); +$title = get_string('myfiles'); +$struser = get_string('user'); + +$PAGE->set_url('/user/files.php'); +$PAGE->set_context($context); +$PAGE->set_title($title); +$PAGE->set_heading($title); +$PAGE->set_pagelayout('mydashboard'); +$PAGE->set_pagetype('user-files'); + +$data = new object(); +$options = array('subdirs'=>1, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL); +file_prepare_standard_filemanager($data, 'files', $options, $context, 'user', 'private', 0); + +$mform = new user_filesedit_form(null, array('data'=>$data, 'options'=>$options)); + +if ($mform->is_cancelled()) { + redirect(new moodle_url('/user/files.php')); + +} else if ($formdata = $mform->get_data()) { + $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'user', 'private', 0); + redirect(new moodle_url('/user/files.php')); +} + +echo $OUTPUT->header(); +echo $OUTPUT->box_start('generalbox'); +$mform->display(); +echo $OUTPUT->box_end(); +echo $OUTPUT->footer(); diff --git a/user/filesedit_form.php b/user/filesedit_form.php new file mode 100644 index 00000000000..f26a3b08687 --- /dev/null +++ b/user/filesedit_form.php @@ -0,0 +1,43 @@ +. + +/** + * minimalistic edit form + * + * @package block_private_files + * @copyright 2010 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +require_once("$CFG->libdir/formslib.php"); + +class user_filesedit_form extends moodleform { + function definition() { + $mform = $this->_form; + + $data = $this->_customdata['data']; + $options = $this->_customdata['options']; + + $mform->addElement('filemanager', 'files_filemanager', get_string('files'), null, $options); + + $this->add_action_buttons(true, get_string('savechanges')); + + $this->set_data($data); + } +} diff --git a/user/module.js b/user/module.js index ef956d4c128..01ed0168d0d 100644 --- a/user/module.js +++ b/user/module.js @@ -32,3 +32,20 @@ M.core_user.init_participation = function(Y) { }); }, '#checknone'); }; + +M.core_user.init_tree = function(Y, expand_all, htmlid) { + Y.use('yui2-treeview', function(Y) { + var tree = new YAHOO.widget.TreeView(htmlid); + + tree.subscribe("clickEvent", function(node, event) { + // we want normal clicking which redirects to url + return false; + }); + + if (expand_all) { + tree.expandAll(); + } + + tree.render(); + }); +}; diff --git a/user/renderer.php b/user/renderer.php new file mode 100644 index 00000000000..a7f98429465 --- /dev/null +++ b/user/renderer.php @@ -0,0 +1,87 @@ +. + + +/** + * Print private files tree + * + * @package core_user + * @copyright 2010 Dongsheng Cai + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +defined('MOODLE_INTERNAL') || die(); + +class core_user_renderer extends plugin_renderer_base { + + /** + * Prints user files tree view + * @return string + */ + public function user_files_tree() { + return $this->render(new user_files_tree); + } + + public function render_user_files_tree(user_files_tree $tree) { + $htmlid = 'user_files_tree_'.uniqid(); + $this->page->requires->js_init_call('M.user_core.init_tree', array(false, $htmlid)); + $html = '
'; + $html .= $this->htmllize_tree($tree, $tree->dir); + $html .= '
'; + return $html; + } + + /** + * Internal function - creates htmls structure suitable for YUI tree. + */ + protected function htmllize_tree($tree, $dir) { + global $CFG; + $yuiconfig = array(); + $yuiconfig['type'] = 'html'; + + if (empty($dir['subdirs']) and empty($dir['files'])) { + return ''; + } + $result = ''; + + return $result; + } +} + +class user_files_tree implements renderable { + public $context; + public $dir; + public function __construct() { + global $USER; + $this->context = get_context_instance(CONTEXT_USER, $USER->id); + $fs = get_file_storage(); + $this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0); + } +}