Merge branch 'MDL-78112-500' of https://github.com/paulholden/moodle into MOODLE_500_STABLE
This commit is contained in:
+27
-13
@@ -14,19 +14,9 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* FileManager form element
|
||||
*
|
||||
* Contains HTML class for a filemanager form element
|
||||
*
|
||||
* @package core_form
|
||||
* @copyright 2009 Dongsheng Cai <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
use core\context\user;
|
||||
|
||||
global $CFG;
|
||||
|
||||
require_once('HTML/QuickForm/element.php');
|
||||
require_once($CFG->dirroot.'/lib/filelib.php');
|
||||
require_once($CFG->dirroot.'/repository/lib.php');
|
||||
@@ -35,7 +25,8 @@ require_once('templatable_form_element.php');
|
||||
/**
|
||||
* Filemanager form element
|
||||
*
|
||||
* FilemaneManager lets user to upload/manage multiple files
|
||||
* Contains HTML class for a filemanager form element
|
||||
*
|
||||
* @package core_form
|
||||
* @category form
|
||||
* @copyright 2009 Dongsheng Cai <[email protected]>
|
||||
@@ -309,6 +300,29 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element implements temp
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* What to display when element is frozen
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFrozenHtml(): string {
|
||||
global $USER;
|
||||
|
||||
$filelist = [];
|
||||
|
||||
// List all of the current draft files.
|
||||
$usercontext = user::instance($USER->id);
|
||||
$files = get_file_storage()->get_area_files($usercontext->id, 'user', 'draft', $this->getValue(), 'id', false);
|
||||
foreach ($files as $file) {
|
||||
$filelist[] = html_writer::link(
|
||||
moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename(), true),
|
||||
$file->get_filename(),
|
||||
);
|
||||
}
|
||||
|
||||
return html_writer::alist($filelist) . $this->_getPersistantData();
|
||||
}
|
||||
|
||||
public function export_for_template(renderer_base $output) {
|
||||
$context = $this->export_for_template_base($output);
|
||||
$context['html'] = $this->toHtml();
|
||||
@@ -429,7 +443,7 @@ class form_filemanager implements renderable {
|
||||
$this->options = file_get_drafarea_files($options->itemid, '/');
|
||||
|
||||
// calculate file count
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
$usercontext = user::instance($USER->id);
|
||||
$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $options->itemid, 'id', false);
|
||||
$filecount = count($files);
|
||||
$this->options->filecount = $filecount;
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<?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/>.
|
||||
|
||||
namespace core_form;
|
||||
|
||||
use advanced_testcase;
|
||||
use core\context\user;
|
||||
use core\output\html_writer;
|
||||
use core\url;
|
||||
use MoodleQuickForm_filemanager;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/form/filemanager.php");
|
||||
|
||||
/**
|
||||
* Tests for the filemanager form element
|
||||
*
|
||||
* @package core_form
|
||||
* @covers \MoodleQuickForm_filemanager
|
||||
* @copyright 2026 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
final class filemanager_test extends advanced_testcase {
|
||||
/**
|
||||
* Test retrieving frozen HTML
|
||||
*/
|
||||
public function test_get_frozen_html(): void {
|
||||
global $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
$file = get_file_storage()->create_file_from_string([
|
||||
'contextid' => user::instance($USER->id)->id,
|
||||
'userid' => $USER->id,
|
||||
'component' => 'user',
|
||||
'filearea' => 'draft',
|
||||
'itemid' => file_get_unused_draft_itemid(),
|
||||
'filepath' => '/',
|
||||
'filename' => 'Hello.txt',
|
||||
], 'Hello');
|
||||
|
||||
$element = new MoodleQuickForm_filemanager('file', 'File');
|
||||
$element->setValue($file->get_itemid());
|
||||
|
||||
$draftfileurl = url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename(), true);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
html_writer::link($draftfileurl, $file->get_filename()),
|
||||
$element->getFrozenHtml(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user