]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/AttributeController.php
Started the page attributes interface
[bookstack] / app / Http / Controllers / AttributeController.php
1 <?php namespace BookStack\Http\Controllers;
2
3 use BookStack\Repos\AttributeRepo;
4 use Illuminate\Http\Request;
5 use BookStack\Http\Requests;
6
7 class AttributeController extends Controller
8 {
9
10     protected $attributeRepo;
11
12     /**
13      * AttributeController constructor.
14      * @param $attributeRepo
15      */
16     public function __construct(AttributeRepo $attributeRepo)
17     {
18         $this->attributeRepo = $attributeRepo;
19     }
20
21     /**
22      * Get all the Attributes for a particular entity
23      * @param $entityType
24      * @param $entityId
25      */
26     public function getForEntity($entityType, $entityId)
27     {
28         $attributes = $this->attributeRepo->getForEntity($entityType, $entityId);
29         return response()->json($attributes);
30     }
31
32     /**
33      * Update the attributes for a particular entity.
34      * @param $entityType
35      * @param $entityId
36      * @param Request $request
37      * @return mixed
38      */
39     public function updateForEntity($entityType, $entityId, Request $request)
40     {
41         $entity = $this->attributeRepo->getEntity($entityType, $entityId, 'update');
42         if ($entity === null) return $this->jsonError("Entity not found", 404);
43
44         $inputAttributes = $request->input('attributes');
45         $attributes = $this->attributeRepo->saveAttributesToEntity($entity, $inputAttributes);
46         return response()->json([
47             'attributes' => $attributes,
48             'message' => 'Attributes successfully updated'
49         ]);
50     }
51
52     /**
53      * Get attribute name suggestions from a given search term.
54      * @param Request $request
55      */
56     public function getNameSuggestions(Request $request)
57     {
58         $searchTerm = $request->get('search');
59         $suggestions = $this->attributeRepo->getNameSuggestions($searchTerm);
60         return response()->json($suggestions);
61     }
62
63
64 }