mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-26 02:10:19 +08:00
bf591765c1
Also introduced helpers for getting entities by slugs since we do it in so many places.
76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Http\Controllers;
|
|
|
|
use BookStack\Entities\Models\Book;
|
|
use BookStack\Entities\Models\Bookshelf;
|
|
use BookStack\Entities\Models\Chapter;
|
|
use BookStack\Entities\Models\Page;
|
|
use BookStack\References\ReferenceFetcher;
|
|
|
|
class ReferenceController extends Controller
|
|
{
|
|
protected ReferenceFetcher $referenceFetcher;
|
|
|
|
public function __construct(ReferenceFetcher $referenceFetcher)
|
|
{
|
|
$this->referenceFetcher = $referenceFetcher;
|
|
}
|
|
|
|
/**
|
|
* Display the references to a given page.
|
|
*/
|
|
public function page(string $bookSlug, string $pageSlug)
|
|
{
|
|
$page = Page::getBySlugs($bookSlug, $pageSlug);
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($page);
|
|
|
|
return view('pages.references', [
|
|
'page' => $page,
|
|
'references' => $references,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Display the references to a given chapter.
|
|
*/
|
|
public function chapter(string $bookSlug, string $chapterSlug)
|
|
{
|
|
$chapter = Chapter::getBySlugs($bookSlug, $chapterSlug);
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($chapter);
|
|
|
|
return view('chapters.references', [
|
|
'chapter' => $chapter,
|
|
'references' => $references,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Display the references to a given book.
|
|
*/
|
|
public function book(string $slug)
|
|
{
|
|
$book = Book::getBySlug($slug);
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($book);
|
|
|
|
return view('books.references', [
|
|
'book' => $book,
|
|
'references' => $references,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Display the references to a given shelf.
|
|
*/
|
|
public function shelf(string $slug)
|
|
{
|
|
$shelf = Bookshelf::getBySlug($slug);
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($shelf);
|
|
|
|
return view('shelves.references', [
|
|
'shelf' => $shelf,
|
|
'references' => $references,
|
|
]);
|
|
}
|
|
}
|