MDL-14589 adding file export options to file_browser classes

This commit is contained in:
skodak 2009-05-20 20:57:21 +00:00
parent 70020e5caf
commit cd221853d6
2 changed files with 78 additions and 9 deletions

View file

@ -1,10 +1,12 @@
<?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) {
@ -13,11 +15,14 @@ abstract class file_info {
}
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_visible_name();
public abstract function is_directory();
public abstract function get_children();
public abstract function get_parent();
public function get_params_rawencoded() {
$params = $this->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;
}
//public abstract function copy(location params);
/**
* 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;
}
//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);

View file

@ -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;
}
}