Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-34748 repository_filesystem: Sort files by title by default

  • Loading branch information...
commit b56249893d33c084044d91495bbc808054c75eb2 1 parent c36de79
Marina Glancy marinaglancy authored
Showing with 31 additions and 19 deletions.
  1. +31 −19 repository/filesystem/lib.php
50 repository/filesystem/lib.php
View
@@ -75,33 +75,45 @@ public function get_listing($path = '', $page = '') {
$list['dynload'] = true;
$list['nologin'] = true;
$list['nosearch'] = true;
+ // retrieve list of files and directories and sort them
+ $fileslist = array();
+ $dirslist = array();
if ($dh = opendir($this->root_path)) {
while (($file = readdir($dh)) != false) {
if ( $file != '.' and $file !='..') {
- if (filetype($this->root_path.$file) == 'file') {
- $list['list'][] = array(
- 'title' => $file,
- 'source' => $path.'/'.$file,
- 'size' => filesize($this->root_path.$file),
- 'date' => time(),
- 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($this->root_path.$file, 32))->out(false)
- );
+ if (is_file($this->root_path.$file)) {
+ $fileslist[] = $file;
} else {
- if (!empty($path)) {
- $current_path = $path . '/'. $file;
- } else {
- $current_path = $file;
- }
- $list['list'][] = array(
- 'title' => $file,
- 'children' => array(),
- 'thumbnail' => $OUTPUT->pix_url('f/folder-32')->out(false),
- 'path' => $current_path
- );
+ $dirslist[] = $file;
}
}
}
}
+ collatorlib::asort($fileslist);
+ collatorlib::asort($dirslist);
+ // fill the $list['list']
+ foreach ($dirslist as $file) {
+ if (!empty($path)) {
+ $current_path = $path . '/'. $file;
+ } else {
+ $current_path = $file;
+ }
+ $list['list'][] = array(
+ 'title' => $file,
+ 'children' => array(),
+ 'thumbnail' => $OUTPUT->pix_url('f/folder-32')->out(false),
+ 'path' => $current_path
+ );
+ }
+ foreach ($fileslist as $file) {
+ $list['list'][] = array(
+ 'title' => $file,
+ 'source' => $path.'/'.$file,
+ 'size' => filesize($this->root_path.$file),
+ 'date' => time(),
+ 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($this->root_path.$file, 32))->out(false)
+ );
+ }
$list['list'] = array_filter($list['list'], array($this, 'filter'));
return $list;
}
Please sign in to comment.
Something went wrong with that request. Please try again.