2022-08-19 08:14:43 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http\Controllers;
|
|
|
|
|
2022-08-19 17:40:44 -04:00
|
|
|
use BookStack\Entities\Models\Book;
|
|
|
|
use BookStack\Entities\Models\Bookshelf;
|
|
|
|
use BookStack\Entities\Models\Chapter;
|
2022-08-19 08:14:43 -04:00
|
|
|
use BookStack\Entities\Models\Page;
|
2022-08-20 07:07:38 -04:00
|
|
|
use BookStack\References\ReferenceFetcher;
|
2022-08-19 08:14:43 -04:00
|
|
|
|
|
|
|
class ReferenceController extends Controller
|
|
|
|
{
|
2022-08-20 07:07:38 -04:00
|
|
|
protected ReferenceFetcher $referenceFetcher;
|
2022-08-19 08:14:43 -04:00
|
|
|
|
2022-08-20 07:07:38 -04:00
|
|
|
public function __construct(ReferenceFetcher $referenceFetcher)
|
2022-08-19 08:14:43 -04:00
|
|
|
{
|
2022-08-20 07:07:38 -04:00
|
|
|
$this->referenceFetcher = $referenceFetcher;
|
2022-08-19 08:14:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the references to a given page.
|
|
|
|
*/
|
|
|
|
public function page(string $bookSlug, string $pageSlug)
|
|
|
|
{
|
|
|
|
/** @var Page $page */
|
|
|
|
$page = Page::visible()->whereSlugs($bookSlug, $pageSlug)->firstOrFail();
|
2022-08-20 07:07:38 -04:00
|
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($page);
|
2022-08-19 08:14:43 -04:00
|
|
|
|
2022-08-19 17:40:44 -04:00
|
|
|
return view('pages.references', [
|
2022-08-29 12:46:41 -04:00
|
|
|
'page' => $page,
|
2022-08-19 17:40:44 -04:00
|
|
|
'references' => $references,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the references to a given chapter.
|
|
|
|
*/
|
|
|
|
public function chapter(string $bookSlug, string $chapterSlug)
|
|
|
|
{
|
|
|
|
/** @var Chapter $chapter */
|
|
|
|
$chapter = Chapter::visible()->whereSlugs($bookSlug, $chapterSlug)->firstOrFail();
|
2022-08-20 07:07:38 -04:00
|
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($chapter);
|
2022-08-19 17:40:44 -04:00
|
|
|
|
|
|
|
return view('chapters.references', [
|
2022-08-29 12:46:41 -04:00
|
|
|
'chapter' => $chapter,
|
2022-08-19 17:40:44 -04:00
|
|
|
'references' => $references,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the references to a given book.
|
|
|
|
*/
|
|
|
|
public function book(string $slug)
|
|
|
|
{
|
|
|
|
$book = Book::visible()->where('slug', '=', $slug)->firstOrFail();
|
2022-08-20 07:07:38 -04:00
|
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($book);
|
2022-08-19 17:40:44 -04:00
|
|
|
|
|
|
|
return view('books.references', [
|
2022-08-29 12:46:41 -04:00
|
|
|
'book' => $book,
|
2022-08-19 17:40:44 -04:00
|
|
|
'references' => $references,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the references to a given shelf.
|
|
|
|
*/
|
|
|
|
public function shelf(string $slug)
|
|
|
|
{
|
|
|
|
$shelf = Bookshelf::visible()->where('slug', '=', $slug)->firstOrFail();
|
2022-08-20 07:07:38 -04:00
|
|
|
$references = $this->referenceFetcher->getPageReferencesToEntity($shelf);
|
2022-08-19 17:40:44 -04:00
|
|
|
|
|
|
|
return view('shelves.references', [
|
2022-08-29 12:46:41 -04:00
|
|
|
'shelf' => $shelf,
|
2022-08-19 17:40:44 -04:00
|
|
|
'references' => $references,
|
|
|
|
]);
|
|
|
|
}
|
2022-08-19 08:14:43 -04:00
|
|
|
}
|