diff --git a/lib/Alchemy/Phrasea/Application/Api.php b/lib/Alchemy/Phrasea/Application/Api.php index 751fb1d484..55aa2e4a06 100644 --- a/lib/Alchemy/Phrasea/Application/Api.php +++ b/lib/Alchemy/Phrasea/Application/Api.php @@ -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()) { $response->setStatusCode(200); } + // set response content type if (!$response->headers->get('Content-Type')) { $response->headers->set('Content-Type', $request->getMimeType($request->getRequestFormat(Result::FORMAT_JSON))); diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php index c2eda48729..90297dcb53 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php @@ -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 * diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php index 845647ebac..fb03b39f89 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Api/V1.php @@ -72,6 +72,8 @@ class V1 implements ControllerProviderInterface, ServiceProviderInterface $controllers->get('/monitor/phraseanet/', 'controller.api.v1:showPhraseanetConfigurationAction') ->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/{databox_id}/collections/', 'controller.api.v1:getDataboxCollectionsAction') diff --git a/lib/classes/appbox.php b/lib/classes/appbox.php index 5934bfab2e..eaac5de92e 100644 --- a/lib/classes/appbox.php +++ b/lib/classes/appbox.php @@ -268,6 +268,26 @@ class appbox extends base 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 * @return string