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