Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-30973 Files API, check and update DocBlock

  • Loading branch information...
commit d2b7803e5a0ff017d5e95e5fc4368075c7f5b5f8 1 parent baa5cd8
@dcai dcai authored
Showing with 1,497 additions and 785 deletions.
  1. +10 −3 blocks/html/lib.php
  2. +55 −52 lib/filebrowser/file_browser.php
  3. +51 −22 lib/filebrowser/file_info.php
  4. +129 −39 lib/filebrowser/file_info_context_course.php
  5. +33 −14 lib/filebrowser/file_info_context_coursecat.php
  6. +47 −15 lib/filebrowser/file_info_context_module.php
  7. +24 −14 lib/filebrowser/file_info_context_system.php
  8. +59 −14 lib/filebrowser/file_info_context_user.php
  9. +64 −37 lib/filebrowser/file_info_stored.php
  10. +132 −21 lib/filebrowser/virtual_root_file.php
  11. +182 −131 lib/filelib.php
  12. +26 −19 lib/filestorage/file_archive.php
  13. +48 −21 lib/filestorage/file_exceptions.php
  14. +30 −25 lib/filestorage/file_packer.php
  15. +85 −85 lib/filestorage/file_storage.php
  16. +19 −20 lib/filestorage/stored_file.php
  17. +35 −26 lib/filestorage/zip_archive.php
  18. +47 −25 lib/filestorage/zip_packer.php
  19. +13 −6 lib/questionlib.php
  20. +14 −10 mod/assignment/lib.php
  21. +13 −9 mod/data/lib.php
  22. +8 −6 mod/feedback/lib.php
  23. +27 −19 mod/folder/lib.php
  24. +25 −19 mod/forum/lib.php
  25. +13 −9 mod/glossary/lib.php
  26. +27 −19 mod/imscp/lib.php
  27. +25 −17 mod/lesson/lib.php
  28. +28 −19 mod/page/lib.php
  29. +14 −8 mod/quiz/lib.php
  30. +4 −1 mod/quiz/report/statistics/lib.php
  31. +28 −19 mod/resource/lib.php
  32. +20 −16 mod/scorm/lib.php
  33. +10 −2 mod/wiki/lib.php
  34. +13 −0 mod/workshop/form/accumulative/lib.php
  35. +13 −0 mod/workshop/form/comments/lib.php
  36. +13 −0 mod/workshop/form/numerrors/lib.php
  37. +12 −3 mod/workshop/lib.php
  38. +4 −2 question/previewlib.php
  39. +11 −2 question/type/calculated/lib.php
  40. +11 −2 question/type/calculatedmulti/lib.php
  41. +12 −2 question/type/calculatedsimple/lib.php
  42. +11 −2 question/type/essay/lib.php
  43. +10 −2 question/type/match/lib.php
  44. +11 −2 question/type/multichoice/lib.php
  45. +11 −2 question/type/numerical/lib.php
  46. +10 −2 question/type/shortanswer/lib.php
  47. +10 −2 question/type/truefalse/lib.php
