-<?php //$Id$
+<?php
/**
* Base class for things in the tree navigated by @see{file_browser}.
*/
abstract class file_info {
+
protected $context;
+
protected $browser;
public function __construct($browser, $context) {
}
public abstract function get_params();
+
public abstract function get_visible_name();
+
public abstract function is_directory();
+
public abstract function get_children();
- public abstract function get_parent();
+ public abstract function get_parent();
public function get_params_rawencoded() {
$params = $this->get_params();
return $encoded;
}
-
-
public function get_url($forcedownload=false, $https=false) {
return null;
}
return false;
}
-//TODO: following methods are not implemented yet ;-)
+ /**
+ * 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
+ */
+ public function copy_to_storage($contextid, $filearea, $itemid, $filepath, $filename) {
+ return false;
+ }
+
+ /**
+ * Copy content of this file to local storage, overriding current file if needed.
+ * @param string $pathname real local full file name
+ * @return boolean success
+ */
+ public function copy_to_pathname($pathname) {
+ return false;
+ }
- //public abstract function copy(location params);
+
+//TODO: following methods are not implemented yet ;-)
//public abstract function move(location params);
//public abstract function rename(new name);
//public abstract function unzip(location params);
return $this->lf->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
+ */
+ public function copy_to_storage($contextid, $filearea, $itemid, $filepath, $filename) {
+ if (!$this->is_readable() or $this->is_directory()) {
+ return false;
+ }
+
+ $fs = get_file_storage();
+ if ($existing = $fs->get_file($contextid, $filearea, $itemid, $filepath, $filename)) {
+ $existing->delete();
+ }
+ $file_record = array('contextid'=>$contextid, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$fileapth, 'filename'=>$filename);
+ $fs->create_file_from_storedfile($file_record, $this->lf);
+
+ return true;
+ }
+
+ /**
+ * Copy content of this file to local storage, overriding current file if needed.
+ * @param string $pathname real local full file name
+ * @return boolean success
+ */
+ public function copy_to_pathname($pathname) {
+ if (!$this->is_readable() or $this->is_directory()) {
+ return false;
+ }
+
+ if (file_exists($pathname)) {
+ if (!unlink($pathname)) {
+ return false;
+ }
+ }
+
+ $this->lf->copy_content_to($pathname);
+
+ return true;
+ }
}