From 85495bd291a8e93b9939893e4ef870dd9a6f2f54 Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Mon, 15 Mar 2010 06:41:02 +0000 Subject: [PATCH] "MDL-21021, added a block to manager user private files" --- blocks/private_files/block_private_files.php | 95 ++++++++++++++++++++ lang/en_utf8/block_private_files.php | 3 + 2 files changed, 98 insertions(+) create mode 100755 blocks/private_files/block_private_files.php create mode 100644 lang/en_utf8/block_private_files.php diff --git a/blocks/private_files/block_private_files.php b/blocks/private_files/block_private_files.php new file mode 100755 index 00000000000..1301112c5ae --- /dev/null +++ b/blocks/private_files/block_private_files.php @@ -0,0 +1,95 @@ +. + + +/** + * Manage user private area files + * + * @package moodlecore + * @subpackage repository + * @copyright 2010 Dongsheng Cai + * @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() { + $this->title = get_string('privatefiles', 'block_private_files'); + $this->version = 2010030100; + } + + function specialization() { + } + function applicable_formats() { + return array('all' => true); + } + + function instance_allow_multiple() { + return false; + } + + function get_content() { + global $CFG, $USER, $PAGE; + if ($this->content !== NULL) { + return $this->content; + } + if (empty($this->instance)) { + return null; + } + $this->content->text = ''; + $this->content->footer = ''; + if (isloggedin() && !isguestuser()) { // Show the block + $usercontext = get_context_instance(CONTEXT_USER, $USER->id); + $client_id = uniqid(); + + $params = new stdclass; + $params->accepted_types = '*'; + $params->return_types = FILE_INTERNAL; + $params->context = $PAGE->context; + $params->env = 'filemanager'; + + $filepicker_options = initialise_filepicker($params); + + $fs = get_file_storage(); + $draftfiles = $fs->get_area_files($usercontext->id, 'user_private', 0, 'id', false); + // the number of existing files in user private area + $filecount = count($draftfiles); + + // read existing user private files + $options = file_get_user_area_files(0, '/', 'user_private'); + $options->maxbytes = -1; + $options->maxfiles = -1; + $options->filearea = 'user_private'; + $options->client_id = $client_id; + $options->filecount = $filecount; + $options->itemid = 0; + $options->subdirs = true; + // store filepicker options + $options->filepicker = $filepicker_options; + + $this->content = new stdClass; + $this->content->text = print_filemanager($options, true); +; + $this->content->footer = ''; + + } + return $this->content; + } +} diff --git a/lang/en_utf8/block_private_files.php b/lang/en_utf8/block_private_files.php new file mode 100644 index 00000000000..0343e592344 --- /dev/null +++ b/lang/en_utf8/block_private_files.php @@ -0,0 +1,3 @@ +