first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for repository_recent.
*
* @package repository_recent
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace repository_recent\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for repository_recent implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+37
View File
@@ -0,0 +1,37 @@
<?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 capabilities.
*
* @package repository_recent
* @copyright 2010 Dongsheng Cai
* @author Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'repository/recent:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'user' => CAP_ALLOW
)
)
);
+27
View 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;
}
@@ -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/>.
/**
* 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['recent:view'] = 'View recent files repository plugin';
$string['pluginname_help'] = 'Files recently used by current user';
$string['pluginname'] = 'Recent files';
$string['privacy:metadata'] = 'The Recent files repository plugin does not store or transmit any personal data.';
$string['timelimit'] = 'Time limit';
$string['timelimit_help'] = 'Only retrieve recent files within the time limit';
+251
View File
@@ -0,0 +1,251 @@
<?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/>.
/**
* This plugin is used to access recent used files
*
* @since Moodle 2.0
* @package repository_recent
* @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot . '/repository/lib.php');
/**
* repository_recent class is used to browse recent used files
*
* @since Moodle 2.0
* @package repository_recent
* @copyright 2010 Dongsheng Cai {@link http://dongsheng.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('DEFAULT_RECENT_FILES_NUM', 50);
/**
* DEFAULT_RECENT_FILES_TIME_LIMIT - default time limit.
*/
define('DEFAULT_RECENT_FILES_TIME_LIMIT', 6 * 4 * WEEKSECS);
class repository_recent extends repository {
/** @var int only retrieve files within the time limit */
protected $timelimit;
/** @var int recent files number configuration. */
protected $number;
/**
* 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;
}
$timelimit = get_config('recent', 'recentfilestimelimit');
$this->timelimit = (int)$timelimit;
}
/**
* recent plugin doesn't require login, so list all files
* @return mixed
*/
public function print_login() {
return $this->get_listing();
}
/**
* Only return files within the time limit
*
* @param int $limitfrom retrieve the files from
* @param int $limit limit number of the files
* @param int $timelimit only return files with the time limit
* @return array list of recent files
*/
private function get_recent_files($limitfrom = 0, $limit = DEFAULT_RECENT_FILES_NUM, $timelimit = 0) {
// XXX: get current itemid
global $USER, $DB, $itemid;
$timelimitsql = '';
if ($timelimit > 0) {
$timelimitsql = "AND timemodified >= :timelimit";
$timelimitparam = ['timelimit' => time() - $timelimit];
}
// This SQL will ignore draft files if not owned by current user.
// Ignore all file references.
$sql = "SELECT files1.id, files1.contextid, files1.component, files1.filearea,
files1.itemid, files1.filepath, files1.filename, files1.pathnamehash
FROM {files} files1
JOIN (
SELECT contenthash, filename, MAX(id) AS id
FROM {files}
WHERE userid = :userid
AND referencefileid is NULL
AND filename != :filename
AND ((filearea = :filearea1 AND itemid = :itemid) OR filearea != :filearea2)
$timelimitsql
GROUP BY contenthash, filename
) files2 ON files1.id = files2.id
ORDER BY files1.timemodified DESC";
$params = array(
'userid' => $USER->id,
'filename' => '.',
'filearea1' => 'draft',
'itemid' => $itemid,
'filearea2' => 'draft');
if (isset($timelimitparam)) {
$params = array_merge($params, $timelimitparam);
}
$rs = $DB->get_recordset_sql($sql, $params, $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['component'] = $file_record->component;
$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 $OUTPUT;
$ret = array();
$ret['dynload'] = true;
$ret['nosearch'] = true;
$ret['nologin'] = true;
$list = array();
$files = $this->get_recent_files(0, $this->number, $this->timelimit);
try {
foreach ($files as $file) {
// Check that file exists and accessible, retrieve size/date info
$browser = get_file_browser();
$context = context::instance_by_id($file['contextid']);
$fileinfo = $browser->get_file_info($context, $file['component'],
$file['filearea'], $file['itemid'], $file['filepath'], $file['filename']);
if ($fileinfo) {
$params = base64_encode(json_encode($file));
$node = array(
'title' => $fileinfo->get_visible_name(),
'size' => $fileinfo->get_filesize(),
'datemodified' => $fileinfo->get_timemodified(),
'datecreated' => $fileinfo->get_timecreated(),
'author' => $fileinfo->get_author(),
'license' => $fileinfo->get_license(),
'source'=> $params,
'icon' => $OUTPUT->image_url(file_file_icon($fileinfo))->out(false),
'thumbnail' => $OUTPUT->image_url(file_file_icon($fileinfo))->out(false),
);
if ($imageinfo = $fileinfo->get_imageinfo()) {
$fileurl = new moodle_url($fileinfo->get_url());
$node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $fileinfo->get_timemodified()));
$node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $fileinfo->get_timemodified()));
$node['image_width'] = $imageinfo['width'];
$node['image_height'] = $imageinfo['height'];
}
$list[] = $node;
}
}
} catch (Exception $e) {
throw new repository_exception('emptyfilelist', 'repository_recent');
}
$ret['list'] = array_filter($list, array($this, 'filter'));
return $ret;
}
public static function get_type_option_names() {
return array('recentfilesnumber', 'recentfilestimelimit', 'pluginname');
}
public static function type_config_form($mform, $classname = 'repository') {
parent::type_config_form($mform, $classname);
$number = get_config('repository_recent', 'recentfilesnumber');
if (empty($number)) {
$number = DEFAULT_RECENT_FILES_NUM;
}
$mform->addElement('text', 'recentfilesnumber', get_string('recentfilesnumber', 'repository_recent'));
$mform->setType('recentfilesnumber', PARAM_INT);
$mform->setDefault('recentfilesnumber', $number);
$mform->addElement('duration', 'recentfilestimelimit',
get_string('timelimit', 'repository_recent'), ['units' => [DAYSECS, WEEKSECS], 'optional' => true]);
$mform->addHelpButton('recentfilestimelimit', 'timelimit', 'repository_recent');
$mform->setDefault('recentfilestimelimit', DEFAULT_RECENT_FILES_TIME_LIMIT);
}
/**
* This plugin doesn't support to link to external links
*
* @return int
*/
public function supported_returntypes() {
return FILE_INTERNAL;
}
/**
* Repository method to make sure that user can access particular file.
*
* This is checked when user tries to pick the file from repository to deal with
* potential parameter substitutions is request
*
* @todo MDL-33805 remove this function when recent files are managed correctly
*
* @param string $source
* @return bool whether the file is accessible by current user
*/
public function file_is_accessible($source) {
global $USER;
$reference = $this->get_file_reference($source);
$file = self::get_moodle_file($reference);
return (!empty($file) && $file->get_userid() == $USER->id);
}
/**
* Does this repository used to browse moodle files?
*
* @return boolean
*/
public function has_moodle_files() {
return true;
}
/**
* Is this repository accessing private data?
*
* @return bool
*/
public function contains_private_data() {
return false;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

+75
View File
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
]>
<svg version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
x="0px" y="0px" width="74px" height="51px" viewBox="-0.535 -0.774 74 51"
style="overflow:visible;enable-background:new -0.535 -0.774 74 51;" xml:space="preserve" preserveAspectRatio="xMinYMid meet">
<defs>
</defs>
<radialGradient id="SVGID_1_" cx="137.084" cy="32.2324" r="123.3346" gradientUnits="userSpaceOnUse">
<stop offset="0" style="stop-color:#FAAF40"/>
<stop offset="0.0432" style="stop-color:#F9A538"/>
<stop offset="0.1116" style="stop-color:#F89D31"/>
<stop offset="0.2269" style="stop-color:#F89A2F"/>
<stop offset="0.5276" style="stop-color:#F7922D"/>
<stop offset="1" style="stop-color:#F37B28"/>
<a:midPointStop offset="0" style="stop-color:#FAAF40"/>
<a:midPointStop offset="0.1982" style="stop-color:#FAAF40"/>
<a:midPointStop offset="0.2269" style="stop-color:#F89A2F"/>
<a:midPointStop offset="0.6064" style="stop-color:#F89A2F"/>
<a:midPointStop offset="1" style="stop-color:#F37B28"/>
</radialGradient>
<path style="fill:url(#SVGID_1_);" d="M61.192,49.375V26.558c0-4.771-1.972-7.156-5.911-7.156c-3.942,0-5.912,2.386-5.912,7.156
v22.817H37.754V26.558c0-4.771-1.938-7.156-5.811-7.156c-3.94,0-5.91,2.386-5.91,7.156v22.817H14.417V25.211
c0-4.979,1.728-8.747,5.185-11.304c3.043-2.282,7.158-3.425,12.343-3.425c5.255,0,9.127,1.349,11.617,4.045
c2.142-2.696,6.049-4.045,11.72-4.045c5.186,0,9.298,1.143,12.341,3.425c3.457,2.557,5.186,6.325,5.186,11.304v24.164H61.192z"/>
<path style="fill:#58595B;" d="M15.499,16.321c-0.394,1.999-0.788,3.999-1.181,5.997c10.983,3.72,21.4,0.111,26.883-9.489
C33.184,7.282,25.601,12.914,15.499,16.321"/>
<linearGradient id="SVGID_2_" gradientUnits="userSpaceOnUse" x1="14.4287" y1="16.0166" x2="40.6895" y2="16.0166">
<stop offset="0" style="stop-color:#929497"/>
<stop offset="0.1245" style="stop-color:#757578"/>
<stop offset="0.2792" style="stop-color:#575658"/>
<stop offset="0.4403" style="stop-color:#403E3F"/>
<stop offset="0.6085" style="stop-color:#302D2E"/>
<stop offset="0.7884" style="stop-color:#262223"/>
<stop offset="1" style="stop-color:#231F20"/>
<a:midPointStop offset="0" style="stop-color:#929497"/>
<a:midPointStop offset="0.2606" style="stop-color:#929497"/>
<a:midPointStop offset="1" style="stop-color:#231F20"/>
</linearGradient>
<path style="fill:url(#SVGID_2_);" d="M15.499,14.889c-0.356,2.259-0.714,4.518-1.07,6.776c10.527,3.567,20.84,0.503,26.261-8.944
C33.708,4.677,25.925,11.373,15.499,14.889"/>
<linearGradient id="SVGID_3_" gradientUnits="userSpaceOnUse" x1="19.457" y1="7.248" x2="30.3611" y2="22.8207">
<stop offset="0" style="stop-color:#231F20"/>
<stop offset="1" style="stop-color:#231F20;stop-opacity:0"/>
<a:midPointStop offset="0" style="stop-color:#231F20"/>
<a:midPointStop offset="0.5" style="stop-color:#231F20"/>
<a:midPointStop offset="1" style="stop-color:#231F20;stop-opacity:0"/>
</linearGradient>
<path style="fill:url(#SVGID_3_);" d="M27.993,17.575c-4.764-0.997-10.036,1.485-13.564,4.09
C12.103,4.879,22.536,5.222,36.098,9.415c-0.857,4.143-2.387,9.598-5.017,12.903C31.081,20.182,30.052,18.6,27.993,17.575"/>
<linearGradient id="SVGID_4_" gradientUnits="userSpaceOnUse" x1="0.0078" y1="7.7275" x2="48.0068" y2="7.7275">
<stop offset="0" style="stop-color:#929497"/>
<stop offset="0.1245" style="stop-color:#757578"/>
<stop offset="0.2792" style="stop-color:#575658"/>
<stop offset="0.4403" style="stop-color:#403E3F"/>
<stop offset="0.6085" style="stop-color:#302D2E"/>
<stop offset="0.7884" style="stop-color:#262223"/>
<stop offset="1" style="stop-color:#231F20"/>
<a:midPointStop offset="0" style="stop-color:#929497"/>
<a:midPointStop offset="0.2606" style="stop-color:#929497"/>
<a:midPointStop offset="1" style="stop-color:#231F20"/>
</linearGradient>
<path style="fill:url(#SVGID_4_);" d="M0.008,14.889C17.625,4.318,27.468,2.282,48.007,0.202
C24.279,18.919,23.64,14.889,0.008,14.889"/>
<line style="fill:#383738;stroke:#4A4A4C;stroke-width:0.5;" x1="48.007" y1="0.202" x2="29.186" y2="13.948"/>
<path style="opacity:0.23;fill:#231F20;" d="M25.506,7.567C25.733,9.723,25.286,5.423,25.506,7.567"/>
<line style="fill:#FFFFFF;stroke:#A8ABAD;stroke-width:0.5;" x1="0.008" y1="14.889" x2="29.186" y2="13.948"/>
<path style="fill:none;stroke:#F16922;stroke-width:0.5;" d="M23.79,7.733c-4.996,1.381-21.387,5.041-21.64,7.086
c-0.483,3.917-0.123,10.143-0.123,10.143"/>
<path style="fill:#F16922;" d="M3.532,39.84C1.697,35.389-0.443,30.363,2.1,24.184C3.794,29.957,3.544,34.362,3.532,39.84"/>
<ellipse transform="matrix(0.942 -0.3356 0.3356 0.942 -1.1544 8.1596)" style="fill:#6D6E70;" cx="23.032" cy="7.42" rx="0.792" ry="0.411"/>
</svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

