mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-22156, added recent files repository plugin
This commit is contained in:
parent
7f288e5002
commit
6fbf3c4868
@ -820,8 +820,13 @@ abstract class repository {
|
||||
$filename = $params['filename'];
|
||||
$fileitemid = $params['itemid'];
|
||||
$context = get_context_instance_by_id($contextid);
|
||||
$file_info = $browser->get_file_info($context, $filearea, $fileitemid, $filepath, $filename);
|
||||
$file_info->copy_to_storage($user_context->id, 'user_draft', $itemid, $save_path, $title);
|
||||
try {
|
||||
$file_info = $browser->get_file_info($context, $filearea, $fileitemid, $filepath, $filename);
|
||||
$file_info->copy_to_storage($user_context->id, 'user_draft', $itemid, $save_path, $title);
|
||||
} catch (Exception $e) {
|
||||
$err->e = $e->getMessage();
|
||||
die(json_encode($err));
|
||||
}
|
||||
|
||||
$ret['itemid'] = $itemid;
|
||||
$ret['title'] = $title;
|
||||
@ -1869,8 +1874,8 @@ function repository_setup_default_plugins() {
|
||||
$local_plugin_id = $local_plugin->create(true);
|
||||
$upload_plugin = new repository_type('upload', array(), true);
|
||||
$upload_plugin_id = $upload_plugin->create(true);
|
||||
if (is_int($local_plugin_id) or is_int($upload_plugin_id)) {
|
||||
echo $OUTPUT->box(get_string('setupdefaultplugins', 'repository'));
|
||||
}
|
||||
$recent_plugin = new repository_type('recent', array(), true);
|
||||
$recent_plugin_id = $upload_plugin->create(true);
|
||||
echo $OUTPUT->box(get_string('setupdefaultplugins', 'repository'));
|
||||
return true;
|
||||
}
|
||||
|
30
repository/recent/db/access.php
Normal file
30
repository/recent/db/access.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?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/recent:view' => array(
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'legacy' => array(
|
||||
'student' => CAP_ALLOW,
|
||||
'teacher' => CAP_ALLOW,
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
'manager' => CAP_ALLOW
|
||||
)
|
||||
)
|
||||
);
|
27
repository/recent/db/install.php
Normal file
27
repository/recent/db/install.php
Normal file
@ -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_recent_install() {
|
||||
global $CFG;
|
||||
$result = true;
|
||||
require_once($CFG->dirroot.'/repository/lib.php');
|
||||
$recent_plugin = new repository_type('recent', array(), true);
|
||||
if(!$id = $recent_plugin->create(true)) {
|
||||
$result = false;
|
||||
}
|
||||
return $result;
|
||||
}
|
35
repository/recent/db/upgrade.php
Normal file
35
repository/recent/db/upgrade.php
Normal file
@ -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_recent_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;
|
||||
}
|
BIN
repository/recent/icon.png
Normal file
BIN
repository/recent/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 582 B |
31
repository/recent/lang/en/repository_recent.php
Normal file
31
repository/recent/lang/en/repository_recent.php
Normal file
@ -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_recent', language 'en', branch 'MOODLE_20_STABLE'
|
||||
*
|
||||
* @package moodlecore
|
||||
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['configplugin'] = 'Configuration for recent files repository';
|
||||
$string['recentfilesnumber'] = 'Number of recent files';
|
||||
$string['emptyfilelist'] = 'There are no files to show';
|
||||
$string['notitle'] = 'notitle';
|
||||
$string['repositorydesc'] = 'Files recently used by current user';
|
||||
$string['repositoryname'] = 'Recent files';
|
151
repository/recent/repository.class.php
Executable file
151
repository/recent/repository.class.php
Executable file
@ -0,0 +1,151 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* repository_recent class is used to browse recent used files
|
||||
*
|
||||
* @since 2.0
|
||||
* @package moodlecore
|
||||
* @subpackage repository
|
||||
* @copyright 2010 Dongsheng Cai
|
||||
* @author Dongsheng Cai <dongsheng@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define('DEFAULT_RECENT_FILES_NUM', 50);
|
||||
class repository_recent extends repository {
|
||||
|
||||
/**
|
||||
* initialize recent plugin
|
||||
* @param int $repositoryid
|
||||
* @param int $context
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array()) {
|
||||
parent::__construct($repositoryid, $context, $options);
|
||||
$number = get_config('recent', 'recentfilesnumber');
|
||||
$number = (int)$number;
|
||||
if (empty($number)) {
|
||||
$this->number = DEFAULT_RECENT_FILES_NUM;
|
||||
} else {
|
||||
$this->number = $number;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* recent plugin doesn't require login, so list all files
|
||||
* @return mixed
|
||||
*/
|
||||
public function print_login() {
|
||||
return $this->get_listing();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not supported by File API yet
|
||||
* @param string $search_text
|
||||
* @return mixed
|
||||
*/
|
||||
public function search($search_text) {
|
||||
return array();
|
||||
}
|
||||
|
||||
private function get_recent_files($limitfrom = 0, $limit = DEFAULT_RECENT_FILES_NUM) {
|
||||
global $USER, $DB;
|
||||
$sql = 'SELECT DISTINCT pathnamehash, contextid, itemid, filearea, filepath, filename FROM {files} WHERE userid = ? AND filename <> "." ORDER BY timecreated DESC';
|
||||
$params = array('userid'=>$USER->id);
|
||||
$rs = $DB->get_recordset_sql($sql, array('userid'=>$USER->id), $limitfrom, $limit);
|
||||
$result = array();
|
||||
foreach ($rs as $file_record) {
|
||||
$info = array();
|
||||
$info['contextid'] = $file_record->contextid;
|
||||
$info['itemid'] = $file_record->itemid;
|
||||
$info['filearea'] = $file_record->filearea;
|
||||
$info['filepath'] = $file_record->filepath;
|
||||
$info['filename'] = $file_record->filename;
|
||||
$result[$file_record->pathnamehash] = $info;
|
||||
}
|
||||
$rs->close();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file listing
|
||||
*
|
||||
* @param string $encodedpath
|
||||
* @param string $path not used by this plugin
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_listing($encodedpath = '', $page = '') {
|
||||
global $CFG, $USER, $OUTPUT;
|
||||
$ret = array();
|
||||
$ret['dynload'] = true;
|
||||
$ret['nosearch'] = true;
|
||||
$list = array();
|
||||
$files = $this->get_recent_files(0, $this->number);
|
||||
|
||||
try {
|
||||
foreach ($files as $file) {
|
||||
$params = base64_encode(serialize($file));
|
||||
$icon = 'f/'.str_replace('.gif', '', mimeinfo('icon', $file['filename'])) . '-32';
|
||||
$node = array(
|
||||
'title' => $file['filename'],
|
||||
'size' => 0,
|
||||
'date' => '',
|
||||
'source'=> $params,
|
||||
'thumbnail' => $OUTPUT->pix_url($icon) . '',
|
||||
);
|
||||
$list[] = $node;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw new repository_exception('emptyfilelist', 'repository_recent');
|
||||
}
|
||||
$ret['list'] = $list;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set repository name
|
||||
*
|
||||
* @return string repository name
|
||||
*/
|
||||
public function get_name(){
|
||||
return get_string('repositoryname', 'repository_recent');;
|
||||
}
|
||||
|
||||
public static function get_type_option_names() {
|
||||
return array('recentfilesnumber');
|
||||
}
|
||||
|
||||
public function type_config_form($mform) {
|
||||
$number = get_config('repository_recent', 'recentfilesnumber');
|
||||
var_dump($number);
|
||||
if (empty($number)) {
|
||||
$number = DEFAULT_RECENT_FILES_NUM;
|
||||
}
|
||||
$mform->addElement('text', 'recentfilesnumber', get_string('recentfilesnumber', 'repository_recent'));
|
||||
}
|
||||
|
||||
/**
|
||||
* This plugin doesn't support to link to external links
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function supported_returntypes() {
|
||||
return FILE_INTERNAL;
|
||||
}
|
||||
}
|
18
repository/recent/version.php
Normal file
18
repository/recent/version.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?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/>.
|
||||
|
||||
$plugin->version = 2010042201;
|
Loading…
x
Reference in New Issue
Block a user