]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/PageTemplateController.php
Added force option for update-url command
[bookstack] / app / Http / Controllers / PageTemplateController.php
1 <?php
2
3 namespace BookStack\Http\Controllers;
4
5 use BookStack\Entities\Repos\PageRepo;
6 use BookStack\Exceptions\NotFoundException;
7 use Illuminate\Http\Request;
8
9 class PageTemplateController extends Controller
10 {
11     protected $pageRepo;
12
13     /**
14      * PageTemplateController constructor.
15      */
16     public function __construct(PageRepo $pageRepo)
17     {
18         $this->pageRepo = $pageRepo;
19     }
20
21     /**
22      * Fetch a list of templates from the system.
23      */
24     public function list(Request $request)
25     {
26         $page = $request->get('page', 1);
27         $search = $request->get('search', '');
28         $templates = $this->pageRepo->getTemplates(10, $page, $search);
29
30         if ($search) {
31             $templates->appends(['search' => $search]);
32         }
33
34         return view('pages.parts.template-manager-list', [
35             'templates' => $templates,
36         ]);
37     }
38
39     /**
40      * Get the content of a template.
41      *
42      * @throws NotFoundException
43      */
44     public function get(int $templateId)
45     {
46         $page = $this->pageRepo->getById($templateId);
47
48         if (!$page->template) {
49             throw new NotFoundException();
50         }
51
52         return response()->json([
53             'html'     => $page->html,
54             'markdown' => $page->markdown,
55         ]);
56     }
57 }