mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Merge branch 'master' into PHRAS-3644-1.1.6-rc1
This commit is contained in:
76
lib/Alchemy/Phrasea/Controller/Api/V3/V3Controller.php
Normal file
76
lib/Alchemy/Phrasea/Controller/Api/V3/V3Controller.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Controller\Api\V3;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Controller\Api\Result;
|
||||||
|
use Alchemy\Phrasea\Controller\Controller;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
class V3Controller extends Controller
|
||||||
|
{
|
||||||
|
public function getDataboxSubdefsAction(Request $request)
|
||||||
|
{
|
||||||
|
if (!empty($request->attributes->get('databox_id'))) {
|
||||||
|
$ret = [
|
||||||
|
'databoxes' => $this->listSubdefsStructure([$this->findDataboxById($request->attributes->get('databox_id'))])
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$acl = $this->getAclForUser($this->getAuthenticatedUser());
|
||||||
|
|
||||||
|
// ensure can see databox structure
|
||||||
|
$ret = [
|
||||||
|
'databoxes' => $this->listSubdefsStructure($acl->get_granted_sbas([\ACL::BAS_MODIFY_STRUCT]))
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result::create($request, $ret)->createResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List the subdef structure of databoxes
|
||||||
|
* @param array $databoxes
|
||||||
|
* @return array
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
private function listSubdefsStructure(array $databoxes)
|
||||||
|
{
|
||||||
|
$ret = [];
|
||||||
|
|
||||||
|
/** @var \databox $databox */
|
||||||
|
foreach ($databoxes as $databox) {
|
||||||
|
$databoxId = $databox->get_sbas_id();
|
||||||
|
$subdefStructure = $databox->get_subdef_structure();
|
||||||
|
$subdefs = [];
|
||||||
|
foreach ($subdefStructure as $subGroup) {
|
||||||
|
/** @var \databox_subdef $sub */
|
||||||
|
foreach ($subGroup->getIterator() as $sub) {
|
||||||
|
$opt = [];
|
||||||
|
$data = [
|
||||||
|
'name' => $sub->get_name(),
|
||||||
|
'databox_id' => $databoxId,
|
||||||
|
'class' => $sub->get_class(),
|
||||||
|
'preset' => $sub->get_preset(),
|
||||||
|
'downloadable' => $sub->isDownloadable(),
|
||||||
|
'devices' => $sub->getDevices(),
|
||||||
|
'labels' => [
|
||||||
|
'fr' => $sub->get_label('fr'),
|
||||||
|
'en' => $sub->get_label('en'),
|
||||||
|
'de' => $sub->get_label('de'),
|
||||||
|
'nl' => $sub->get_label('nl'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$options = $sub->getOptions();
|
||||||
|
foreach ($options as $option) {
|
||||||
|
$opt[$option->getName()] = $option->getValue();
|
||||||
|
}
|
||||||
|
$data['options'] = $opt;
|
||||||
|
$subdefs[$subGroup->getName()][$sub->get_name()] = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$ret[$databoxId]['databox_id'] = $databoxId;
|
||||||
|
$ret[$databoxId]['subdefs'] = $subdefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
@@ -4,6 +4,7 @@ namespace Alchemy\Phrasea\ControllerProvider\Api;
|
|||||||
|
|
||||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Alchemy\Phrasea\Controller\Api\V1Controller;
|
use Alchemy\Phrasea\Controller\Api\V1Controller;
|
||||||
|
use Alchemy\Phrasea\Controller\Api\V3\V3Controller;
|
||||||
use Alchemy\Phrasea\Controller\Api\V3\V3RecordController;
|
use Alchemy\Phrasea\Controller\Api\V3\V3RecordController;
|
||||||
use Alchemy\Phrasea\Controller\Api\V3\V3ResultHelpers;
|
use Alchemy\Phrasea\Controller\Api\V3\V3ResultHelpers;
|
||||||
use Alchemy\Phrasea\Controller\Api\V3\V3SearchController;
|
use Alchemy\Phrasea\Controller\Api\V3\V3SearchController;
|
||||||
@@ -53,6 +54,9 @@ class V3 extends Api implements ControllerProviderInterface, ServiceProviderInte
|
|||||||
$app['controller.api.v3.stories'] = $app->share(function (PhraseaApplication $app) {
|
$app['controller.api.v3.stories'] = $app->share(function (PhraseaApplication $app) {
|
||||||
return (new V3StoriesController($app));
|
return (new V3StoriesController($app));
|
||||||
});
|
});
|
||||||
|
$app['controller.api.v3'] = $app->share(function (PhraseaApplication $app) {
|
||||||
|
return (new V3Controller($app));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(Application $app)
|
public function boot(Application $app)
|
||||||
@@ -150,6 +154,16 @@ class V3 extends Api implements ControllerProviderInterface, ServiceProviderInte
|
|||||||
$controllers->post('/subdefs_service/', 'controller.api.v3.subdefs_service:indexAction_POST');
|
$controllers->post('/subdefs_service/', 'controller.api.v3.subdefs_service:indexAction_POST');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @uses V3Controller::getDataboxSubdefsAction()
|
||||||
|
*/
|
||||||
|
$controllers->get('/databoxes/{databox_id}/subdefs/', 'controller.api.v3:getDataboxSubdefsAction')
|
||||||
|
->before('controller.api.v1:ensureAccessToDatabox')
|
||||||
|
->before('controller.api.v1:ensureCanSeeDataboxStructure')
|
||||||
|
->assert('databox_id', '\d+');
|
||||||
|
|
||||||
|
$controllers->get('/databoxes/subdefs/', 'controller.api.v3:getDataboxSubdefsAction');
|
||||||
|
|
||||||
return $controllers;
|
return $controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user