0
0
Fork 0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-04-21 19:42:59 +00:00
BookStackApp_BookStack/app/Http/Controllers/AttributeController.php
2016-05-12 23:12:05 +01:00

64 lines
1.8 KiB
PHP

<?php namespace BookStack\Http\Controllers;
use BookStack\Repos\AttributeRepo;
use Illuminate\Http\Request;
use BookStack\Http\Requests;
class AttributeController extends Controller
{
protected $attributeRepo;
/**
* AttributeController constructor.
* @param $attributeRepo
*/
public function __construct(AttributeRepo $attributeRepo)
{
$this->attributeRepo = $attributeRepo;
}
/**
* Get all the Attributes for a particular entity
* @param $entityType
* @param $entityId
*/
public function getForEntity($entityType, $entityId)
{
$attributes = $this->attributeRepo->getForEntity($entityType, $entityId);
return response()->json($attributes);
}
/**
* Update the attributes for a particular entity.
* @param $entityType
* @param $entityId
* @param Request $request
* @return mixed
*/
public function updateForEntity($entityType, $entityId, Request $request)
{
$entity = $this->attributeRepo->getEntity($entityType, $entityId, 'update');
if ($entity === null) return $this->jsonError("Entity not found", 404);
$inputAttributes = $request->input('attributes');
$attributes = $this->attributeRepo->saveAttributesToEntity($entity, $inputAttributes);
return response()->json([
'attributes' => $attributes,
'message' => 'Attributes successfully updated'
]);
}
/**
* Get attribute name suggestions from a given search term.
* @param Request $request
*/
public function getNameSuggestions(Request $request)
{
$searchTerm = $request->get('search');
$suggestions = $this->attributeRepo->getNameSuggestions($searchTerm);
return response()->json($suggestions);
}
}