示例#1
0
 /**
  * Converts file_info object to element of repository return path
  *
  * @param file_info $fileinfo
  * @return array
  */
 private function get_node_path(file_info $fileinfo)
 {
     $encodedpath = base64_encode(json_encode($fileinfo->get_params()));
     return array('path' => $encodedpath, 'name' => $fileinfo->get_visible_name());
 }
示例#2
0
 /**
  * Constructor of moodle_file_tree_viewer class
  * @param file_info $file_info
  * @param array $options
  */
 public function __construct(file_info $file_info, array $options = null)
 {
     global $CFG;
     //note: this MUST NOT use get_file_storage() !!!!!!!!!!!!!!!!!!!!!!!!!!!!
     $this->options = (array) $options;
     $this->context = $options['context'];
     $this->tree = array();
     $children = $file_info->get_children();
     $current_file_params = $file_info->get_params();
     $parent_info = $file_info->get_parent();
     $level = $parent_info;
     $this->path = array();
     while ($level) {
         $params = $level->get_params();
         $context = context::instance_by_id($params['contextid']);
         // $this->context is current context
         if ($context->id != $this->context->id or empty($params['filearea'])) {
             break;
         }
         // unset unused parameters
         unset($params['component']);
         unset($params['filearea']);
         unset($params['filename']);
         unset($params['itemid']);
         $url = new moodle_url('/files/index.php', $params);
         $this->path[] = html_writer::link($url, $level->get_visible_name());
         $level = $level->get_parent();
     }
     $this->path = array_reverse($this->path);
     if ($current_file_params['filepath'] != '/') {
         $this->path[] = $file_info->get_visible_name();
     }
     foreach ($children as $child) {
         $filedate = $child->get_timemodified();
         $filesize = $child->get_filesize();
         $mimetype = $child->get_mimetype();
         $params = $child->get_params();
         unset($params['component']);
         unset($params['filearea']);
         unset($params['filename']);
         unset($params['itemid']);
         $fileitem = array('params' => $params, 'filename' => $child->get_visible_name(), 'mimetype' => $child->get_mimetype(), 'filedate' => $filedate ? $filedate : '', 'filesize' => $filesize ? $filesize : '');
         $url = new moodle_url('/files/index.php', $params);
         if ($child->is_directory()) {
             $fileitem['isdir'] = true;
             $fileitem['url'] = $url->out(false);
         } else {
             $fileitem['url'] = $child->get_url();
         }
         $this->tree[] = $fileitem;
     }
 }