]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/TagController.php
815d9e8d5c87936d168baf406be87772a6fc3ba1
[bookstack] / app / Http / Controllers / TagController.php
1 <?php namespace BookStack\Http\Controllers;
2
3 use BookStack\Repos\TagRepo;
4 use Illuminate\Http\Request;
5
6 class TagController extends Controller
7 {
8
9     protected $tagRepo;
10
11     /**
12      * TagController constructor.
13      * @param $tagRepo
14      */
15     public function __construct(TagRepo $tagRepo)
16     {
17         $this->tagRepo = $tagRepo;
18         parent::__construct();
19     }
20
21     /**
22      * Get all the Tags for a particular entity
23      * @param $entityType
24      * @param $entityId
25      * @return \Illuminate\Http\JsonResponse
26      */
27     public function getForEntity($entityType, $entityId)
28     {
29         $tags = $this->tagRepo->getForEntity($entityType, $entityId);
30         return response()->json($tags);
31     }
32
33     /**
34      * Get tag name suggestions from a given search term.
35      * @param Request $request
36      * @return \Illuminate\Http\JsonResponse
37      */
38     public function getNameSuggestions(Request $request)
39     {
40         $searchTerm = $request->get('search', false);
41         $suggestions = $this->tagRepo->getNameSuggestions($searchTerm);
42         return response()->json($suggestions);
43     }
44
45     /**
46      * Get tag value suggestions from a given search term.
47      * @param Request $request
48      * @return \Illuminate\Http\JsonResponse
49      */
50     public function getValueSuggestions(Request $request)
51     {
52         $searchTerm = $request->get('search', false);
53         $tagName = $request->get('name', false);
54         $suggestions = $this->tagRepo->getValueSuggestions($searchTerm, $tagName);
55         return response()->json($suggestions);
56     }
57 }