MDL-30995 Completion Fixedup some more PHP DOC issues
[moodle.git] / lib / filebrowser / file_info.php
blob44069114762f949dc688f83d1d43eb97a111e6f7
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Base for all file browsing classes.
21 * @package core_files
22 * @copyright 2008 Petr Skoda (http://skodak.org)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 /**
29 * Base class for things in the tree navigated by {@link file_browser}.
31 * @package core_files
32 * @copyright 2008 Petr Skoda (http://skodak.org)
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 abstract class file_info {
37 /** @var stdClass File context */
38 protected $context;
40 /** @var file_browser File browser instance */
41 protected $browser;
43 /**
44 * Constructor
46 * @param file_browser $browser file_browser instance
47 * @param stdClass $context
49 public function __construct($browser, $context) {
50 $this->browser = $browser;
51 $this->context = $context;
54 /**
55 * Returns list of standard virtual file/directory identification.
56 * The difference from stored_file parameters is that null values
57 * are allowed in all fields
59 * @return array with keys contextid, component, filearea, itemid, filepath and filename
61 public function get_params() {
62 return array('contextid' => $this->context->id,
63 'component' => null,
64 'filearea' => null,
65 'itemid' => null,
66 'filepath' => null,
67 'filename' => null);
70 /**
71 * Returns localised visible name.
73 * @return string
75 public abstract function get_visible_name();
77 /**
78 * Whether or not this is a directory
80 * @return bool
82 public abstract function is_directory();
84 /**
85 * Returns list of children.
87 * @return array of file_info instances
89 public abstract function get_children();
91 /**
92 * Returns parent file_info instance
94 * @return file_info or null for root
96 public abstract function get_parent();
98 /**
99 * Returns array of url encoded params.
101 * @return array with numeric keys
103 public function get_params_rawencoded() {
104 $params = $this->get_params();
105 $encoded = array();
106 $encoded[] = 'contextid='.$params['contextid'];
107 $encoded[] = 'component='.$params['component'];
108 $encoded[] = 'filearea='.$params['filearea'];
109 $encoded[] = 'itemid='.(is_null($params['itemid']) ? -1 : $params['itemid']);
110 $encoded[] = 'filepath='.(is_null($params['filepath']) ? '' : rawurlencode($params['filepath']));
111 $encoded[] = 'filename='.((is_null($params['filename']) or $params['filename'] === '.') ? '' : rawurlencode($params['filename']));
113 return $encoded;
117 * Returns file download url
119 * @param bool $forcedownload whether or not force download
120 * @param bool $https whether or not force https
121 * @return string url
123 public function get_url($forcedownload=false, $https=false) {
124 return null;
128 * Whether or not I can read content of this file or enter directory
130 * @return bool
132 public function is_readable() {
133 return true;
137 * Whether or not new files or directories can be added
139 * @return bool
141 public function is_writable() {
142 return true;
146 * Is this info area and is it "empty"? Are there any files in subfolders?
148 * This is used mostly in repositories to reduce the
149 * number of empty folders. This method may be very slow,
150 * use with care.
152 * @return bool
154 public function is_empty_area() {
155 return false;
159 * Returns file size in bytes, null for directories
161 * @return int bytes or null if not known
163 public function get_filesize() {
164 return null;
168 * Returns mimetype
170 * @return string mimetype or null if not known
172 public function get_mimetype() {
173 return null;
177 * Returns time created unix timestamp if known
179 * @return int timestamp or null
181 public function get_timecreated() {
182 return null;
186 * Returns time modified unix timestamp if known
188 * @return int timestamp or null
190 public function get_timemodified() {
191 return null;
195 * Returns the license type of the file
196 * @return string license short name or null
198 public function get_license() {
199 return null;
203 * Returns the author name of the file
205 * @return string author name or null
207 public function get_author() {
208 return null;
212 * Returns the source of the file
214 * @return string a source url or null
216 public function get_source() {
217 return null;
221 * Returns the sort order of the file
223 * @return int
225 public function get_sortorder() {
226 return 0;
230 * Create new directory, may throw exception - make sure
231 * params are valid.
233 * @param string $newdirname name of new directory
234 * @param int $userid id of author, default $USER->id
235 * @return file_info new directory
237 public function create_directory($newdirname, $userid = NULL) {
238 return null;
242 * Create new file from string - make sure
243 * params are valid.
245 * @param string $newfilename name of new file
246 * @param string $content of file
247 * @param int $userid id of author, default $USER->id
248 * @return file_info new file
250 public function create_file_from_string($newfilename, $content, $userid = NULL) {
251 return null;
255 * Create new file from pathname - make sure
256 * params are valid.
258 * @param string $newfilename name of new file
259 * @param string $pathname location of file
260 * @param int $userid id of author, default $USER->id
261 * @return file_info new file
263 public function create_file_from_pathname($newfilename, $pathname, $userid = NULL) {
264 return null;
268 * Create new file from stored file - make sure
269 * params are valid.
271 * @param string $newfilename name of new file
272 * @param int|stored_file $fid id or stored_file of file
273 * @param int $userid id of author, default $USER->id
274 * @return file_info new file
276 public function create_file_from_storedfile($newfilename, $fid, $userid = NULL) {
277 return null;
281 * Delete file, make sure file is deletable first.
283 * @return bool success
285 public function delete() {
286 return false;
290 * Copy content of this file to local storage, overriding current file if needed.
292 * @param int $contextid context ID
293 * @param string $component component
294 * @param string $filearea file area
295 * @param int $itemid item ID
296 * @param string $filepath file path
297 * @param string $filename file name
298 * @return boolean success
300 public function copy_to_storage($contextid, $component, $filearea, $itemid, $filepath, $filename) {
301 return false;
305 * Copy content of this file to local storage, overriding current file if needed.
307 * @todo MDL-31068 implement move() rename() unzip() zip()
308 * @param string $pathname real local full file name
309 * @return boolean success
311 public function copy_to_pathname($pathname) {
312 return false;
316 //TODO: following methods are not implemented yet ;-)
317 //public abstract function move(location params);
318 //public abstract function rename(new name);
319 //public abstract function unzip(location params);
320 //public abstract function zip(zip file, file info);