mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-10-12 10:09:58 +00:00
So that their metadata can be read without having to create instances and fullfill dependancy injection just to list. Also added title to interface prefs page.
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace BookStack\View\ViewBlocks;
|
|
|
|
use BookStack\Entities\Queries\EntityQueries;
|
|
use BookStack\Entities\Queries\QueryRecentlyViewed;
|
|
use BookStack\Entities\Queries\QueryTopFavourites;
|
|
use BookStack\View\ViewBlockInterface;
|
|
use Illuminate\Http\Request;
|
|
|
|
class HomeRecentlyViewedOrRecentBooks implements ViewBlockInterface
|
|
{
|
|
public function __construct(
|
|
protected EntityQueries $queries,
|
|
protected QueryRecentlyViewed $recentlyViewed,
|
|
) {
|
|
}
|
|
|
|
public static function getId(): string
|
|
{
|
|
return 'builtin_home-recently-viewed-or-recent-books';
|
|
}
|
|
|
|
public static function getLabel(): string
|
|
{
|
|
$key = user()->isGuest() ? 'books_recent' : 'my_recently_viewed';
|
|
return trans("entities.{$key}");
|
|
}
|
|
|
|
public function getView(array $viewData): string
|
|
{
|
|
if ($viewData['homeView'] === 'default') {
|
|
return 'home.parts.default-card-recently-viewed-or-recent-books';
|
|
}
|
|
|
|
return 'home.parts.configured-section-recently-viewed-or-recent-books';
|
|
}
|
|
|
|
public function withData(array $viewData): array
|
|
{
|
|
if (user()->isGuest()) {
|
|
$recents = $this->queries->books->visibleForList()
|
|
->orderBy('created_at', 'desc')
|
|
->take(10)
|
|
->get();
|
|
} else {
|
|
$recents = $this->recentlyViewed->run(10, 1);
|
|
}
|
|
|
|
return [
|
|
'recents' => $recents
|
|
];
|
|
}
|
|
}
|