]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/TagController.php
aaf0cb9b274e34f7f97b913b390f44e4aee59ede
[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         return view('tags.index', [
36             'tags'   => $tags,
37             'search' => $search,
38             'nameFilter' => $nameFilter,
39         ]);
40     }
41
42     /**
43      * Get tag name suggestions from a given search term.
44      */
45     public function getNameSuggestions(Request $request)
46     {
47         $searchTerm = $request->get('search', null);
48         $suggestions = $this->tagRepo->getNameSuggestions($searchTerm);
49
50         return response()->json($suggestions);
51     }
52
53     /**
54      * Get tag value suggestions from a given search term.
55      */
56     public function getValueSuggestions(Request $request)
57     {
58         $searchTerm = $request->get('search', null);
59         $tagName = $request->get('name', null);
60         $suggestions = $this->tagRepo->getValueSuggestions($searchTerm, $tagName);
61
62         return response()->json($suggestions);
63     }
64 }