Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-33746 make folder view look like filemanager tree view

  • Loading branch information...
commit 9b47ec7bb3899a0fd1b4df5610e48a47b92c246e 1 parent b9c2095
@marinaglancy marinaglancy authored stronk7 committed
Showing with 20 additions and 5 deletions.
  1. +20 −5 mod/folder/renderer.php
View
25 mod/folder/renderer.php
@@ -41,8 +41,8 @@ public function folder_tree($folder, $cm, $course) {
public function render_folder_tree(folder_tree $tree) {
global $PAGE;
- echo '<div id="folder_tree">';
- echo $this->htmllize_tree($tree, $tree->dir);
+ echo '<div id="folder_tree" class="filemanager">';
+ echo $this->htmllize_tree($tree, array('files' => array(), 'subdirs' => array($tree->dir)));
echo '</div>';
$this->page->requires->js_init_call('M.mod_folder.init_tree', array(true));
}
@@ -56,14 +56,29 @@ protected function htmllize_tree($tree, $dir) {
if (empty($dir['subdirs']) and empty($dir['files'])) {
return '';
}
+ $browser = get_file_browser();
$result = '<ul>';
foreach ($dir['subdirs'] as $subdir) {
- $result .= '<li>'.s($subdir['dirname']).' '.$this->htmllize_tree($tree, $subdir).'</li>';
+ $image = $this->output->pix_icon(file_folder_icon(24), $subdir['dirname'], 'moodle');
+ $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', s($subdir['dirname']), array('class' => 'fp-filename'));
+ $filename = html_writer::tag('div', $filename, array('class' => 'fp-filename-icon'));
+ $result .= html_writer::tag('li', $filename. $this->htmllize_tree($tree, $subdir));
}
foreach ($dir['files'] as $file) {
- $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/mod_folder/content/'.$tree->folder->revision.$file->get_filepath().$file->get_filename(), true);
+ $fileinfo = $browser->get_file_info($tree->context, $file->get_component(),
+ $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
+ $url = $fileinfo->get_url(true);
$filename = $file->get_filename();
- $result .= '<li><span>'.html_writer::link($url, $filename).'</span></li>';
+ if ($imageinfo = $fileinfo->get_imageinfo()) {
+ $fileurl = new moodle_url($fileinfo->get_url());
+ $image = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $fileinfo->get_timemodified()));
+ $image = html_writer::empty_tag('img', array('src' => $image));
+ } else {
+ $image = $this->output->pix_icon(file_file_icon($file, 24), $filename, 'moodle');
+ }
+ $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', $filename, array('class' => 'fp-filename'));
+ $filename = html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'fp-filename-icon'));
+ $result .= html_writer::tag('li', $filename);
}
$result .= '</ul>';
Please sign in to comment.
Something went wrong with that request. Please try again.