Пример #1
0
 /**
  * Given a filesystem directory and the artefact data corresponding to that 
  * directory, creates an index.html for it.
  *
  * @param string $filesystemdirectory The file system directory to make the 
  *                                    index.html inside
  * @param int    $level               How deep this directory index is
  * @param object $artefactdata        Artefact data relating to the folder 
  *                                    represented by this directory
  */
 private function create_index_for_directory($filesystemdirectory, $level, ArtefactTypeFolder $artefact = null)
 {
     $smarty = $this->exporter->get_smarty(str_repeat('../', $level + 2), 'file');
     $smarty->assign('page_heading', get_string('Files', 'artefact.file'));
     $smarty->assign('breadcrumbs', array(array('text' => 'Files', 'path' => 'index.html')));
     if ($artefact) {
         $smarty->assign('folder', ArtefactTypeFileBase::get_full_path($artefact->get('id'), $this->artefactdata));
     } else {
         $smarty->assign('folder', '/');
     }
     $id = $artefact ? $artefact->get('id') : null;
     $smarty->assign('folders', $this->prepare_artefacts_for_smarty($id, true));
     $smarty->assign('files', $this->prepare_artefacts_for_smarty($id, false));
     $content = $smarty->fetch('export:html/file:index.tpl');
     if (false === file_put_contents($filesystemdirectory . 'index.html', $content)) {
         throw new SystemException("Unable to create index.html for directory {$id}");
     }
 }
Пример #2
0
 /**
  * Given a file, returns the folder path for it in the Mahara files area
  *
  * The path is pre-sanitised so it can be used when generating the export
  *
  * @param  $file The file or folder to get the folder path for
  * @return string
  */
 private function get_folder_path_for_file($file)
 {
     if ($this->folderdata === null) {
         $this->folderdata = get_records_select_assoc('artefact', "artefacttype = 'folder' AND owner = ?", array($file->get('owner')));
         if ($this->folderdata) {
             foreach ($this->folderdata as &$folder) {
                 $folder->title = PluginExportHtml::sanitise_path($folder->title);
             }
         }
     }
     $folderpath = ArtefactTypeFileBase::get_full_path($file->get('parent'), $this->folderdata);
     return $folderpath;
 }
Пример #3
0
 /**
  * Optional method. If specified, allows the blocktype class to munge the
  * artefactchooser element data before it's templated
  */
 public static function artefactchooser_get_element_data($artefact)
 {
     $folderdata = ArtefactTypeFileBase::artefactchooser_folder_data($artefact);
     $artefact->icon = call_static_method(generate_artefact_class_name($artefact->artefacttype), 'get_icon', array('id' => $artefact->id));
     $artefact->hovertitle = $artefact->description;
     $path = $artefact->parent ? ArtefactTypeFileBase::get_full_path($artefact->parent, $folderdata->data) : '';
     $artefact->description = str_shorten_text($folderdata->ownername . $path . $artefact->title, 30);
     return $artefact;
 }
Пример #4
0
 public function unzip_directory_name()
 {
     if (isset($this->data['unzipdir'])) {
         return $this->data['unzipdir'];
     }
     $folderdata = ArtefactTypeFileBase::artefactchooser_folder_data($this);
     $parent = $this->get('parent');
     $strpath = ArtefactTypeFileBase::get_full_path($parent, $folderdata->data);
     $extn = $this->get('oldextension');
     $name = $this->get('title');
     if (substr($name, -1 - strlen($extn)) == '.' . $extn) {
         $name = substr($name, 0, strlen($name) - 1 - strlen($extn));
     }
     $name = ArtefactTypeFileBase::get_new_file_title($name, $parent, $this->get('owner'), $this->get('group'), $this->get('institution'));
     $this->data['unzipdir'] = array('basename' => $name, 'fullname' => $strpath . $name);
     return $this->data['unzipdir'];
 }