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