Skip to content

Commit

Permalink
MDL-22591, user_private plugin, disable it from private file block, h…
Browse files Browse the repository at this point in the history
…ide user_private area from local plugin
  • Loading branch information
Dongsheng Cai committed May 31, 2010
1 parent 838447c commit 6bf197b
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 9 deletions.
1 change: 1 addition & 0 deletions blocks/private_files/block_private_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function get_content() {
$options->accepted_types = '*';
$options->return_types = FILE_INTERNAL;
$options->context = $PAGE->context;
$options->disable_types = array('user');

$this->content = new stdClass;
$this->content->text = $OUTPUT->file_manager($options);
Expand Down
1 change: 1 addition & 0 deletions lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public function __construct(stdClass $options) {
$params->return_types = $options->return_types;
$params->context = $options->context;
$params->env = 'filemanager';
$params->disable_types = !empty($options->disable_types)?$options->disable_types:array();
$filepicker_options = initialise_filepicker($params);
$this->options->filepicker = $filepicker_options;
}
Expand Down
27 changes: 20 additions & 7 deletions repository/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,9 @@ public static function get_instances($args = array()) {
$sql .= ' AND (i.userid = 0 or i.userid = ?)';
$params[] = $args['userid'];
}

if (!empty($args['disable_types']) && is_array($args['disable_types'])) {
$sql .= ' AND r.type NOT IN ("'.implode('","', $args['disable_types']).'")';
}
foreach ($contexts as $context) {
if (empty($firstcontext)) {
$firstcontext = true;
Expand Down Expand Up @@ -1815,6 +1817,10 @@ function initialise_filepicker($args) {
} else {
$context = $args->context;
}
$disable_types = array();
if (!empty($args->disable_types)) {
$disable_types = $args->disable_types;
}

$user_context = get_context_instance(CONTEXT_USER, $USER->id);

Expand All @@ -1823,7 +1829,8 @@ function initialise_filepicker($args) {
'context'=>array($user_context, get_system_context()),
'currentcontext'=> $context,
'accepted_types'=>$args->accepted_types,
'return_types'=>$args->return_types
'return_types'=>$args->return_types,
'disable_types'=>$disable_types
));

$return->repositories = array();
Expand Down Expand Up @@ -1854,12 +1861,18 @@ function repository_setup_default_plugins() {
global $OUTPUT;
//if the plugin type has no multiple instance (e.g. has no instance option name)
//repository_type::create will create an instance automatically
$local_plugin = new repository_type('local', array(), true);
$local_plugin_id = $local_plugin->create(true);
$upload_plugin = new repository_type('upload', array(), true);
$upload_plugin_id = $upload_plugin->create(true);
$user_plugin = new repository_type('user', array(), true);
$upload_plugin->create(true);

$recent_plugin = new repository_type('recent', array(), true);
$recent_plugin_id = $upload_plugin->create(true);
$upload_plugin->create(true);

$upload_plugin = new repository_type('upload', array(), true);
$upload_plugin->create(true);

$local_plugin = new repository_type('local', array(), true);
$local_plugin->create(true);

echo $OUTPUT->notification(get_string('setupdefaultplugins', 'repository'), 'notifysuccess');
return true;
}
8 changes: 7 additions & 1 deletion repository/local/repository.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ public function get_listing($encodedpath = '') {
$children = $fileinfo->get_children();
foreach ($children as $child) {
if ($child->is_directory()) {
$encodedpath = base64_encode(serialize($child->get_params()));
$params = $child->get_params();
$encodedpath = base64_encode(serialize($params));
// hide user_private area from local plugin, user should
// use private file plugin to access private files
if ($params['filearea'] == 'user_private') {
continue;
}
$node = array(
'title' => $child->get_visible_name(),
'size' => 0,
Expand Down
2 changes: 1 addition & 1 deletion repository/repository_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
// We have two special repoisitory type need to deal with
// local and recent plugins don't added new files to moodle, just add new records to database
// so we don't check user quota and maxbytes here
if ($repo->options['type'] == 'local' || $repo->options['type'] == 'recent' ) {
if (in_array($repo->options['type'], array('local', 'recent', 'user'))) {
try {
$fileinfo = $repo->copy_to_area($source, $saveas_filearea, $itemid, $saveas_path, $saveas_filename);
} catch (Exception $e) {
Expand Down
31 changes: 31 additions & 0 deletions repository/user/db/access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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/>.

$capabilities = array(

'repository/user:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW,
'student' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
)
);
27 changes: 27 additions & 0 deletions repository/user/db/install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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/>.

function xmldb_repository_user_install() {
global $CFG;
$result = true;
require_once($CFG->dirroot.'/repository/lib.php');
$user_plugin = new repository_type('user', array(), true);
if(!$id = $user_plugin->create(true)) {
$result = false;
}
return $result;
}
35 changes: 35 additions & 0 deletions repository/user/db/upgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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/>.

function xmldb_repository_user_upgrade($oldversion) {

global $CFG, $DB;

$dbman = $DB->get_manager();
$result = true;

/// And upgrade begins here. For each one, you'll need one
/// block of code similar to the next one. Please, delete
/// this comment lines once this file start handling proper
/// upgrade code.

/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
/// $result = result of database_manager methods
/// }

return $result;
}
Binary file added repository/user/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions repository/user/lang/en/repository_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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/>.

/**
* Strings for component 'repository_user', language 'en', branch 'MOODLE_20_STABLE'
*
* @package repository_user
* @copyright 2010 Dongsheng Cai
* @author Dongsheng Cai <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['configplugin'] = 'Configuration for user private files repository';
$string['repositorydesc'] = 'Files in user private area';
$string['repositoryname'] = 'Private files';
$string['emptyfilelist'] = 'There are no files to show';
$string['user:view'] = 'View user private files';
Loading

0 comments on commit 6bf197b

Please sign in to comment.