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();
}
/**
- * Returns download url for
+ * Returns file download url
* @param bool $forcedownload
* @param bool $htts force https
* @return string url
$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,
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();
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);
$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,
'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;
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);
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;
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();
$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',
'filename' =>null);
}
+ /**
+ * Returns localised visible name.
+ * @return string
+ */
public function get_visible_name() {
$format = $this->course->format;
$sectionsname = get_string("coursesectionsummaries");
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;
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);
}
$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,
'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) {
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);
$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(),
'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();
}
}
+ /**
+ * 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;
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();
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) {
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;
}
+ /**
+ * 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;
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;
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;
return null;
}
+ /**
+ * Delete file, make sure file is deletable first.
+ * @return bool success
+ */
public function delete() {
if (!$this->is_writable()) {
return false;
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,
'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;
return $children;
}
+ /**
+ * Returns parent file_info instance
+ * @return file_info or null for root
+ */
public function get_parent() {
return null;
}
}
}
+ /**
+ * 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,
'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;
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));
}
* 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;
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