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
+116
View File
@@ -0,0 +1,116 @@
<?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 is the external method for deleting draft files.
*
* @package core_files
* @since Moodle 3.10
* @copyright 2020 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_files\external\delete;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/filelib.php');
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use context_user;
/**
* This is the external method for deleting draft files.
*
* @copyright 2020 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class draft extends external_api {
/**
* Describes the parameters for execute.
*
* @return external_function_parameters
* @since Moodle 3.10
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters (
[
'draftitemid' => new external_value(PARAM_INT, 'Item id of the draft file area'),
'files' => new external_multiple_structure(
new external_single_structure(
[
'filepath' => new external_value(PARAM_PATH, 'Path to the file or directory to delete.'),
'filename' => new external_value(PARAM_FILE, 'Name of the file to delete.'),
]
), 'Files or directories to be deleted.'
),
]
);
}
/**
* Delete the indicated files (or directories) from a user draft file area.
*
* @param int $draftitemid item id of the draft file area
* @param array $files files to be deleted
* @return array of warnings and parent paths of the files deleted
* @since Moodle 3.10
*/
public static function execute(int $draftitemid, array $files): array {
global $CFG, $USER;
require_once($CFG->dirroot . '/repository/lib.php');
$params = self::validate_parameters(self::execute_parameters(), compact('draftitemid', 'files'));
[$draftitemid, $files] = array_values($params);
$usercontext = context_user::instance($USER->id);
self::validate_context($usercontext);
$files = array_map(function($file) {
return (object) $file;
}, $files);
$parentpaths = repository_delete_selected_files($usercontext, 'user', 'draft', $draftitemid, $files);
return [
'parentpaths' => array_keys($parentpaths),
'warnings' => [],
];
}
/**
* Describes the execute return value.
*
* @return external_single_structure
* @since Moodle 3.10
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure(
[
'parentpaths' => new external_multiple_structure(
new external_value(PARAM_PATH, 'Path to parent directory of the deleted files.')
),
'warnings' => new external_warnings(),
]
);
}
}
+98
View File
@@ -0,0 +1,98 @@
<?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/>.
/**
* Generate a new draft itemid for the current user.
*
* @package core_files
* @since Moodle 3.11
* @copyright 2020 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_files\external\get;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/filelib.php');
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use context_user;
/**
* Generate a new draft itemid for the current user.
*
* @copyright 2020 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class unused_draft extends external_api {
/**
* Describes the parameters for execute.
*
* @return external_function_parameters
* @since Moodle 3.11
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters ([]);
}
/**
* Generate a new draft itemid for the current user.
*
* @return array of information containing the draft item area and possible warnings.
* @since Moodle 3.11
*/
public static function execute(): array {
global $USER;
$usercontext = context_user::instance($USER->id);
self::validate_context($usercontext);
return [
'component' => 'user',
'contextid' => $usercontext->id,
'userid' => $USER->id,
'filearea' => 'draft',
'itemid' => file_get_unused_draft_itemid(),
'warnings' => [],
];
}
/**
* Describes the execute return value.
*
* @return external_single_structure
* @since Moodle 3.11
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure(
[
'component' => new external_value(PARAM_COMPONENT, 'File area component.'),
'contextid' => new external_value(PARAM_INT, 'File area context.'),
'userid' => new external_value(PARAM_INT, 'File area user id.'),
'filearea' => new external_value(PARAM_ALPHA, 'File area name.'),
'itemid' => new external_value(PARAM_INT, 'File are item id.'),
'warnings' => new external_warnings(),
]
);
}
}
+171
View File
@@ -0,0 +1,171 @@
<?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_files\external;
use coding_exception;
use core_text;
use moodle_url;
use renderer_base;
use stdClass;
use stored_file;
/**
* Class for exporting stored_file data.
*
* @package core_files
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class stored_file_exporter extends \core\external\exporter {
/** @var int Length of the shortened filename */
protected const FILENAMESHORT_LENGTH = 25;
/** @var stored_file */
protected $file;
public function __construct(stored_file $file, $related = array()) {
$this->file = $file;
$data = new stdClass();
$data->contextid = $file->get_contextid();
$data->component = $file->get_component();
$data->filearea = $file->get_filearea();
$data->itemid = $file->get_itemid();
$data->filepath = $file->get_filepath();
$data->filename = $file->get_filename();
$data->isdir = $file->is_directory();
$data->isimage = $file->is_valid_image();
$data->timemodified = $file->get_timemodified();
$data->timecreated = $file->get_timecreated();
$data->filesize = $file->get_filesize();
$data->author = $file->get_author();
$data->license = $file->get_license();
if ($related['context']->id != $data->contextid) {
throw new coding_exception('Unexpected context ID received.');
}
parent::__construct($data, $related);
}
protected static function define_related() {
return array('context' => 'context');
}
protected static function define_properties() {
return array(
'contextid' => array(
'type' => PARAM_INT
),
'component' => array(
'type' => PARAM_COMPONENT
),
'filearea' => array(
'type' => PARAM_AREA
),
'itemid' => array(
'type' => PARAM_INT
),
'filepath' => array(
'type' => PARAM_PATH
),
'filename' => array(
'type' => PARAM_FILE
),
'isdir' => array(
'type' => PARAM_BOOL
),
'isimage' => array(
'type' => PARAM_BOOL
),
'timemodified' => array(
'type' => PARAM_INT
),
'timecreated' => array(
'type' => PARAM_INT
),
'filesize' => array(
'type' => PARAM_INT
),
'author' => array(
'type' => PARAM_TEXT
),
'license' => array(
'type' => PARAM_TEXT
)
);
}
protected static function define_other_properties() {
return array(
'filenameshort' => array(
'type' => PARAM_RAW,
),
'filesizeformatted' => array(
'type' => PARAM_RAW
),
'icon' => array(
'type' => PARAM_RAW,
),
'timecreatedformatted' => array(
'type' => PARAM_RAW
),
'timemodifiedformatted' => array(
'type' => PARAM_RAW
),
'url' => array(
'type' => PARAM_URL
),
);
}
protected function get_other_values(renderer_base $output) {
$filename = $this->file->get_filename();
$filenameshort = $filename;
if (core_text::strlen($filename) > static::FILENAMESHORT_LENGTH) {
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$extensionlength = core_text::strlen($extension) + 1;
$filenameshort = core_text::substr($filename, 0, -$extensionlength);
$filenameshort = shorten_text($filenameshort, static::FILENAMESHORT_LENGTH - $extensionlength, true, '..') .
".{$extension}";
}
$icon = $this->file->is_directory() ? file_folder_icon() : file_file_icon($this->file);
$url = moodle_url::make_pluginfile_url(
$this->file->get_contextid(),
$this->file->get_component(),
$this->file->get_filearea(),
$this->file->get_itemid(),
$this->file->get_filepath(),
$this->file->get_filename(),
true
);
return array(
'filenameshort' => $filenameshort,
'filesizeformatted' => display_size((int) $this->file->get_filesize()),
'icon' => $icon,
'url' => $url->out(false),
'timecreatedformatted' => userdate($this->file->get_timecreated()),
'timemodifiedformatted' => userdate($this->file->get_timemodified()),
);
}
}