]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/TagController.php
e59580b6065a2a816f3a2b6fade8526e62d80ef4
[bookstack] / app / Http / Controllers / TagController.php
1 <?php
2
3 namespace BookStack\Http\Controllers;
4
5 use BookStack\Actions\TagRepo;
6 use Illuminate\Http\Request;
7
8 class TagController extends Controller
9 {
10     protected $tagRepo;
11
12     /**
13      * TagController constructor.
14      */
15     public function __construct(TagRepo $tagRepo)
16     {
17         $this->tagRepo = $tagRepo;
18     }
19
20     /**
21      * Show a listing of existing tags in the system.
22      */
23     public function index(Request $request)
24     {
25         $search = $request->get('search', '');
26         $nameFilter = $request->get('name', '');
27         $tags = $this->tagRepo
28             ->queryWithTotals($search, $nameFilter)
29             ->paginate(50)
30             ->appends(array_filter([
31                 'search' => $search,
32                 'name'   => $nameFilter,
33             ]));
34
35         $this->setPageTitle(trans('entities.tags'));
36
37         return view('tags.index', [
38             'tags'       => $tags,
39             'search'     => $search,
40             'nameFilter' => $nameFilter,
41         ]);
42     }
43
44     /**
45      * Get tag name suggestions from a given search term.
46      */
47     public function getNameSuggestions(Request $request)
48     {
49         $searchTerm = $request->get('search', null);
50         $suggestions = $this->tagRepo->getNameSuggestions($searchTerm);
51
52         return response()->json($suggestions);
53     }
54
55     /**
56      * Get tag value suggestions from a given search term.
57      */
58     public function getValueSuggestions(Request $request)
59     {
60         $searchTerm = $request->get('search', null);
61         $tagName = $request->get('name', null);
62         $suggestions = $this->tagRepo->getValueSuggestions($searchTerm, $tagName);
63
64         return response()->json($suggestions);
65     }
66 }