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() {
|
function GET_folder() {
|
||||||
list($folder_id) = input('i:folder_id');
|
list($folder_id) = input('i:folder_id');
|
||||||
$folder = books_get_folder($folder_id);
|
$parents = books_get_folder($folder_id, true);
|
||||||
if (!$folder)
|
if (!$parents)
|
||||||
not_found();
|
not_found();
|
||||||
|
if (count($parents) > 1)
|
||||||
|
$parents = array_reverse($parents);
|
||||||
|
$folder = $parents[count($parents)-1];
|
||||||
$files = books_get($folder_id, category: $folder->category);
|
$files = books_get($folder_id, category: $folder->category);
|
||||||
add_meta([
|
add_meta([
|
||||||
'$title' => lang('meta_files_book_folder_title', $folder->getTitle()),
|
'$title' => lang('meta_files_book_folder_title', $folder->getTitle()),
|
||||||
@ -36,6 +39,7 @@ class FilesHandler extends request_handler {
|
|||||||
set_title(lang('files').' - '.$folder->title);
|
set_title(lang('files').' - '.$folder->title);
|
||||||
render('files/folder',
|
render('files/folder',
|
||||||
folder: $folder,
|
folder: $folder,
|
||||||
|
parents: $parents,
|
||||||
files: $files);
|
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));
|
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();
|
$db = DB();
|
||||||
$q = $db->query("SELECT * FROM books WHERE id=?", $id);
|
$q = $db->query("SELECT * FROM books WHERE id=?", $id);
|
||||||
if (!$db->numRows($q))
|
if (!$db->numRows($q))
|
||||||
@ -722,5 +722,14 @@ function books_get_folder(int $id): ?BookItem {
|
|||||||
$item = new BookItem($db->fetch($q));
|
$item = new BookItem($db->fetch($q));
|
||||||
if (!$item->isFolder())
|
if (!$item->isFolder())
|
||||||
return null;
|
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;
|
return $item;
|
||||||
}
|
}
|
||||||
|
@ -44,16 +44,28 @@ return <<<HTML
|
|||||||
HTML;
|
HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
function folder($ctx, BookItem $folder, array $files) {
|
function folder($ctx, BookItem $folder, array $files, ?array $parents) {
|
||||||
$svg = svg();
|
$svg = svg();
|
||||||
$svg->folder_20(preload_symbol: true);
|
$svg->folder_20(preload_symbol: true);
|
||||||
$svg->file_20(preload_symbol: true);
|
$svg->file_20(preload_symbol: true);
|
||||||
|
|
||||||
return <<<HTML
|
$bc = [
|
||||||
{$ctx->bc([
|
|
||||||
['text' => $ctx->lang('files'), 'url' => '/files/'],
|
['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 class="files-list">
|
||||||
<div id="files_list">
|
<div id="files_list">
|
||||||
{$ctx->collection_files($files)}
|
{$ctx->collection_files($files)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user