MDL-23367 First cut at moving the private files interface under /user. Has a few small bugs, working on them.

This commit is contained in:
Martin Dougiamas 2010-07-19 13:21:16 +00:00
parent bfbca63de3
commit 82af55d7e3
8 changed files with 276 additions and 4 deletions

View File

@ -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 = '';
}

View File

@ -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';

View File

@ -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

57
user/files.php Normal file
View File

@ -0,0 +1,57 @@
<?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/>.
/**
* 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();

65
user/filesedit.php Normal file
View File

@ -0,0 +1,65 @@
<?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/>.
/**
* 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();

43
user/filesedit_form.php Normal file
View File

@ -0,0 +1,43 @@
<?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/>.
/**
* 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);
}
}

View File

@ -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();
});
};

87
user/renderer.php Normal file
View File

@ -0,0 +1,87 @@
<?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/>.
/**
* Print private files tree
*
* @package core_user
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
* @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 = '<div id="'.$htmlid.'">';
$html .= $this->htmllize_tree($tree, $tree->dir);
$html .= '</div>';
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 = '<ul>';
foreach ($dir['subdirs'] as $subdir) {
$image = $this->output->pix_icon("/f/folder", $subdir['dirname'], 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
}
foreach ($dir['files'] as $file) {
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/user/private'.$file->get_filepath().$file->get_filename(), true);
$filename = $file->get_filename();
$icon = substr(mimeinfo("icon", $filename), 0, -4);
$image = $this->output->pix_icon("/f/$icon", $filename, 'moodle', array('class'=>'icon'));
$result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
}
$result .= '</ul>';
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);
}
}