mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-14589 adding file export options to file_browser classes
This commit is contained in:
parent
70020e5caf
commit
cd221853d6
2 changed files with 78 additions and 9 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue