]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18111 improving file api comments and docs
authorskodak <skodak>
Thu, 21 May 2009 09:37:21 +0000 (09:37 +0000)
committerskodak <skodak>
Thu, 21 May 2009 09:37:21 +0000 (09:37 +0000)
lib/file/file_info.php
lib/file/file_info_course.php
lib/file/file_info_coursecat.php
lib/file/file_info_coursefile.php
lib/file/file_info_coursesection.php
lib/file/file_info_module.php
lib/file/file_info_stored.php
lib/file/file_info_system.php
lib/file/file_info_user.php
lib/file/file_storage.php
lib/packer/file_packer.php

index c4ccd63449e5f453b1ed8d30e428a2b618d3bce9..5fad0a1908005cc07601f69173f41f806b08eb64 100644 (file)
@@ -60,8 +60,8 @@ abstract class file_info {
     public abstract function is_directory();
 
     /**
-     * Does this node have children?
-     * @return bool
+     * Returns list of children.
+     * @return array of file_info instances
      */
     public abstract function get_children();
 
@@ -88,7 +88,7 @@ abstract class file_info {
     }
 
     /**
-     * Returns download url for
+     * Returns file download url
      * @param bool $forcedownload
      * @param bool $htts force https
      * @return string url
index 056963ce31df00d472ae0bffb2acf931c876bb54..00bd4918a581bdf9d7470e292e9f9f267c2f7f30 100644 (file)
@@ -37,6 +37,12 @@ class file_info_course extends file_info {
         $this->course   = $course;
     }
 
+    /**
+     * 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() {
         return array('contextid'=>$this->context->id,
                      'filearea' =>null,
@@ -49,14 +55,26 @@ class file_info_course extends file_info {
         return ($this->course->id == SITEID) ? get_string('frontpage', 'admin') : format_string($this->course->fullname);
     }
 
+    /**
+     * Can I add new files or directories?
+     * @return bool
+     */
     public function is_writable() {
         return false;
     }
 
+    /**
+     * Is directory?
+     * @return bool
+     */
     public function is_directory() {
         return true;
     }
 
+    /**
+     * Returns list of children.
+     * @return array of file_info instances
+     */
     public function get_children() {
         $children = array();
 
@@ -88,11 +106,13 @@ class file_info_course extends file_info {
 
         return $children;
     }
-    
+
     /**
-     * TODO error checking if get_parent_contextid() returns false
+     * Returns parent file_info instance
+     * @return file_info or null for root
      */
     public function get_parent() {
+        //TODO: error checking if get_parent_contextid() returns false
         $pcid = get_parent_contextid($this->context);
         $parent = get_context_instance_by_id($pcid);
         return $this->browser->get_file_info($parent);
index 57e6de21217466fab9d038510e8ec5d72da19f39..97f7180e7547cd2f4c5f046b220c6f36382f1bc8 100644 (file)
@@ -36,6 +36,12 @@ class file_info_coursecat extends file_info {
         $this->category = $category;
     }
 
+    /**
+     * 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() {
         return array('contextid'=>$this->context->id,
                      'filearea' =>null,
@@ -44,18 +50,34 @@ class file_info_coursecat extends file_info {
                      'filename' =>null);
     }
 
+    /**
+     * Returns localised visible name.
+     * @return string
+     */
     public function get_visible_name() {
         return format_string($this->category->name);
     }
 
+    /**
+     * Can I add new files or directories?
+     * @return bool
+     */
     public function is_writable() {
         return false;
     }
 
+    /**
+     * Is directory?
+     * @return bool
+     */
     public function is_directory() {
         return true;
     }
 
+    /**
+     * Returns list of children.
+     * @return array of file_info instances
+     */
     public function get_children() {
         global $DB;
 
@@ -90,6 +112,10 @@ class file_info_coursecat extends file_info {
         return $children;
     }
 
+    /**
+     * Returns parent file_info instance
+     * @return file_info or null for root
+     */
     public function get_parent() {
         $cid = get_parent_contextid($this->context);
         $parent = get_context_instance_by_id($cid);
index 6ddacadce48677714494b36172f8a1c0ec924d39..0d1073f97e69ecaf46a256d63e8054b78f6937c7 100644 (file)
@@ -35,6 +35,12 @@ class file_info_coursefile extends file_info_stored {
         parent::__construct($browser, $context, $storedfile, $urlbase, get_string('coursefiles'), false, true, true, false);
     }
 
+    /**
+     * Returns file download url
+     * @param bool $forcedownload
+     * @param bool $htts force https
+     * @return string url
+     */
     public function get_url($forcedownload=false, $https=false) {
         global $CFG;
 
@@ -55,6 +61,10 @@ class file_info_coursefile extends file_info_stored {
         return file_encode_url($this->urlbase, $path, $forcedownload, $https);
     }
 
+    /**
+     * Returns list of children.
+     * @return array of file_info instances
+     */
     public function get_children() {
         if (!$this->lf->is_directory()) {
             return array();
index d3ef0cff1f83b300ff5bb81875b8b304a461fffb..d42f1ce2820f96cc119fe00284a5c239534cbd31 100644 (file)
@@ -36,6 +36,12 @@ class file_info_coursesection extends file_info {
         $this->course = $course;
     }
 
+    /**
+     * 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() {
         return array('contextid'=>$this->context->id,
                      'filearea' =>'course_section',
@@ -44,6 +50,10 @@ class file_info_coursesection extends file_info {
                      'filename' =>null);
     }
 
+    /**
+     * Returns localised visible name.
+     * @return string
+     */
     public function get_visible_name() {
         $format = $this->course->format;
         $sectionsname = get_string("coursesectionsummaries");
@@ -51,14 +61,26 @@ class file_info_coursesection extends file_info {
         return $sectionsname;
     }
 
+    /**
+     * Can I add new files or directories?
+     * @return bool
+     */
     public function is_writable() {
         return false;
     }
 
+    /**
+     * Is directory?
+     * @return bool
+     */
     public function is_directory() {
         return true;
     }
 
+    /**
+     * Returns list of children.
+     * @return array of file_info instances
+     */
     public function get_children() {
         global $DB;
 
@@ -74,6 +96,10 @@ class file_info_coursesection extends file_info {
         return $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);
     }
index 375b2da22e66322d1825389fe13d725a3f3fe478..5de584afc5ef4d2fe1c3d8c3a18df38a090821a5 100644 (file)
@@ -41,6 +41,12 @@ class file_info_module extends file_info {
         $this->areas  = $areas;
     }
 
+    /**
+     * 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() {
         return array('contextid'=>$this->context->id,
                      'filearea' =>null,
@@ -49,18 +55,34 @@ class file_info_module extends file_info {
                      'filename' =>null);
     }
 
+    /**
+     * Returns localised visible name.
+     * @return string
+     */
     public function get_visible_name() {
         return $this->cm->name.' ('.get_string('modulename', $this->cm->modname).')';
     }
 
+    /**
+     * Can I add new files or directories?
+     * @return bool
+     */
     public function is_writable() {
         return false;
     }
 
+    /**
+     * Is directory?
+     * @return bool
+     */
     public function is_directory() {
         return true;
     }
 
+    /**
+     * Returns list of children.
+     * @return array of file_info instances
+     */
     public function get_children() {
         $children = array();
         foreach ($this->areas as $area=>$desctiption) {
@@ -71,6 +93,10 @@ class file_info_module extends file_info {
         return $children;
     }
 
+    /**
+     * Returns parent file_info instance
+     * @return file_info or null for root
+     */
     public function get_parent() {
         $pcid = get_parent_contextid($this->context);
         $parent = get_context_instance_by_id($pcid);
index e4d82c142d9bd99a66dd4488cfb56cde62c934ca..5c975cc388611820ea96d92065017b4ad750d926 100644 (file)
@@ -50,6 +50,12 @@ class file_info_stored extends file_info {
         $this->areaonly       = $areaonly;
     }
 
+    /**
+     * 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() {
         return array('contextid'=>$this->context->id,
                      'filearea' =>$this->lf->get_filearea(),
@@ -58,6 +64,10 @@ class file_info_stored extends file_info {
                      'filename' =>$this->lf->get_filename());
     }
 
+    /**
+     * Returns localised visible name.
+     * @return string
+     */
     public function get_visible_name() {
         $filename = $this->lf->get_filename();
         $filepath = $this->lf->get_filepath();
@@ -77,6 +87,12 @@ class file_info_stored extends file_info {
         }
     }
 
+    /**
+     * Returns file download url
+     * @param bool $forcedownload
+     * @param bool $htts force https
+     * @return string url
+     */
     public function get_url($forcedownload=false, $https=false) {
         global $CFG;
 
@@ -103,35 +119,66 @@ class file_info_stored extends file_info {
         return file_encode_url($this->urlbase, $path, $forcedownload, $https);
     }
 
+    /**
+     * Can I read content of this file or enter directory?
+     * @return bool
+     */
     public function is_readable() {
         return $this->readaccess;
     }
 
+    /**
+     * Can I add new files or directories?
+     * @return bool
+     */
     public function is_writable() {
         return $this->writeaccess;
     }
 
+    /**
+     * Returns file size in bytes, null for directories
+     * @return int bytes or null if not known
+     */
     public function get_filesize() {
         return $this->lf->get_filesize();
     }
 
+    /**
+     * Returns mimetype
+     * @return string mimetype or null if not known
+     */
     public function get_mimetype() {
-        // TODO: add some custom mime icons for courses, categories??
         return $this->lf->get_mimetype();
     }
 
+    /**
+     * Returns time created unix timestamp if known
+     * @return int timestamp or null
+     */
     public function get_timecreated() {
         return $this->lf->get_timecreated();
     }
 
+    /**
+     * Returns time modified unix timestamp if known
+     * @return int timestamp or null
+     */
     public function get_timemodified() {
         return $this->lf->get_timemodified();
     }
 
+    /**
+     * Is directory?
+     * @return bool
+     */
     public function is_directory() {
         return $this->lf->is_directory();
     }
 
+    /**
+     * Returns list of children.
+     * @return array of file_info instances
+     */
     public function get_children() {
         if (!$this->lf->is_directory()) {
             return array();
@@ -150,6 +197,10 @@ class file_info_stored extends file_info {
         return $result;
     }
 
+    /**
+     * Returns parent file_info instance
+     * @return file_info or null for root
+     */
     public function get_parent() {
         if ($this->lf->get_filepath() === '/' and $this->lf->is_directory()) {
             if ($this->areaonly) {
@@ -175,6 +226,13 @@ class file_info_stored extends file_info {
         return $this->browser->get_file_info($this->context, $this->lf->get_filearea(), $this->lf->get_itemid(), $filepath, '.');
     }
 
+    /**
+     * 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
+     */
     public function create_directory($newdirname, $userid=null) {
         if (!$this->is_writable() or !$this->lf->is_directory()) {
             return null;
@@ -196,6 +254,14 @@ class file_info_stored extends file_info {
     }
 
 
+    /**
+     * 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
+     */
     public function create_file_from_string($newfilename, $content, $userid=null) {
         if (!$this->is_writable() or !$this->lf->is_directory()) {
             return null;
@@ -228,6 +294,14 @@ class file_info_stored extends file_info {
         return 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
+     */
     public function create_file_from_pathname($newfilename, $pathname, $userid=null) {
         if (!$this->is_writable() or !$this->lf->is_directory()) {
             return null;
@@ -260,6 +334,14 @@ class file_info_stored extends file_info {
         return null;
     }
 
+    /**
+     * 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
+     * @return file_info new file
+     */
     public function create_file_from_storedfile($newfilename, $fid, $userid=null) {
         if (!$this->is_writable() or $this->lf->get_filename() !== '.') {
             return null;
@@ -292,6 +374,10 @@ class file_info_stored extends file_info {
         return null;
     }
 
+    /**
+     * Delete file, make sure file is deletable first.
+     * @return bool success
+     */
     public function delete() {
         if (!$this->is_writable()) {
             return false;
index 3a96830e41c06769e01f8a4bf81af09f7f369b6e..23d0016789027bacf20f5afdbbd3c118a29c0ff7 100644 (file)
@@ -33,6 +33,12 @@ class file_info_system extends file_info {
         parent::__construct($browser, get_context_instance(CONTEXT_SYSTEM));
     }
 
+    /**
+     * 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() {
         return array('contextid'=>$this->context->id,
                      'filearea' =>null,
@@ -41,18 +47,34 @@ class file_info_system extends file_info {
                      'filename' =>null);
     }
 
+    /**
+     * Returns localised visible name.
+     * @return string
+     */
     public function get_visible_name() {
         return get_string('arearoot', 'repository');
     }
 
+    /**
+     * Can I add new files or directories?
+     * @return bool
+     */
     public function is_writable() {
         return false;
     }
 
+    /**
+     * Is directory?
+     * @return bool
+     */
     public function is_directory() {
         return true;
     }
 
+    /**
+     * Returns list of children.
+     * @return array of file_info instances
+     */
     public function get_children() {
         global $DB, $USER;
 
@@ -87,6 +109,10 @@ class file_info_system extends file_info {
         return $children;
     }
 
+    /**
+     * Returns parent file_info instance
+     * @return file_info or null for root
+     */
     public function get_parent() {
         return null;
     }
index a8856ce9b58a78acf775c26b26185746b24c3586..46885987167126484b2642aad02abf274569675c 100644 (file)
@@ -46,6 +46,12 @@ class file_info_user extends file_info {
         }
     }
 
+    /**
+     * 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() {
         return array('contextid'=>$this->context->id,
                      'filearea' =>null,
@@ -54,18 +60,34 @@ class file_info_user extends file_info {
                      'filename' =>null);
     }
 
+    /**
+     * Returns localised visible name.
+     * @return string
+     */
     public function get_visible_name() {
         return fullname($this->user, true);
     }
 
+    /**
+     * Can I add new files or directories?
+     * @return bool
+     */
     public function is_writable() {
         return false;
     }
 
+    /**
+     * Is directory?
+     * @return bool
+     */
     public function is_directory() {
         return true;
     }
 
+    /**
+     * Returns list of children.
+     * @return array of file_info instances
+     */
     public function get_children() {
         global $USER, $CFG;
 
@@ -84,6 +106,10 @@ class file_info_user extends file_info {
         return $children;
     }
 
+    /**
+     * Returns parent file_info instance
+     * @return file_info or null for root
+     */
     public function get_parent() {
         return $this->browser->get_file_info(get_context_instance(CONTEXT_SYSTEM));
     }
index d4edcc3ed1b829f98684e5381828f3bd78adfb29..aa03ebd076e024f5700ac9a5253d1ca9513ae401 100644 (file)
@@ -32,7 +32,7 @@ require_once("$CFG->libdir/file/stored_file.php");
  * Only owner of file area may use this class to access own files,
  * for example only code in mod/assignment/* may access assignment
  * attachments. When core needs to access files of modules it has
- * to use file_browser class instead. 
+ * to use file_browser class instead.
  */
 class file_storage {
     private $filedir;
index f04d0714a321bae39c65b4f3eee65a5b334ecf44..10dd48956728a1d832964397851bfb7ad70d7d41 100644 (file)
@@ -31,7 +31,7 @@
 abstract class file_packer {
 
     /**
-     * archive files and store the result in file storage
+     * Archive files and store the result in file storage
      * @param array $files array with zip paths as keys (archivepath=>ospathname or archivepath=>stored_file) 
      * @param int $contextid
      * @param string $filearea