@@ -0,0 +1,31 @@
@repository @repository_recent @_file_upload
Feature: Recent files repository lists the recently used files
In order to save time when selecting files
As a user
I need to use again the files I've just used
@javascript
Scenario: Add files recently uploaded
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| private_files | System | 1 | my-index | side-post |
And the following "activities" exist:
| activity | course | name | intro |
| folder | C1 | Folder name | Folder description |
And I log in as "admin"
And I follow "Manage private files"
And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager
And I upload "lib/tests/fixtures/upload_users.csv" file to "Files" filemanager
And I press "Save changes"
And I am on the "Folder name" "folder activity" page
And I press "Edit"
And I add "empty.txt" file from "Recent files" to "Files" filemanager
And I add "empty.txt" file from "Recent files" to "Files" filemanager as:
| Save as | empty_copy.txt |
And I press "Save changes"
Then I should see "empty.txt"
And I should see "empty_copy.txt"
And I should see "Folder description"
+53
View File
@@ -0,0 +1,53 @@
<?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/>.
/**
* Recent repository data generator
*
* @package repository_recent
* @category test
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Recent repository data generator class
*
* @package repository_recent
* @category test
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class repository_recent_generator extends testing_repository_generator {
/**
* Fill in type record defaults.
*
* @param array $record
* @return array
*/
protected function prepare_type_record(array $record) {
$record = parent::prepare_type_record($record);
if (!isset($record['recentfilesnumber'])) {
$record['recentfilesnumber'] = '';
}
if (!isset($record['recentfilestimelimit'])) {
$record['recentfilestimelimit'] = '';
}
return $record;
}
}
+218
View File
@@ -0,0 +1,218 @@
<?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/>.
/**
* Unit test for recent repository
*
* @package repository_recent
*
* @author Nathan Nguyen <nathannguyen@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace repository_recent;
use repository;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->dirroot . '/files/externallib.php');
/**
* Unit test for recent repository
*
* @package repository_recent
*
* @author Nathan Nguyen <nathannguyen@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class lib_test extends \advanced_testcase {
/** @var repository Recent repository */
private $repo;
/** @var \context repository */
private $usercontext;
/**
* SetUp to create an repository instance.
*/
protected function setUp(): void {
global $USER;
$this->setAdminUser();
$this->usercontext = \context_user::instance($USER->id);
$repoid = $this->getDataGenerator()->create_repository('recent')->id;
$this->repo = repository::get_repository_by_id($repoid, $this->usercontext);
}
/**
* Test get listing
*/
public function test_get_listing_with_duplicate_file(): void {
global $itemid;
$this->resetAfterTest(true);
// Set global itemid for draft file (file manager mockup).
$itemid = file_get_unused_draft_itemid();
// No recent file.
$filelist = $this->repo->get_listing()['list'];
$this->assertCount(0, $filelist);
// Create test file 1.
$this->create_test_file('TestFile1', 'draft', $itemid);
$filelist = $this->repo->get_listing()['list'];
$this->assertCount(1, $filelist);
// Due to create_test_file function, same filename means same content as the content is the filename hash.
$this->create_test_file('TestFile1', 'private');
$filelist = $this->repo->get_listing()['list'];
$this->assertCount(1, $filelist);
// Create test file 2, different area.
$this->create_test_file('TestFile2', 'private');
$filelist = $this->repo->get_listing()['list'];
$this->assertCount(2, $filelist);
}
/**
* Test get listing reference file
*/
public function test_get_listing_with_reference_file(): void {
$this->resetAfterTest(true);
// Create test file 1.
$file1 = $this->create_test_file('TestFile1', 'private');
$filelist = $this->repo->get_listing()['list'];
$this->assertCount(1, $filelist);
// Create reference file.
$file2 = $this->create_reference_file($file1, 'TestFile2', 'private');
$filelist = $this->repo->get_listing()['list'];
$this->assertCount(1, $filelist);
// Delete reference.
$file2->delete_reference();
$filelist = $this->repo->get_listing()['list'];
$this->assertCount(2, $filelist);
}
/**
* Test number limit
*/
public function test_get_listing_number_limit(): void {
$this->resetAfterTest(true);
$this->create_multiple_test_files('private', 75);
$filelist = $this->repo->get_listing()['list'];
$this->assertCount(50, $filelist);
// The number limit is set as property of the repo, so we need to create new repo instance.
set_config('recentfilesnumber', 100, 'recent');
$repoid = $this->getDataGenerator()->create_repository('recent')->id;
$repo = repository::get_repository_by_id($repoid, $this->usercontext);
$filelist = $repo->get_listing()['list'];
$this->assertCount(75, $filelist);
}
/**
* Test time limit
*/
public function test_get_listing_time_limit(): void {
$this->resetAfterTest(true);
$this->create_multiple_test_files('private', 25);
$file1 = $this->create_test_file('TestFileTimeLimit', 'private');
// Set time modified back to a year ago.
$file1->set_timemodified(time() - YEARSECS);
// There is no time limit by default.
$filelist = $this->repo->get_listing()['list'];
$this->assertCount(26, $filelist);
// The time limit is set as property of the repo, so we need to create new repo instance.
set_config('recentfilestimelimit', 3600, 'recent');
$repoid = $this->getDataGenerator()->create_repository('recent')->id;
$repo = repository::get_repository_by_id($repoid, $this->usercontext);
$filelist = $repo->get_listing()['list'];
// Only get the recent files in the last hour.
$this->assertCount(25, $filelist);
}
/**
* Create multiple test file
*
* @param string $filearea file area
* @param int $numberoffiles number of files to be created
*/
private function create_multiple_test_files($filearea, $numberoffiles) {
for ($i = 0; $i < $numberoffiles; ++$i) {
$filename = "TestFile$i" . time();
$this->create_test_file($filename, $filearea);
}
}
/**
* Create test file
*
* @param string $filename file name
* @param string $filearea file area
* @param int $itemid item id
* @return \stored_file the newly created file
*/
private function create_test_file($filename, $filearea, $itemid = 0) {
global $USER;
$filerecord = array();
$filerecord['contextid'] = $this->usercontext->id;
$filerecord['component'] = 'user';
$filerecord['filearea'] = $filearea;
$filerecord['itemid'] = $itemid;
$filerecord['filepath'] = '/';
$filerecord['filename'] = $filename;
$filerecord['userid'] = $USER->id;
$fs = get_file_storage();
$content = hash("md5", $filename);
return $fs->create_file_from_string($filerecord, $content);
}
/**
* Create reference file
*
* @param \stored_file $file source file
* @param string $filename file name
* @param string $filearea file area
* @param int $itemid item id
* @return \stored_file the newly created file
*/
private function create_reference_file($file, $filename, $filearea, $itemid = 0) {
global $USER, $DB;
$newfilerecord = array();
$newfilerecord['contextid'] = $this->usercontext->id;
$newfilerecord['component'] = 'user';
$newfilerecord['filearea'] = $filearea;
$newfilerecord['itemid'] = $itemid;
$newfilerecord['filepath'] = '/';
$newfilerecord['filename'] = $filename;
$newfilerecord['userid'] = $USER->id;
$fs = get_file_storage();
$oldfilerecord = $DB->get_record('files', ['id' => $file->get_id()]);
$ref = $fs->pack_reference($oldfilerecord);
return $fs->create_file_from_reference($newfilerecord, $this->repo->id, $ref);
}
}
+31
View 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/>.
/**
* Version details
*
* @package repository
* @subpackage recent
* @copyright 2010 Dongsheng Cai
* @author Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'repository_recent'; // Full name of the plugin (used for diagnostics)