Browse files

MDL-28666 file_storage::get_directory_files() supports references

  • Loading branch information...
1 parent 7051415 commit 462c4955f44e1d41dab5eae868c47176c330fb6f @dcai dcai committed with marinaglancy May 14, 2012
Showing with 22 additions and 15 deletions.
  1. +21 −15 lib/filestorage/file_storage.php
  2. +1 −0 repository/coursefiles/lib.php
View
36 lib/filestorage/file_storage.php
@@ -504,11 +504,13 @@ public function get_directory_files($contextid, $component, $filearea, $itemid,
$dirs = $includedirs ? "" : "AND filename <> '.'";
$length = textlib::strlen($filepath);
- $sql = "SELECT *
- FROM {files}
- WHERE contextid = :contextid AND component = :component AND filearea = :filearea AND itemid = :itemid
- AND ".$DB->sql_substr("filepath", 1, $length)." = :filepath
- AND id <> :dirid
+ $sql = "SELECT f.*, r.repositoryid, r.reference
+ FROM {files} f
+ LEFT JOIN {files_reference} r
+ ON f.referencefileid = r.id
+ WHERE f.contextid = :contextid AND f.component = :component AND f.filearea = :filearea AND f.itemid = :itemid
+ AND ".$DB->sql_substr("f.filepath", 1, $length)." = :filepath
+ AND f.id <> :dirid
$dirs
ORDER BY $sort";
$params = array('contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>$filepath, 'dirid'=>$directory->get_id());
@@ -532,12 +534,14 @@ public function get_directory_files($contextid, $component, $filearea, $itemid,
$length = textlib::strlen($filepath);
if ($includedirs) {
- $sql = "SELECT *
- FROM {files}
- WHERE contextid = :contextid AND component = :component AND filearea = :filearea
- AND itemid = :itemid AND filename = '.'
- AND ".$DB->sql_substr("filepath", 1, $length)." = :filepath
- AND id <> :dirid
+ $sql = "SELECT f.*, r.repositoryid, r.reference
+ FROM {files} f
+ LEFT JOIN {files_reference} r
+ ON f.referencefileid = r.id
+ WHERE f.contextid = :contextid AND f.component = :component AND f.filearea = :filearea
+ AND f.itemid = :itemid AND f.filename = '.'
+ AND ".$DB->sql_substr("f.filepath", 1, $length)." = :filepath
+ AND f.id <> :dirid
ORDER BY $sort";
$reqlevel = substr_count($filepath, '/') + 1;
$filerecords = $DB->get_records_sql($sql, $params);
@@ -549,10 +553,12 @@ public function get_directory_files($contextid, $component, $filearea, $itemid,
}
}
- $sql = "SELECT *
- FROM {files}
- WHERE contextid = :contextid AND component = :component AND filearea = :filearea AND itemid = :itemid
- AND filepath = :filepath AND filename <> '.'
+ $sql = "SELECT f.*, r.repositoryid, r.reference
+ FROM {files} f
+ LEFT JOIN {files_reference} r
+ ON f.referencefileid = r.id
+ WHERE f.contextid = :contextid AND f.component = :component AND f.filearea = :filearea AND f.itemid = :itemid
+ AND f.filepath = :filepath AND f.filename <> '.'
ORDER BY $sort";
$filerecords = $DB->get_records_sql($sql, $params);
View
1 repository/coursefiles/lib.php
@@ -240,6 +240,7 @@ public function get_file_reference($source) {
* @return stdClass|null|false
*/
public function get_file_by_reference($reference) {
+ $fs = get_file_storage();
$ref = $reference->reference;
$params = file_storage::unpack_reference($ref);
if (!is_array($params)) {

0 comments on commit 462c495

Please sign in to comment.