mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 03:23:19 +00:00
Merge pull request #1425 from aztech-dev/api-collections-4.0
Add API get collection route
This commit is contained in:
@@ -92,6 +92,7 @@ return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) {
|
|||||||
if ($request->getRequestFormat(Result::FORMAT_JSON) === Result::FORMAT_JSONP && !$response->isOk() && !$response->isServerError()) {
|
if ($request->getRequestFormat(Result::FORMAT_JSON) === Result::FORMAT_JSONP && !$response->isOk() && !$response->isServerError()) {
|
||||||
$response->setStatusCode(200);
|
$response->setStatusCode(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set response content type
|
// set response content type
|
||||||
if (!$response->headers->get('Content-Type')) {
|
if (!$response->headers->get('Content-Type')) {
|
||||||
$response->headers->set('Content-Type', $request->getMimeType($request->getRequestFormat(Result::FORMAT_JSON)));
|
$response->headers->set('Content-Type', $request->getMimeType($request->getRequestFormat(Result::FORMAT_JSON)));
|
||||||
|
@@ -462,6 +462,13 @@ class V1Controller extends Controller
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDataboxCollectionAction(Request $request, $base_id)
|
||||||
|
{
|
||||||
|
return Result::create($request, [
|
||||||
|
$this->listCollection($this->app->getApplicationBox()->get_collection($base_id))
|
||||||
|
])->createResponse();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a Response containing the collections of a \databox
|
* Get a Response containing the collections of a \databox
|
||||||
*
|
*
|
||||||
|
@@ -72,6 +72,8 @@ class V1 implements ControllerProviderInterface, ServiceProviderInterface
|
|||||||
$controllers->get('/monitor/phraseanet/', 'controller.api.v1:showPhraseanetConfigurationAction')
|
$controllers->get('/monitor/phraseanet/', 'controller.api.v1:showPhraseanetConfigurationAction')
|
||||||
->before('controller.api.v1:ensureAdmin');
|
->before('controller.api.v1:ensureAdmin');
|
||||||
|
|
||||||
|
$controllers->get('/collections/{base_id}/', 'controller.api.v1:getDataboxCollectionAction');
|
||||||
|
|
||||||
$controllers->get('/databoxes/list/', 'controller.api.v1:listDataboxesAction');
|
$controllers->get('/databoxes/list/', 'controller.api.v1:listDataboxesAction');
|
||||||
|
|
||||||
$controllers->get('/databoxes/{databox_id}/collections/', 'controller.api.v1:getDataboxCollectionsAction')
|
$controllers->get('/databoxes/{databox_id}/collections/', 'controller.api.v1:getDataboxCollectionsAction')
|
||||||
|
@@ -268,6 +268,26 @@ class appbox extends base
|
|||||||
return $databoxes[$sbas_id];
|
return $databoxes[$sbas_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_collection($base_id)
|
||||||
|
{
|
||||||
|
$sbas_id = phrasea::sbasFromBas($this->app, $base_id);
|
||||||
|
|
||||||
|
if ($sbas_id === false) {
|
||||||
|
throw new \RuntimeException('Collection not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$collections = $this->get_databox($sbas_id)->get_collections();
|
||||||
|
|
||||||
|
foreach ($collections as $collection) {
|
||||||
|
if ($collection->get_base_id() == $base_id) {
|
||||||
|
return $collection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This should not happen, but I'd rather be safe than sorry.
|
||||||
|
throw new \RuntimeException('Collection not found.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $option
|
* @param string $option
|
||||||
* @return string
|
* @return string
|
||||||
|
Reference in New Issue
Block a user