Commit cfb167b9 authored by Nigel McNie's avatar Nigel McNie
Browse files

Beginnings of better display for the file artefact plugin.

parent 2f07bb9f
......@@ -174,15 +174,44 @@ class HtmlExportFile extends HtmlExportArtefactPlugin {
$smarty->assign('folder', '/');
}
$id = ($artefact) ? $artefact->get('id') : 'null';
$smarty->assign('folders', array_filter($this->artefactdata, create_function('$a', 'return $a->get("parent") == ' . $id . ' && $a->get("artefacttype") == "folder";')));
$smarty->assign('files', array_filter($this->artefactdata, create_function('$a', 'return $a->get("parent") == ' . $id . ' && $a->get("artefacttype") != "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");
}
}
/**
* Helper to convert artefacts into smarty-friendly data
*
* @param int $parent The ID of the parent folder for the artefact to
* convert
* @param bool $folders True to get folders, false to get everything but
* folders
*/
private function prepare_artefacts_for_smarty($parent, $folders) {
$data = array();
$equality = ($folders) ? '==' : '!=';
$parent = (is_null($parent)) ? 'null': intval($parent);
$artefacts = array_filter($this->artefactdata,
create_function('$a', 'return $a->get("parent") == ' . $parent . ' && $a->get("artefacttype") ' . $equality . ' "folder";'));
foreach ($artefacts as $artefact) {
$size = $artefact->get('size');
$size = ($size) ? display_size($size) : '';
$data[] = array(
'icon' => '',
'title' => $artefact->get('title'),
'description' => $artefact->get('description'),
'size' => $size,
'date' => strftime(get_string('strftimedaydatetime'), $artefact->get('ctime')),
);
}
return $data;
}
}
?>
{include file="export:html:header.tpl"}
<h2>Index of {$folder}</h2>
<h2>{str tag=Folder section=artefact.file}: {$folder}</h2>
{if $folder != '/'}<p><a href="../index.html">Parent Folder</a>{/if}
{if $files || $folders}
<ul>
{if $folder == '/' && !$folders && !$files}
<p>{str tag=nofilesfound section=artefact.file}</p>
{else}
<table id="files">
<colgroup style="width: 3em;">
<colgroup>
<colgroup>
<colgroup style="width: 3em;">
<colgroup style="width: 3em;">
<tr>
<th></th>
<th>{str tag=Name section=artefact.file}</th>
<th>{str tag=Description section=artefact.file}</th>
<th>{str tag=Size section=artefact.file}</th>
<th>{str tag=Date section=artefact.file}</th>
</tr>
{if $folder != '/'}
<tr>
<td><img src="{$rootpath}static/file/theme/default/static/images/folder.gif" alt="{str tag=Folder section=artefact.file}"></td>
<td><a href="../index.html">{str tag=parentfolder section=artefact.file}</a></td>
<td>{str tag=parentfolder section=artefact.file}</td>
<td></td>
<td></td>
</tr>
{/if}
{foreach from=$folders item=folder}
<li>Folder: <a href="{$folder->get('title')|rawurlencode|escape}/index.html">{$folder->get('title')|escape}</a></li>
<tr>
<td><img src="{$rootpath}static/file/theme/default/static/images/folder.gif" alt="{str tag=Folder section=artefact.file}"></td>
<td><a href="{$folder.title|rawurlencode|escape}/index.html">{$folder.title|escape}</a></td>
<td>{$folder.description|escape}</td>
<td>{$folder.size|escape}</td>
<td>{$folder.ctime|escape}</td>
</tr>
{/foreach}
{foreach from=$files item=file}
<li>File: <a href="{$file->get('title')|rawurlencode|escape}">{$file->get('title')|escape}</a></li>
<tr>
<td><img src="{$rootpath}static/file/theme/default/static/images/file.gif" alt="{str tag=File section=artefact.file}"></td>
<td><a href="{$file.title|rawurlencode|escape}">{$file.title|escape}</a></td>
<td>{$file.description|escape}</td>
<td>{$file.size|escape}</td>
<td>{$file.ctime|escape}</td>
</tr>
{/foreach}
</ul>
{else}
<p>This folder is empty.</p>
</table>
{/if}
{include file="export:html:footer.tpl"}
......@@ -69,6 +69,7 @@ $string['fileinstructions'] = 'Upload your images, documents, or other files for
$string['filethingdeleted'] = '%s deleted';
$string['filewithnameexists'] = 'A file or folder with the name "%s" already exists.';
$string['folder'] = 'Folder';
$string['Folder'] = 'Folder';
$string['Folders'] = 'Folders';
$string['foldercreated'] = 'Folder created';
$string['foldernamerequired'] = 'Please provide a name for the new folder.';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment