]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16596 adding missing get_parent_directory() method
authorskodak <skodak>
Sun, 21 Sep 2008 19:53:46 +0000 (19:53 +0000)
committerskodak <skodak>
Sun, 21 Sep 2008 19:53:46 +0000 (19:53 +0000)
lib/file/stored_file.php
lib/file/virtual_root_file.php

index 3ad8575151a42363a70bc5b8550754e54f890f32..d3e1afe241f20ee8379c19a5492bfa49dd9e312a 100644 (file)
@@ -199,6 +199,30 @@ class stored_file {
         return true;
     }
 
+    /**
+     * Returns parent directory, creates missing parents if needed
+     * @return object stored_file
+     */
+    public function get_parent_directory() {
+        if ($this->file_record->filepath === '/' and $this->file_record->filename === '.') {
+            //root dir does not have parent
+            return null;
+        }
+
+        if ($this->file_record->filename !== '.') {
+            return $this->fs->create_directory($this->file_record->contextid, $this->file_record->filearea, $this->file_record->itemid, $this->file_record->filepath);
+        }
+
+        $filepath = $this->file_record->filepath;
+        $filepath = trim($filepath, '/');
+        $dirs = explode('/', $filepath);
+        array_pop($dirs);
+        $filepath = implode('/', $dirs);
+        $filepath = ($filepath === '') ? '/' : "/$filepath/";
+
+        return $this->fs->create_directory($this->file_record->contextid, $this->file_record->filearea, $this->file_record->itemid, $filepath);
+    }
+
     public function get_contextid() {
         return $this->file_record->contextid;
     }
index cebd7ae20ef6dfb37c2e91e605c8e6aa72ea8300..526956180d1cd68fb794c87c063a6d854abe565c 100644 (file)
@@ -119,6 +119,14 @@ class virtual_root_file {
         return false;
     }
 
+    /**
+     * Returns parent directory
+     * @return object stored_file
+     */
+    public function get_parent_directory() {
+        return null;
+    }
+
     public function get_contextid() {
         return $this->contextid;
     }