View
13 blocks/html/lib.php
@@ -18,11 +18,18 @@
/**
* Form for editing HTML block instances.
*
- * @package block_html
* @copyright 2010 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package block_html
+ * @category files
+ * @param stdClass $course course object
+ * @param stdClass $birecord_or_cm block instance record
+ * @param stdClass $context context object
+ * @param string $filearea file area
+ * @param array $args extra arguments
+ * @param bool $forcedownload whether or not force download
+ * @return bool
*/
-
function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload) {
global $SCRIPT;
@@ -79,4 +86,4 @@ function block_html_global_db_replace($search, $replace) {
}
}
$instances->close();
-}
+}
View
107 lib/filebrowser/file_browser.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,10 +18,9 @@
/**
* Utility class for browsing of files.
*
- * @package core
- * @subpackage filebrowser
- * @copyright 2008 Petr Skoda (http://skodak.org)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package core_files
+ * @copyright 2008 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
@@ -41,8 +39,7 @@
require_once("$CFG->libdir/filebrowser/file_info_context_module.php");
/**
- * This class provides the main entry point for other code wishing to get
- * information about files.
+ * This class provides the main entry point for other code wishing to get information about files.
*
* The whole file storage for a Moodle site can be seen as a huge virtual tree.
* The spine of the tree is the tree of contexts (system, course-categories,
@@ -56,22 +53,23 @@
*
* Always use this abstraction when you need to access module files from core code.
*
- * @package core
- * @subpackage filebrowser
- * @copyright 2008 Petr Skoda (http://skodak.org)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package core_files
+ * @category files
+ * @copyright 2008 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_browser {
/**
* Looks up file_info instance
- * @param object $context
- * @param string $component
- * @param string $filearea
- * @param int $itemid
- * @param string $filepath
- * @param string $filename
- * @return file_info instance or null if not found or access not allowed
+ *
+ * @param stdClass $context context object
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null file_info instance or null if not found or access not allowed
*/
public function get_file_info($context = NULL, $component = NULL, $filearea = NULL, $itemid = NULL, $filepath = NULL, $filename = NULL) {
if (!$context) {
@@ -95,12 +93,13 @@ public function get_file_info($context = NULL, $component = NULL, $filearea = NU
/**
* Returns info about the files at System context
- * @param object $context
- * @param string $component
- * @param string $filearea
- * @param int $itemid
- * @param string $filepath
- * @param string $filename
+ *
+ * @param object $context context object
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
* @return file_info instance or null if not found or access not allowed
*/
private function get_file_info_context_system($context, $component, $filearea, $itemid, $filepath, $filename) {
@@ -111,13 +110,14 @@ private function get_file_info_context_system($context, $component, $filearea, $
/**
* Returns info about the files at User context
- * @param object $context
- * @param string $component
- * @param string $filearea
- * @param int $itemid
- * @param string $filepath
- * @param string $filename
- * @return file_info instance or null if not found or access not allowed
+ *
+ * @param stdClass $context context object
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null file_info instance or null if not found or access not allowed
*/
private function get_file_info_context_user($context, $component, $filearea, $itemid, $filepath, $filename) {
global $DB, $USER;
@@ -142,13 +142,14 @@ private function get_file_info_context_user($context, $component, $filearea, $it
/**
* Returns info about the files at Course category context
- * @param object $context
- * @param string $component
- * @param string $filearea
- * @param int $itemid
- * @param string $filepath
- * @param string $filename
- * @return file_info instance or null if not found or access not allowed
+ *
+ * @param stdClass $context context object
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null file_info instance or null if not found or access not allowed
*/
private function get_file_info_context_coursecat($context, $component, $filearea, $itemid, $filepath, $filename) {
global $DB;
@@ -163,13 +164,14 @@ private function get_file_info_context_coursecat($context, $component, $filearea
/**
* Returns info about the files at Course category context
- * @param object $context
- * @param string $component
- * @param string $filearea
- * @param int $itemid
- * @param string $filepath
- * @param string $filename
- * @return file_info instance or null if not found or access not allowed
+ *
+ * @param stdClass $context context object
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null file_info instance or null if not found or access not allowed
*/
private function get_file_info_context_course($context, $component, $filearea, $itemid, $filepath, $filename) {
global $DB, $COURSE;
@@ -186,13 +188,14 @@ private function get_file_info_context_course($context, $component, $filearea, $
/**
* Returns info about the files at Course category context
- * @param object $context
- * @param string $component
- * @param string $filearea
- * @param int $itemid
- * @param string $filepath
- * @param string $filename
- * @return file_info instance or null if not found or access not allowed
+ *
+ * @param stdClass $context context object
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null file_info instance or null if not found or access not allowed
*/
private function get_file_info_context_module($context, $component, $filearea, $itemid, $filepath, $filename) {
global $COURSE, $DB, $CFG;
View
73 lib/filebrowser/file_info.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Base for all file browsing classes.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,19 +26,26 @@
defined('MOODLE_INTERNAL') || die();
/**
- * Base class for things in the tree navigated by @see{file_browser}.
+ * Base class for things in the tree navigated by {@link file_browser}.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class file_info {
+ /** @var stdClass File context */
protected $context;
+ /** @var file_browser File browser instance */
protected $browser;
+ /**
+ * Constructor
+ *
+ * @param file_browser $browser file_browser instance
+ * @param stdClass $context
+ */
public function __construct($browser, $context) {
$this->browser = $browser;
$this->context = $context;
@@ -50,6 +55,7 @@ public function __construct($browser, $context) {
* Returns list of standard virtual file/directory identification.
* The difference from stored_file parameters is that null values
* are allowed in all fields
+ *
* @return array with keys contextid, component, filearea, itemid, filepath and filename
*/
public function get_params() {
@@ -63,30 +69,35 @@ public function get_params() {
/**
* Returns localised visible name.
+ *
* @return string
*/
public abstract function get_visible_name();
/**
- * Is directory?
+ * Whether or not this is a directory
+ *
* @return bool
*/
public abstract function is_directory();
/**
* Returns list of children.
+ *
* @return array of file_info instances
*/
public abstract function get_children();
/**
* Returns parent file_info instance
+ *
* @return file_info or null for root
*/
public abstract function get_parent();
/**
* Returns array of url encoded params.
+ *
* @return array with numeric keys
*/
public function get_params_rawencoded() {
@@ -104,8 +115,9 @@ public function get_params_rawencoded() {
/**
* Returns file download url
- * @param bool $forcedownload
- * @param bool $htts force https
+ *
+ * @param bool $forcedownload whether or not force download
+ * @param bool $https whether or not force https
* @return string url
*/
public function get_url($forcedownload=false, $https=false) {
@@ -113,7 +125,8 @@ public function get_url($forcedownload=false, $https=false) {
}
/**
- * Can I read content of this file or enter directory?
+ * Whether or not I can read content of this file or enter directory
+ *
* @return bool
*/
public function is_readable() {
@@ -121,7 +134,8 @@ public function is_readable() {
}
/**
- * Can I add new files or directories?
+ * Whether or not new files or directories can be added
+ *
* @return bool
*/
public function is_writable() {
@@ -143,6 +157,7 @@ public function is_empty_area() {
/**
* Returns file size in bytes, null for directories
+ *
* @return int bytes or null if not known
*/
public function get_filesize() {
@@ -151,6 +166,7 @@ public function get_filesize() {
/**
* Returns mimetype
+ *
* @return string mimetype or null if not known
*/
public function get_mimetype() {
@@ -159,6 +175,7 @@ public function get_mimetype() {
/**
* Returns time created unix timestamp if known
+ *
* @return int timestamp or null
*/
public function get_timecreated() {
@@ -167,6 +184,7 @@ public function get_timecreated() {
/**
* Returns time modified unix timestamp if known
+ *
* @return int timestamp or null
*/
public function get_timemodified() {
@@ -183,6 +201,7 @@ public function get_license() {
/**
* Returns the author name of the file
+ *
* @return string author name or null
*/
public function get_author() {
@@ -191,6 +210,7 @@ public function get_author() {
/**
* Returns the source of the file
+ *
* @return string a source url or null
*/
public function get_source() {
@@ -199,6 +219,7 @@ public function get_source() {
/**
* Returns the sort order of the file
+ *
* @return int
*/
public function get_sortorder() {
@@ -208,8 +229,9 @@ public function get_sortorder() {
/**
* Create new directory, may throw exception - make sure
* params are valid.
+ *
* @param string $newdirname name of new directory
- * @param int id of author, default $USER->id
+ * @param int $userid id of author, default $USER->id
* @return file_info new directory
*/
public function create_directory($newdirname, $userid = NULL) {
@@ -219,9 +241,10 @@ public function create_directory($newdirname, $userid = NULL) {
/**
* Create new file from string - make sure
* params are valid.
+ *
* @param string $newfilename name of new file
* @param string $content of file
- * @param int id of author, default $USER->id
+ * @param int $userid id of author, default $USER->id
* @return file_info new file
*/
public function create_file_from_string($newfilename, $content, $userid = NULL) {
@@ -231,9 +254,10 @@ public function create_file_from_string($newfilename, $content, $userid = NULL)
/**
* Create new file from pathname - make sure
* params are valid.
+ *
* @param string $newfilename name of new file
* @param string $pathname location of file
- * @param int id of author, default $USER->id
+ * @param int $userid id of author, default $USER->id
* @return file_info new file
*/
public function create_file_from_pathname($newfilename, $pathname, $userid = NULL) {
@@ -243,9 +267,10 @@ public function create_file_from_pathname($newfilename, $pathname, $userid = NUL
/**
* Create new file from stored file - make sure
* params are valid.
+ *
* @param string $newfilename name of new file
- * @param mixed dile id or stored_file of file
- * @param int id of author, default $USER->id
+ * @param int|stored_file $fid id or stored_file of file
+ * @param int $userid id of author, default $USER->id
* @return file_info new file
*/
public function create_file_from_storedfile($newfilename, $fid, $userid = NULL) {
@@ -254,6 +279,7 @@ public function create_file_from_storedfile($newfilename, $fid, $userid = NULL)
/**
* Delete file, make sure file is deletable first.
+ *
* @return bool success
*/
public function delete() {
@@ -262,12 +288,13 @@ public function delete() {
/**
* Copy content of this file to local storage, overriding current file if needed.
- * @param int $contextid
- * @param string $component
- * @param string $filearea
- * @param int $itemid
- * @param string $filepath
- * @param string $filename
+ *
+ * @param int $contextid context ID
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
* @return boolean success
*/
public function copy_to_storage($contextid, $component, $filearea, $itemid, $filepath, $filename) {
@@ -276,6 +303,8 @@ public function copy_to_storage($contextid, $component, $filearea, $itemid, $fil
/**
* Copy content of this file to local storage, overriding current file if needed.
+ *
+ * @todo MDL-31068 implement move() rename() unzip() zip()
* @param string $pathname real local full file name
* @return boolean success
*/
View
168 lib/filebrowser/file_info_context_course.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Utility class for browsing of course files.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,16 +26,23 @@
defined('MOODLE_INTERNAL') || die();
/**
- * Represents a course context in the tree navigated by @see{file_browser}.
+ * Represents a course context in the tree navigated by {@link file_browser}.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_context_course extends file_info {
+ /** @var stdClass course object */
protected $course;
+ /**
+ * Constructor
+ *
+ * @param file_browser $browser file browser instance
+ * @param stdClass $context context object
+ * @param stdClass $course course object
+ */
public function __construct($browser, $context, $course) {
parent::__construct($browser, $context);
$this->course = $course;
@@ -46,11 +51,12 @@ public function __construct($browser, $context, $course) {
/**
* Return information about this specific context level
*
- * @param $component
- * @param $filearea
- * @param $itemid
- * @param $filepath
- * @param $filename
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null file_info instance or null if not found or access not allowed
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
// try to emulate require_login() tests here
@@ -80,6 +86,14 @@ public function get_file_info($component, $filearea, $itemid, $filepath, $filena
return null;
}
+ /**
+ * Gets a stored file for the course summary filearea directory
+ *
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null file_info instance or null if not found or access not allowed
+ */
protected function get_area_course_summary($itemid, $filepath, $filename) {
global $CFG;
@@ -106,7 +120,14 @@ protected function get_area_course_summary($itemid, $filepath, $filename) {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areacourseintro', 'repository'), false, true, true, false);
}
-
+ /**
+ * Gets a stored file for the course section filearea directory
+ *
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null file_info instance or null if not found or access not allowed
+ */
protected function get_area_course_section($itemid, $filepath, $filename) {
global $CFG, $DB;
@@ -139,7 +160,14 @@ protected function get_area_course_section($itemid, $filepath, $filename) {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, $section->section, true, true, true, false);
}
-
+ /**
+ * Gets a stored file for the course legacy filearea directory
+ *
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null file_info instance or null if not found or access not allowed
+ */
protected function get_area_course_legacy($itemid, $filepath, $filename) {
if (!has_capability('moodle/course:managefiles', $this->context)) {
return null;
@@ -169,6 +197,14 @@ protected function get_area_course_legacy($itemid, $filepath, $filename) {
return new file_info_area_course_legacy($this->browser, $this->context, $storedfile);
}
+ /**
+ * Gets a stored file for the backup course filearea directory
+ *
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null file_info instance or null if not found or access not allowed
+ */
protected function get_area_backup_course($itemid, $filepath, $filename) {
global $CFG;
@@ -202,10 +238,10 @@ protected function get_area_backup_course($itemid, $filepath, $filename) {
/**
* Gets a stored file for the automated backup filearea directory
*
- * @param int $itemid
- * @param string $filepath
- * @param string $filename
- * @return file_info_context_course
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null
*/
protected function get_area_backup_automated($itemid, $filepath, $filename) {
global $CFG;
@@ -237,6 +273,14 @@ protected function get_area_backup_automated($itemid, $filepath, $filename) {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('automatedbackup', 'repository'), true, $downloadable, $uploadable, false);
}
+ /**
+ * Gets a stored file for the backup section filearea directory
+ *
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null file_info instance or null if not found or access not allowed
+ */
protected function get_area_backup_section($itemid, $filepath, $filename) {
global $CFG, $DB;
@@ -273,12 +317,18 @@ protected function get_area_backup_section($itemid, $filepath, $filename) {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, $section->id, true, $downloadable, $uploadable, false);
}
+ /**
+ * Returns localised visible name.
+ *
+ * @return string
+ */
public function get_visible_name() {
return ($this->course->id == SITEID) ? get_string('frontpage', 'admin') : format_string($this->course->fullname, true, array('context'=>$this->context));
}
/**
- * Can I add new files or directories?
+ * Whether or not new files or directories can be added
+ *
* @return bool
*/
public function is_writable() {
@@ -286,7 +336,8 @@ public function is_writable() {
}
/**
- * Is directory?
+ * Whether or not this is a directory
+ *
* @return bool
*/
public function is_directory() {
@@ -295,6 +346,7 @@ public function is_directory() {
/**
* Returns list of children.
+ *
* @return array of file_info instances
*/
public function get_children() {
@@ -336,6 +388,8 @@ public function get_children() {
/**
* Returns parent file_info instance
+ *
+ * @todo error checking if get_parent_contextid() returns false
* @return file_info or null for root
*/
public function get_parent() {
@@ -350,12 +404,18 @@ public function get_parent() {
/**
* Subclass of file_info_stored for files in the course files area.
*
- * @package core
- * @subpackage filebrowser
- * @copyright 2008 Petr Skoda (http://skodak.org)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package core_files
+ * @copyright 2008 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_area_course_legacy extends file_info_stored {
+ /**
+ * Constructor
+ *
+ * @param file_browser $browser file browser instance
+ * @param stdClass $context context object
+ * @param stored_file $storedfile stored_file instance
+ */
public function __construct($browser, $context, $storedfile) {
global $CFG;
$urlbase = $CFG->wwwroot.'/file.php';
@@ -364,8 +424,9 @@ public function __construct($browser, $context, $storedfile) {
/**
* Returns file download url
- * @param bool $forcedownload
- * @param bool $htts force https
+ *
+ * @param bool $forcedownload whether or not force download
+ * @param bool $https whether or not force https
* @return string url
*/
public function get_url($forcedownload=false, $https=false) {
@@ -388,6 +449,7 @@ public function get_url($forcedownload=false, $https=false) {
/**
* Returns list of children.
+ *
* @return array of file_info instances
*/
public function get_children() {
@@ -408,17 +470,26 @@ public function get_children() {
}
/**
- * Represents a course category context in the tree navigated by @see{file_browser}.
+ * Represents a course category context in the tree navigated by {@link file_browser}.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_area_course_section extends file_info {
+ /** @var stdClass course object */
protected $course;
+ /** @var file_info_context_course course file info object */
protected $courseinfo;
+ /**
+ * Constructor
+ *
+ * @param file_browser $browser file browser instance
+ * @param stdClass $context context object
+ * @param stdClass $course course object
+ * @param file_info_context_course $courseinfo file info instance
+ */
public function __construct($browser, $context, $course, file_info_context_course $courseinfo) {
parent::__construct($browser, $context);
$this->course = $course;
@@ -429,6 +500,7 @@ public function __construct($browser, $context, $course, file_info_context_cours
* Returns list of standard virtual file/directory identification.
* The difference from stored_file parameters is that null values
* are allowed in all fields
+ *
* @return array with keys contextid, filearea, itemid, filepath and filename
*/
public function get_params() {
@@ -442,6 +514,7 @@ public function get_params() {
/**
* Returns localised visible name.
+ *
* @return string
*/
public function get_visible_name() {
@@ -452,7 +525,8 @@ public function get_visible_name() {
}
/**
- * Can I add new files or directories?
+ * Return whether or not new files or directories can be added
+ *
* @return bool
*/
public function is_writable() {
@@ -460,7 +534,7 @@ public function is_writable() {
}
/**
- * Is this empty area?
+ * Return whether or not this is a empty area
*
* @return bool
*/
@@ -470,7 +544,8 @@ public function is_empty_area() {
}
/**
- * Is directory?
+ * Return whether or not this is a empty area
+ *
* @return bool
*/
public function is_directory() {
@@ -479,6 +554,7 @@ public function is_directory() {
/**
* Returns list of children.
+ *
* @return array of file_info instances
*/
public function get_children() {
@@ -498,7 +574,8 @@ public function get_children() {
/**
* Returns parent file_info instance
- * @return file_info or null for root
+ *
+ * @return file_info|null file_info or null for root
*/
public function get_parent() {
return $this->courseinfo;
@@ -509,15 +586,24 @@ public function get_parent() {
/**
* Implementation of course section backup area
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_area_backup_section extends file_info {
+ /** @var stdClass course object */
protected $course;
+ /** @var file_info_context_course course file info object */
protected $courseinfo;
+ /**
+ * Constructor
+ *
+ * @param file_browser $browser file browser instance
+ * @param stdClass $context context object
+ * @param stdClass $course course object
+ * @param file_info_context_course $courseinfo file info instance
+ */
public function __construct($browser, $context, $course, file_info_context_course $courseinfo) {
parent::__construct($browser, $context);
$this->course = $course;
@@ -528,6 +614,7 @@ public function __construct($browser, $context, $course, file_info_context_cours
* Returns list of standard virtual file/directory identification.
* The difference from stored_file parameters is that null values
* are allowed in all fields
+ *
* @return array with keys contextid, component, filearea, itemid, filepath and filename
*/
public function get_params() {
@@ -541,6 +628,7 @@ public function get_params() {
/**
* Returns localised visible name.
+ *
* @return string
*/
public function get_visible_name() {
@@ -548,7 +636,8 @@ public function get_visible_name() {
}
/**
- * Can I add new files or directories?
+ * Return whether or not new files and directories can be added
+ *
* @return bool
*/
public function is_writable() {
@@ -556,7 +645,7 @@ public function is_writable() {
}
/**
- * Is this empty area?
+ * Whether or not this is an empty area
*
* @return bool
*/
@@ -566,7 +655,8 @@ public function is_empty_area() {
}
/**
- * Is directory?
+ * Return whether or not this is a directory
+ *
* @return bool
*/
public function is_directory() {
@@ -575,6 +665,7 @@ public function is_directory() {
/**
* Returns list of children.
+ *
* @return array of file_info instances
*/
public function get_children() {
@@ -594,11 +685,10 @@ public function get_children() {
/**
* Returns parent file_info instance
+ *
* @return file_info or null for root
*/
public function get_parent() {
return $this->browser->get_file_info($this->context);
}
}
-
-
View
47 lib/filebrowser/file_info_context_coursecat.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Utility class for browsing of curse category files.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,16 +26,23 @@
defined('MOODLE_INTERNAL') || die();
/**
- * Represents a course category context in the tree navigated by @see{file_browser}.
+ * Represents a course category context in the tree navigated by {@link file_browser}.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_context_coursecat extends file_info {
+ /** @var stdClass Category object */
protected $category;
+ /**
+ * Constructor
+ *
+ * @param file_browser $browser file browser instance
+ * @param stdClass $context context object
+ * @param stdClass $category category object
+ */
public function __construct($browser, $context, $category) {
parent::__construct($browser, $context);
$this->category = $category;
@@ -46,11 +51,12 @@ public function __construct($browser, $context, $category) {
/**
* Return information about this specific context level
*
- * @param $component
- * @param $filearea
- * @param $itemid
- * @param $filepath
- * @param $filename
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return fileinfo|null
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
global $DB;
@@ -80,6 +86,14 @@ public function get_file_info($component, $filearea, $itemid, $filepath, $filena
return null;
}
+ /**
+ * Return a file from course category description area
+ *
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return fileinfo|null
+ */
protected function get_area_coursecat_description($itemid, $filepath, $filename) {
global $CFG;
@@ -110,6 +124,7 @@ protected function get_area_coursecat_description($itemid, $filepath, $filename)
/**
* Returns localised visible name.
+ *
* @return string
*/
public function get_visible_name() {
@@ -117,7 +132,8 @@ public function get_visible_name() {
}
/**
- * Can I add new files or directories?
+ * Whether or not new files or directories can be added
+ *
* @return bool
*/
public function is_writable() {
@@ -125,7 +141,8 @@ public function is_writable() {
}
/**
- * Is directory?
+ * Whether or not this is a directory
+ *
* @return bool
*/
public function is_directory() {
@@ -134,6 +151,7 @@ public function is_directory() {
/**
* Returns list of children.
+ *
* @return array of file_info instances
*/
public function get_children() {
@@ -172,7 +190,8 @@ public function get_children() {
/**
* Returns parent file_info instance
- * @return file_info or null for root
+ *
+ * @return file_info|null fileinfo instance or null for root directory
*/
public function get_parent() {
$cid = get_parent_contextid($this->context);
View
62 lib/filebrowser/file_info_context_module.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Utility class for browsing of module files.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,19 +26,31 @@
defined('MOODLE_INTERNAL') || die();
/**
- * Represents a module context in the tree navigated by @see{file_browser}.
+ * Represents a module context in the tree navigated by {@link file_browser}.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_context_module extends file_info {
+ /** @var stdClass Course object */
protected $course;
+ /** @var stdClass Course module object */
protected $cm;
+ /** @var string Module name */
protected $modname;
+ /** @var array Available file areas */
protected $areas;
+ /**
+ * Constructor
+ *
+ * @param file_browser $browser file browser instance
+ * @param stdClass $context context object
+ * @param stdClass $course course object
+ * @param stdClass $cm course module object
+ * @param string $modname module name
+ */
public function __construct($browser, $context, $course, $cm, $modname) {
global $CFG;
@@ -68,11 +78,12 @@ public function __construct($browser, $context, $course, $cm, $modname) {
/**
* Return information about this specific context level
*
- * @param $component
- * @param $filearea
- * @param $itemid
- * @param $filepath
- * @param $filename
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
// try to emulate require_login() tests here
@@ -119,6 +130,14 @@ public function get_file_info($component, $filearea, $itemid, $filepath, $filena
return null;
}
+ /**
+ * Get a file from module intro area
+ *
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null
+ */
protected function get_area_intro($itemid, $filepath, $filename) {
global $CFG;
@@ -143,6 +162,14 @@ protected function get_area_intro($itemid, $filepath, $filename) {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('moduleintro'), false, true, true, false);
}
+ /**
+ * Get a file from module backup area
+ *
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null
+ */
protected function get_area_backup($itemid, $filepath, $filename) {
global $CFG;
@@ -172,6 +199,7 @@ protected function get_area_backup($itemid, $filepath, $filename) {
/**
* Returns localised visible name.
+ *
* @return string
*/
public function get_visible_name() {
@@ -179,7 +207,8 @@ public function get_visible_name() {
}
/**
- * Can I add new files or directories?
+ * Whether or not files or directories can be added
+ *
* @return bool
*/
public function is_writable() {
@@ -187,7 +216,7 @@ public function is_writable() {
}
/**
- * Is this empty area?
+ * Whether or not this is an emtpy area
*
* @return bool
*/
@@ -215,7 +244,8 @@ public function is_empty_area() {
}
/**
- * Is directory?
+ * Whether or not this is a directory
+ *
* @return bool
*/
public function is_directory() {
@@ -224,6 +254,7 @@ public function is_directory() {
/**
* Returns list of children.
+ *
* @return array of file_info instances
*/
public function get_children() {
@@ -247,7 +278,8 @@ public function get_children() {
/**
* Returns parent file_info instance
- * @return file_info or null for root
+ *
+ * @return file_info|null file_info or null for root
*/
public function get_parent() {
$pcid = get_parent_contextid($this->context);
View
38 lib/filebrowser/file_info_context_system.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Utility class for browsing of system files.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,25 +26,32 @@
defined('MOODLE_INTERNAL') || die();
/**
- * Represents the system context in the tree navigated by @see{file_browser}.
+ * Represents the system context in the tree navigated by {@link file_browser}.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_context_system extends file_info {
+
+ /**
+ * Constructor
+ *
+ * @param file_browser $browser file_browser instance
+ * @param stdClass $context context object
+ */
public function __construct($browser, $context) {
parent::__construct($browser, $context);
}
/**
* Return information about this specific part of context level
- * @param $component
- * @param $filearea
- * @param $itemid
- * @param $filepath
- * @param $filename
+ *
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
if (empty($component)) {
@@ -59,6 +64,7 @@ public function get_file_info($component, $filearea, $itemid, $filepath, $filena
/**
* Returns localised visible name.
+ *
* @return string
*/
public function get_visible_name() {
@@ -66,7 +72,8 @@ public function get_visible_name() {
}
/**
- * Can I add new files or directories?
+ * Whether or not new files or directories can be added
+ *
* @return bool
*/
public function is_writable() {
@@ -74,7 +81,8 @@ public function is_writable() {
}
/**
- * Is directory?
+ * Whether or not this is a directory
+ *
* @return bool
*/
public function is_directory() {
@@ -83,6 +91,7 @@ public function is_directory() {
/**
* Returns list of children.
+ *
* @return array of file_info instances
*/
public function get_children() {
@@ -121,7 +130,8 @@ public function get_children() {
/**
* Returns parent file_info instance
- * @return file_info or null for root
+ *
+ * @return file_info|null file_info instance or null for root
*/
public function get_parent() {
return null;
View
73 lib/filebrowser/file_info_context_user.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Utility class for browsing of user files.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,16 +26,23 @@
defined('MOODLE_INTERNAL') || die();
/**
- * Represents a user context in the tree navigated by @see{file_browser}.
+ * Represents a user context in the tree navigated by {@link file_browser}.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_context_user extends file_info {
+ /** @var stdClass User object */
protected $user;
+ /**
+ * Constructor
+ *
+ * @param file_browser $browser
+ * @param stdClass $context
+ * @param stdClass $user
+ */
public function __construct($browser, $context, $user) {
parent::__construct($browser, $context);
$this->user = $user;
@@ -46,11 +51,12 @@ public function __construct($browser, $context, $user) {
/**
* Return information about this specific context level
*
- * @param $component
- * @param $filearea
- * @param $itemid
- * @param $filepath
- * @param $filename
+ * @param string $component componet
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null
*/
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) {
global $USER;
@@ -76,6 +82,15 @@ public function get_file_info($component, $filearea, $itemid, $filepath, $filena
return null;
}
+ /**
+ * Get a file from user private area
+ *
+ * @todo MDL-31070 this method should respect $CFG->userquota
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null
+ */
protected function get_area_user_private($itemid, $filepath, $filename) {
global $USER, $CFG;
@@ -110,6 +125,14 @@ protected function get_area_user_private($itemid, $filepath, $filename) {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areauserpersonal', 'repository'), false, true, true, false);
}
+ /**
+ * Get a file from user profile area
+ *
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null
+ */
protected function get_area_user_profile($itemid, $filepath, $filename) {
global $CFG;
@@ -144,6 +167,14 @@ protected function get_area_user_profile($itemid, $filepath, $filename) {
get_string('areauserprofile', 'repository'), false, $readaccess, $writeaccess, false);
}
+ /**
+ * Get a file from user draft area
+ *
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null
+ */
protected function get_area_user_draft($itemid, $filepath, $filename) {
global $USER, $CFG;
@@ -174,6 +205,15 @@ protected function get_area_user_draft($itemid, $filepath, $filename) {
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, get_string('areauserdraft', 'repository'), true, true, true, true);
}
+ /**
+ * Get a file from user backup area
+ *
+ * @todo MDL-31091 maybe we need new caability for access control
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return file_info|null
+ */
protected function get_area_user_backup($itemid, $filepath, $filename) {
global $USER, $CFG;
@@ -206,6 +246,7 @@ protected function get_area_user_backup($itemid, $filepath, $filename) {
/**
* Returns localised visible name.
+ *
* @return string
*/
public function get_visible_name() {
@@ -213,7 +254,8 @@ public function get_visible_name() {
}
/**
- * Can I add new files or directories?
+ * Whether or not new files or directories can be added
+ *
* @return bool
*/
public function is_writable() {
@@ -221,7 +263,8 @@ public function is_writable() {
}
/**
- * Is directory?
+ * Whether or not this is a directory
+ *
* @return bool
*/
public function is_directory() {
@@ -230,6 +273,7 @@ public function is_directory() {
/**
* Returns list of children.
+ *
* @return array of file_info instances
*/
public function get_children() {
@@ -253,7 +297,8 @@ public function get_children() {
/**
* Returns parent file_info instance
- * @return file_info or null for root
+ *
+ * @return file_info|null file_info instance or null for root
*/
public function get_parent() {
return $this->browser->get_file_info();
View
101 lib/filebrowser/file_info_stored.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,38 +18,42 @@
/**
* Utility class for browsing of stored files.
*
- * @package core
- * @subpackage filebrowser
- * @copyright 2008 Petr Skoda (http://skodak.org)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package core_files
+ * @copyright 2008 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
- * Represents an actual file or folder - a row in the file table -
- * in the tree navigated by @see{file_browser}.
+ * Represents an actual file or folder - a row in the file table in the tree navigated by {@link file_browser}.
*
- * @package core
- * @subpackage filebrowser
- * @copyright 2008 Petr Skoda (http://skodak.org)
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package core_files
+ * @copyright 2008 Petr Skoda (http://skodak.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class file_info_stored extends file_info {
+ /** @var stored_file|virtual_root_file stored_file or virtual_root_file instance */
protected $lf;
+ /** @var string the serving script */
protected $urlbase;
+ /** @var string the human readable name of this area */
protected $topvisiblename;
+ /** @var int|bool it's false if itemid is 0 and not included in URL */
protected $itemidused;
+ /** @var bool allow file reading */
protected $readaccess;
+ /** @var bool allow file write, delee */
protected $writeaccess;
+ /** @var string do not show links to parent context/area */
protected $areaonly;
/**
* Constructor
*
- * @param file_browser $browser
- * @param stdClass $context
- * @param stored_file|virtual_root_file $storedfile
+ * @param file_browser $browser file browser instance
+ * @param stdClass $context context object
+ * @param stored_file|virtual_root_file $storedfile stored_file instance
* @param string $urlbase the serving script - usually the $CFG->wwwroot/.'pluginfile.php'
* @param string $topvisiblename the human readable name of this area
* @param int|bool $itemidused false if itemid always 0 and not included in URL
@@ -74,6 +77,7 @@ public function __construct(file_browser $browser, $context, $storedfile, $urlba
* Returns list of standard virtual file/directory identification.
* The difference from stored_file parameters is that null values
* are allowed in all fields
+ *
* @return array with keys contextid, component, filearea, itemid, filepath and filename
*/
public function get_params() {
@@ -87,6 +91,7 @@ public function get_params() {
/**
* Returns localised visible name.
+ *
* @return string
*/
public function get_visible_name() {
@@ -110,8 +115,9 @@ public function get_visible_name() {
/**
* Returns file download url
- * @param bool $forcedownload
- * @param bool $htts force https
+ *
+ * @param bool $forcedownload Whether or not force download
+ * @param bool $https whether or not force https
* @return string url
*/
public function get_url($forcedownload=false, $https=false) {
@@ -140,7 +146,8 @@ public function get_url($forcedownload=false, $https=false) {
}
/**
- * Can I read content of this file or enter directory?
+ * Whether or not I can read content of this file or enter directory
+ *
* @return bool
*/
public function is_readable() {
@@ -148,7 +155,8 @@ public function is_readable() {
}
/**
- * Can I add new files or directories?
+ * Whether or not new files or directories can be added
+ *
* @return bool
*/
public function is_writable() {
@@ -156,7 +164,7 @@ public function is_writable() {
}
/**
- * Is this top of empty area?
+ * Whether or not this is an empty area
*
* @return bool
*/
@@ -172,6 +180,7 @@ public function is_empty_area() {
/**
* Returns file size in bytes, null for directories
+ *
* @return int bytes or null if not known
*/
public function get_filesize() {
@@ -180,6 +189,7 @@ public function get_filesize() {
/**
* Returns mimetype
+ *
* @return string mimetype or null if not known
*/
public function get_mimetype() {
@@ -188,6 +198,7 @@ public function get_mimetype() {
/**
* Returns time created unix timestamp if known
+ *
* @return int timestamp or null
*/
public function get_timecreated() {
@@ -196,6 +207,7 @@ public function get_timecreated() {
/**
* Returns time modified unix timestamp if known
+ *
* @return int timestamp or null
*/
public function get_timemodified() {
@@ -203,7 +215,8 @@ public function get_timemodified() {
}
/**
- * Is directory?
+ * Whether or not this is a directory
+ *
* @return bool
*/
public function is_directory() {
@@ -212,6 +225,7 @@ public function is_directory() {
/**
* Returns the license type of the file
+ *
* @return string license short name or null
*/
public function get_license() {
@@ -220,6 +234,7 @@ public function get_license() {
/**
* Returns the author name of the file
+ *
* @return string author name or null
*/
public function get_author() {
@@ -228,6 +243,7 @@ public function get_author() {
/**
* Returns the source of the file
+ *
* @return string a source url or null
*/
public function get_source() {
@@ -236,6 +252,7 @@ public function get_source() {
/**
* Returns the sort order of the file
+ *
* @return int
*/
public function get_sortorder() {
@@ -244,6 +261,7 @@ public function get_sortorder() {
/**
* Returns list of children.
+ *
* @return array of file_info instances
*/
public function get_children() {
@@ -266,7 +284,8 @@ public function get_children() {
/**
* Returns parent file_info instance
- * @return file_info or null for root
+ *
+ * @return file_info|null file_info instance or null for root
*/
public function get_parent() {
if ($this->lf->get_filepath() === '/' and $this->lf->is_directory()) {
@@ -296,9 +315,10 @@ public function get_parent() {
/**
* Create new directory, may throw exception - make sure
* params are valid.
+ *
* @param string $newdirname name of new directory
- * @param int id of author, default $USER->id
- * @return file_info new directory
+ * @param int $userid id of author, default $USER->id
+ * @return file_info|null new directory's file_info instance or null if failed
*/
public function create_directory($newdirname, $userid = NULL) {
if (!$this->is_writable() or !$this->lf->is_directory()) {
@@ -324,10 +344,11 @@ public function create_directory($newdirname, $userid = NULL) {
/**
* Create new file from string - make sure
* params are valid.
+ *
* @param string $newfilename name of new file
* @param string $content of file
- * @param int id of author, default $USER->id
- * @return file_info new file
+ * @param int $userid id of author, default $USER->id
+ * @return file_info|null new file's file_info instance or null if failed
*/
public function create_file_from_string($newfilename, $content, $userid = NULL) {
if (!$this->is_writable() or !$this->lf->is_directory()) {
@@ -370,10 +391,11 @@ public function create_file_from_string($newfilename, $content, $userid = NULL)
/**
* Create new file from pathname - make sure
* params are valid.
+ *
* @param string $newfilename name of new file
* @param string $pathname location of file
- * @param int id of author, default $USER->id
- * @return file_info new file
+ * @param int $userid id of author, default $USER->id
+ * @return file_info|null new file's file_info instance or null if failed
*/
public function create_file_from_pathname($newfilename, $pathname, $userid = NULL) {
if (!$this->is_writable() or !$this->lf->is_directory()) {
@@ -416,10 +438,11 @@ public function create_file_from_pathname($newfilename, $pathname, $userid = NUL
/**
* Create new file from stored file - make sure
* params are valid.
+ *
* @param string $newfilename name of new file
- * @param mixed file id or stored_file of file
- * @param int id of author, default $USER->id
- * @return file_info new file
+ * @param int|stored_file $fid file id or stored_file of file
+ * @param int $userid id of author, default $USER->id
+ * @return file_info|null new file's file_info instance or null if failed
*/
public function create_file_from_storedfile($newfilename, $fid, $userid = NULL) {
if (!$this->is_writable() or $this->lf->get_filename() !== '.') {
@@ -461,6 +484,7 @@ public function create_file_from_storedfile($newfilename, $fid, $userid = NULL)
/**
* Delete file, make sure file is deletable first.
+ *
* @return bool success
*/
public function delete() {
@@ -484,12 +508,14 @@ public function delete() {
/**
* Copy content of this file to local storage, overriding current file if needed.
- * @param int $contextid
- * @param string $filearea
- * @param int $itemid
- * @param string $filepath
- * @param string $filename
- * @return boolean success
+ *
+ * @param int $contextid context ID
+ * @param string $component file component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $filepath file path
+ * @param string $filename file name
+ * @return bool success
*/
public function copy_to_storage($contextid, $component, $filearea, $itemid, $filepath, $filename) {
if (!$this->is_readable() or $this->is_directory()) {
@@ -508,8 +534,9 @@ public function copy_to_storage($contextid, $component, $filearea, $itemid, $fil
/**
* Copy content of this file to local storage, overriding current file if needed.
+ *
* @param string $pathname real local full file name
- * @return boolean success
+ * @return bool success
*/
public function copy_to_pathname($pathname) {
if (!$this->is_readable() or $this->is_directory()) {
View
153 lib/filebrowser/virtual_root_file.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -19,8 +18,7 @@
/**
* Class simulating empty directories.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -28,22 +26,29 @@
defined('MOODLE_INTERNAL') || die();
/**
- * Represents the root directory of an empty file area in the tree navigated by
- * @see{file_browser}.
+ * Represents the root directory of an empty file area in the tree navigated by {@link file_browser}.
*
- * @package core
- * @subpackage filebrowser
+ * @package core_files
* @copyright 2008 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class virtual_root_file {
+ /** @var int context id */
protected $contextid;
+ /** @var string file component */
protected $component;
+ /** @var string file area */
protected $filearea;
+ /** @var int file itemid */
protected $itemid;
/**
* Constructor
+ *
+ * @param int $contextid context ID
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
*/
public function __construct($contextid, $component, $filearea, $itemid) {
$this->contextid = $contextid;
@@ -53,7 +58,8 @@ public function __construct($contextid, $component, $filearea, $itemid) {
}
/**
- * Is this a directory?
+ * Whether or not this is a directory
+ *
* @return bool
*/
public function is_directory() {
@@ -62,6 +68,7 @@ public function is_directory() {
/**
* Delete file
+ *
* @return success
*/
public function delete() {
@@ -80,7 +87,8 @@ public function add_to_curl_request(&$curlrequest, $key) {
/**
* Returns file handle - read only mode, no writing allowed into pool files!
- * @return file handle
+ *
+ * @return resource file handle
*/
public function get_content_file_handle() {
return null;
@@ -88,7 +96,8 @@ public function get_content_file_handle() {
/**
* Dumps file content to page
- * @return file handle
+ *
+ * @return resource file handle
*/
public function readfile() {
return;
@@ -96,6 +105,7 @@ public function readfile() {
/**
* Returns file content as string
+ *
* @return string content
*/
public function get_content() {
@@ -104,6 +114,7 @@ public function get_content() {
/**
* Copy content of file to given pathname
+ *
* @param string $pathname real path to new file
* @return bool success
*/
@@ -113,7 +124,8 @@ public function copy_content_to($pathname) {
/**
* List contents of archive
- * @param object $file_packer
+ *
+ * @param file_packer $packer file packer instance
* @return array of file infos
*/
public function list_files(file_packer $packer) {
@@ -122,7 +134,8 @@ public function list_files(file_packer $packer) {
/**
* Extract file to given file path (real OS filesystem), existing files are overwrited
- * @param object $file_packer
+ *
+ * @param file_packer $packer file packer instance
* @param string $pathname target directory
* @return mixed list of processed files; false if error
*/
@@ -132,13 +145,14 @@ public function extract_to_pathname(file_packer $packer, $pathname) {
/**
* Extract file to given file path (real OS filesystem), existing files are overwrited
- * @param object $file_packer
- * @param int $contextid
- * @param string $component
- * @param string $filearea
- * @param int $itemid
- * @param string $pathbase
- * @param int $userid
+ *
+ * @param file_packer $packer file packer instance
+ * @param int $contextid context ID
+ * @param string $component component
+ * @param string $filearea file area
+ * @param int $itemid item ID
+ * @param string $pathbase path base
+ * @param int $userid user ID
* @return mixed list of processed files; false if error
*/
public function extract_to_storage(file_packer $packer, $contextid, $component, $filearea, $itemid, $pathbase, $userid = NULL) {
@@ -147,7 +161,8 @@ public function extract_to_storage(file_packer $packer, $contextid, $component,
/**
* Add file/directory into archive
- * @param object $filearch
+ *
+ * @param file_archive $filearch file archive instance
* @param string $archivepath pathname in archive
* @return bool success
*/
@@ -157,84 +172,180 @@ public function archive_file(file_archive $filearch, $archivepath) {