MDL-16596 adding missing get_parent_directory() method

This commit is contained in:
skodak
2008-09-21 19:53:46 +00:00
parent 8b1ed8bf8f
commit 4b6b5ce7d9
2 changed files with 32 additions and 0 deletions
+24
View 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;
}
+8
View 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;
}