bookstack/app/Http/Controllers/AttributeController.php

65 lines
1.8 KiB
PHP
Raw Normal View History

2016-05-07 03:33:08 +08:00
<?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);
2016-05-07 03:33:08 +08:00
}
/**
* 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);
2016-05-13 06:12:05 +08:00
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);
}
2016-05-07 03:33:08 +08:00
}