2022-08-19 20:14:43 +08:00
|
|
|
<?php
|
|
|
|
|
2023-05-18 00:56:55 +08:00
|
|
|
namespace BookStack\References;
|
2022-08-19 20:14:43 +08:00
|
|
|
|
2022-08-20 05:40:44 +08:00
|
|
|
use BookStack\Entities\Models\Book;
|
|
|
|
use BookStack\Entities\Models\Bookshelf;
|
|
|
|
use BookStack\Entities\Models\Chapter;
|
2022-08-19 20:14:43 +08:00
|
|
|
use BookStack\Entities\Models\Page;
|
2023-05-18 00:56:55 +08:00
|
|
|
use BookStack\Http\Controllers\Controller;
|
2022-08-19 20:14:43 +08:00
|
|
|
|
|
|
|
class ReferenceController extends Controller
|
|
|
|
{
|
2022-08-20 19:07:38 +08:00
|
|
|
protected ReferenceFetcher $referenceFetcher;
|
2022-08-19 20:14:43 +08:00
|
|
|
|
2022-08-20 19:07:38 +08:00
|
|
|
public function __construct(ReferenceFetcher $referenceFetcher)
|
2022-08-19 20:14:43 +08:00
|
|
|
{
|
2022-08-20 19:07:38 +08:00
|
|
|
$this->referenceFetcher = $referenceFetcher;
|
2022-08-19 20:14:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the references to a given page.
|
|
|
|
*/
|
|
|
|
public function page(string $bookSlug, string $pageSlug)
|
|
|
|
{
|
2022-10-09 23:36:03 +08:00
|
|
|
$page = Page::getBySlugs($bookSlug, $pageSlug);
|
2022-08-20 19:07:38 +08:00
|
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($page);
|
2022-08-19 20:14:43 +08:00
|
|
|
|
2022-08-20 05:40:44 +08:00
|
|
|
return view('pages.references', [
|
2022-08-30 00:46:41 +08:00
|
|
|
'page' => $page,
|
2022-08-20 05:40:44 +08:00
|
|
|
'references' => $references,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the references to a given chapter.
|
|
|
|
*/
|
|
|
|
public function chapter(string $bookSlug, string $chapterSlug)
|
|
|
|
{
|
2022-10-09 23:36:03 +08:00
|
|
|
$chapter = Chapter::getBySlugs($bookSlug, $chapterSlug);
|
2022-08-20 19:07:38 +08:00
|
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($chapter);
|
2022-08-20 05:40:44 +08:00
|
|
|
|
|
|
|
return view('chapters.references', [
|
2022-08-30 00:46:41 +08:00
|
|
|
'chapter' => $chapter,
|
2022-08-20 05:40:44 +08:00
|
|
|
'references' => $references,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the references to a given book.
|
|
|
|
*/
|
|
|
|
public function book(string $slug)
|
|
|
|
{
|
2022-10-09 23:36:03 +08:00
|
|
|
$book = Book::getBySlug($slug);
|
2022-08-20 19:07:38 +08:00
|
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($book);
|
2022-08-20 05:40:44 +08:00
|
|
|
|
|
|
|
return view('books.references', [
|
2022-08-30 00:46:41 +08:00
|
|
|
'book' => $book,
|
2022-08-20 05:40:44 +08:00
|
|
|
'references' => $references,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the references to a given shelf.
|
|
|
|
*/
|
|
|
|
public function shelf(string $slug)
|
|
|
|
{
|
2022-10-09 23:36:03 +08:00
|
|
|
$shelf = Bookshelf::getBySlug($slug);
|
2022-08-20 19:07:38 +08:00
|
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($shelf);
|
2022-08-20 05:40:44 +08:00
|
|
|
|
|
|
|
return view('shelves.references', [
|
2022-08-30 00:46:41 +08:00
|
|
|
'shelf' => $shelf,
|
2022-08-20 05:40:44 +08:00
|
|
|
'references' => $references,
|
|
|
|
]);
|
|
|
|
}
|
2022-08-19 20:14:43 +08:00
|
|
|
}
|