* returned. Default false.
* allowid : If true then id attributes will not be removed, even when using htmlpurifier. Default (different from
* format_text) true. Default changed id attributes are commonly needed.
+ * blanktarget : If true all <a> tags will have target="_blank" added unless target is explicitly specified.
* </pre>
*
* @param string $text The content that may contain ULRs in need of rewriting.
return array($courses, $warnings);
}
+ /**
+ * Returns all area files (optionally limited by itemid).
+ *
+ * @param int $contextid context ID
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID or all files if not specified
+ * @param bool $useitemidinurl wether to use the item id in the file URL (modules intro don't use it)
+ * @return array of files, compatible with the external_files structure.
+ * @since Moodle 3.2
+ */
+ public static function get_area_files($contextid, $component, $filearea, $itemid = false, $useitemidinurl = true) {
+ $files = array();
+ $fs = get_file_storage();
+
+ if ($areafiles = $fs->get_area_files($contextid, $component, $filearea, $itemid, 'itemid, filepath, filename', false)) {
+ foreach ($areafiles as $areafile) {
+ $file = array();
+ $file['filename'] = $areafile->get_filename();
+ $file['filepath'] = $areafile->get_filepath();
+ $file['mimetype'] = $areafile->get_mimetype();
+ $file['filesize'] = $areafile->get_filesize();
+ $file['timemodified'] = $areafile->get_timemodified();
+ $fileitemid = $useitemidinurl ? $areafile->get_itemid() : null;
+ $file['fileurl'] = moodle_url::make_webservice_pluginfile_url($contextid, $component, $filearea,
+ $fileitemid, $areafile->get_filepath(), $areafile->get_filename())->out(false);
+ $files[] = $file;
+ }
+ }
+ return $files;
+ }
+}
+
+/**
+ * External structure representing a set of files.
+ *
+ * @package core_webservice
+ * @copyright 2016 Juan Leyva
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 3.2
+ */
+class external_files extends external_multiple_structure {
+
+ /**
+ * Constructor
+ * @param string $desc Description for the multiple structure.
+ * @param int $required The type of value (VALUE_REQUIRED OR VALUE_OPTIONAL).
+ */
+ public function __construct($desc = 'List of files.', $required = VALUE_REQUIRED) {
+
+ parent::__construct(
+ new external_single_structure(
+ array(
+ 'filename' => new external_value(PARAM_FILE, 'File name.', VALUE_OPTIONAL),
+ 'filepath' => new external_value(PARAM_PATH, 'File path.', VALUE_OPTIONAL),
+ 'filesize' => new external_value(PARAM_INT, 'File size.', VALUE_OPTIONAL),
+ 'fileurl' => new external_value(PARAM_URL, 'Downloadable file url.', VALUE_OPTIONAL),
+ 'timemodified' => new external_value(PARAM_INT, 'Time modified.', VALUE_OPTIONAL),
+ 'mimetype' => new external_value(PARAM_RAW, 'File mime type.', VALUE_OPTIONAL),
+ ),
+ 'File.'
+ ),
+ $desc,
+ $required
+ );
+ }
}