files: support multiple folder parents in breadcrumbs
This commit is contained in:
parent
d287efc184
commit
e2b5031443
@ -25,9 +25,12 @@ class FilesHandler extends request_handler {
|
||||
|
||||
function GET_folder() {
|
||||
list($folder_id) = input('i:folder_id');
|
||||
$folder = books_get_folder($folder_id);
|
||||
if (!$folder)
|
||||
$parents = books_get_folder($folder_id, true);
|
||||
if (!$parents)
|
||||
not_found();
|
||||
if (count($parents) > 1)
|
||||
$parents = array_reverse($parents);
|
||||
$folder = $parents[count($parents)-1];
|
||||
$files = books_get($folder_id, category: $folder->category);
|
||||
add_meta([
|
||||
'$title' => lang('meta_files_book_folder_title', $folder->getTitle()),
|
||||
@ -36,6 +39,7 @@ class FilesHandler extends request_handler {
|
||||
set_title(lang('files').' - '.$folder->title);
|
||||
render('files/folder',
|
||||
folder: $folder,
|
||||
parents: $parents,
|
||||
files: $files);
|
||||
}
|
||||
|
||||
|
@ -714,7 +714,7 @@ function books_get(int $parent_id = 0, BookCategory $category = BookCategory::BO
|
||||
return array_map('BookItem::create_instance', $db->fetchAll($q));
|
||||
}
|
||||
|
||||
function books_get_folder(int $id): ?BookItem {
|
||||
function books_get_folder(int $id, bool $with_parents = false): BookItem|array|null {
|
||||
$db = DB();
|
||||
$q = $db->query("SELECT * FROM books WHERE id=?", $id);
|
||||
if (!$db->numRows($q))
|
||||
@ -722,5 +722,14 @@ function books_get_folder(int $id): ?BookItem {
|
||||
$item = new BookItem($db->fetch($q));
|
||||
if (!$item->isFolder())
|
||||
return null;
|
||||
if ($with_parents) {
|
||||
$items = [$item];
|
||||
if ($item->parentId) {
|
||||
$parents = books_get_folder($item->parentId, true);
|
||||
if ($parents !== null)
|
||||
$items = array_merge($items, $parents);
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
@ -44,16 +44,28 @@ return <<<HTML
|
||||
HTML;
|
||||
}
|
||||
|
||||
function folder($ctx, BookItem $folder, array $files) {
|
||||
function folder($ctx, BookItem $folder, array $files, ?array $parents) {
|
||||
$svg = svg();
|
||||
$svg->folder_20(preload_symbol: true);
|
||||
$svg->file_20(preload_symbol: true);
|
||||
|
||||
return <<<HTML
|
||||
{$ctx->bc([
|
||||
$bc = [
|
||||
['text' => $ctx->lang('files'), 'url' => '/files/'],
|
||||
['text' => $folder->title]
|
||||
])}
|
||||
];
|
||||
|
||||
if ($parents) {
|
||||
for ($i = 0; $i < count($parents)-1; $i++) {
|
||||
$parent = $parents[$i];
|
||||
$bc_item = ['text' => $parent->getTitle()];
|
||||
if ($i < count($parents)-1)
|
||||
$bc_item['url'] = $parent->getUrl();
|
||||
$bc[] = $bc_item;
|
||||
}
|
||||
}
|
||||
$bc[] = ['text' => $folder->title];
|
||||
|
||||
return <<<HTML
|
||||
{$ctx->bc($bc)}
|
||||
<div class="files-list">
|
||||
<div id="files_list">
|
||||
{$ctx->collection_files($files)}
|
||||
|
Loading…
x
Reference in New Issue
Block a user