diff --git a/blocks/private_files/block_private_files.php b/blocks/private_files/block_private_files.php index cc8432efca3..eab23942787 100755 --- a/blocks/private_files/block_private_files.php +++ b/blocks/private_files/block_private_files.php @@ -24,9 +24,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -require_once($CFG->dirroot. '/repository/lib.php'); - class block_private_files extends block_base { function init() { @@ -56,23 +53,13 @@ class block_private_files extends block_base { $this->content->text = ''; $this->content->footer = ''; if (isloggedin() && !isguestuser()) { // Show the block - - $options = new stdclass; - $options->maxbytes = -1; - $options->maxfiles = -1; - $options->subdirs = true; - $options->accepted_types = '*'; - $options->return_types = FILE_INTERNAL; - $options->context = $PAGE->context; - $options->disable_types = array('user'); - $this->content = new object(); //TODO: add capability check here! - //TODO: add list of available files here - $this->content->text = $OUTPUT->single_button(new moodle_url('/blocks/private_files/edit.php'), get_string('edit'), 'get'); -; + $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('edit'), 'get'); $this->content->footer = ''; } diff --git a/blocks/private_files/module.js b/blocks/private_files/module.js new file mode 100644 index 00000000000..322903d7f0f --- /dev/null +++ b/blocks/private_files/module.js @@ -0,0 +1,41 @@ +// 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 . + +/** + * Init private files treeview + * + * @package block_private_files + * @copyright 2009 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +M.block_private_files = {}; + +M.block_private_files.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/blocks/private_files/renderer.php b/blocks/private_files/renderer.php new file mode 100644 index 00000000000..f3a73201f0f --- /dev/null +++ b/blocks/private_files/renderer.php @@ -0,0 +1,83 @@ +. + + +/** + * Print private files tree + * + * @package block_private_files + * @copyright 2010 Dongsheng Cai + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +defined('MOODLE_INTERNAL') || die(); + +class block_private_files_renderer extends plugin_renderer_base { + + /** + * Prints private files tree view + * @return string + */ + public function private_files_tree() { + return $this->render(new private_files_tree); + } + + public function render_private_files_tree(private_files_tree $tree) { + $module = array('name'=>'block_private_files', 'fullpath'=>'/blocks/private_files/module.js', 'requires'=>array('yui2-treeview')); + $htmlid = 'private_files_tree_'.uniqid(); + $this->page->requires->js_init_call('M.block_private_files.init_tree', array(true, $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; + + if (empty($dir['subdirs']) and empty($dir['files'])) { + return ''; + } + $result = ''; + + return $result; + } +} + +class private_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); + } +}