From: skodak Date: Wed, 20 May 2009 20:57:21 +0000 (+0000) Subject: MDL-14589 adding file export options to file_browser classes X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=cd221853d68209cf9b59f2e98217fe7b47f958a6;p=moodle.git MDL-14589 adding file export options to file_browser classes --- diff --git a/lib/file/file_info.php b/lib/file/file_info.php index 14ceb83080..f6eb9928ca 100644 --- a/lib/file/file_info.php +++ b/lib/file/file_info.php @@ -1,10 +1,12 @@ -get_params(); @@ -31,8 +36,6 @@ abstract class file_info { return $encoded; } - - public function get_url($forcedownload=false, $https=false) { return null; } @@ -82,9 +85,30 @@ abstract class file_info { 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); diff --git a/lib/file/file_info_stored.php b/lib/file/file_info_stored.php index 0436af8068..316eadfede 100644 --- a/lib/file/file_info_stored.php +++ b/lib/file/file_info_stored.php @@ -276,4 +276,49 @@ class file_info_stored extends file_info { 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; + } }