]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14589 adding file export options to file_browser classes
authorskodak <skodak>
Wed, 20 May 2009 20:57:21 +0000 (20:57 +0000)
committerskodak <skodak>
Wed, 20 May 2009 20:57:21 +0000 (20:57 +0000)
lib/file/file_info.php
lib/file/file_info_stored.php

index 14ceb83080849a83632ab6fad879497cad1d7415..f6eb9928ca3b73f8ad1de4e270c40fb83546a890 100644 (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_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;
+    }
+
+    /**
+     * 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);
index 0436af80689e8fc252e1fc1de69031f8e1e6e19f..316eadfedebf93ed951a50c6e272d8a1d72a7235 100644 (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;
+    }
 }