MDL-33746 make folder view look like filemanager tree view
authorMarina Glancy <marina@moodle.com>
Thu, 5 Jul 2012 08:50:46 +0000 (16:50 +0800)
committerMarina Glancy <marina@moodle.com>
Thu, 5 Jul 2012 08:50:46 +0000 (16:50 +0800)
mod/folder/renderer.php

index 276765f..539affe 100644 (file)
@@ -41,8 +41,8 @@ class mod_folder_renderer extends plugin_renderer_base {
     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 @@ class mod_folder_renderer extends plugin_renderer_base {
         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>';