BookStack/app/Entities/Controllers/PageTemplateController.php

59 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2023-05-18 00:56:55 +08:00
namespace BookStack\Entities\Controllers;
use BookStack\Entities\Repos\PageRepo;
use BookStack\Exceptions\NotFoundException;
2023-05-18 00:56:55 +08:00
use BookStack\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PageTemplateController extends Controller
{
protected $pageRepo;
/**
2021-06-26 23:23:15 +08:00
* PageTemplateController constructor.
*/
public function __construct(PageRepo $pageRepo)
{
$this->pageRepo = $pageRepo;
}
/**
* Fetch a list of templates from the system.
*/
public function list(Request $request)
{
$page = $request->get('page', 1);
$search = $request->get('search', '');
$templates = $this->pageRepo->getTemplates(10, $page, $search);
if ($search) {
$templates->appends(['search' => $search]);
}
return view('pages.parts.template-manager-list', [
2021-06-26 23:23:15 +08:00
'templates' => $templates,
]);
}
/**
* Get the content of a template.
2021-06-26 23:23:15 +08:00
*
* @throws NotFoundException
*/
public function get(int $templateId)
{
$page = $this->pageRepo->getById($templateId);
if (!$page->template) {
throw new NotFoundException();
}
return response()->json([
2021-06-26 23:23:15 +08:00
'html' => $page->html,
'markdown' => $page->markdown,
]);
}
}