mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 20:13:28 +00:00
Refactor SubdefsController
This commit is contained in:
@@ -12,8 +12,6 @@
|
|||||||
namespace Alchemy\Phrasea;
|
namespace Alchemy\Phrasea;
|
||||||
|
|
||||||
use Alchemy\Geonames\GeonamesServiceProvider;
|
use Alchemy\Geonames\GeonamesServiceProvider;
|
||||||
use Alchemy\Phrasea\ControllerProvider\Admin\Setup;
|
|
||||||
use Alchemy\Phrasea\ControllerProvider\Admin\Subdefs;
|
|
||||||
use Alchemy\Phrasea\ControllerProvider\Admin\TaskManager;
|
use Alchemy\Phrasea\ControllerProvider\Admin\TaskManager;
|
||||||
use Alchemy\Phrasea\ControllerProvider\Client\Root as ClientRoot;
|
use Alchemy\Phrasea\ControllerProvider\Client\Root as ClientRoot;
|
||||||
use Alchemy\Phrasea\ControllerProvider\Prod\BasketController;
|
use Alchemy\Phrasea\ControllerProvider\Prod\BasketController;
|
||||||
@@ -313,6 +311,7 @@ class Application extends SilexApplication
|
|||||||
'Alchemy\Phrasea\ControllerProvider\Admin\Root' => [],
|
'Alchemy\Phrasea\ControllerProvider\Admin\Root' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Admin\SearchEngine' => [],
|
'Alchemy\Phrasea\ControllerProvider\Admin\SearchEngine' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Admin\Setup' => [],
|
'Alchemy\Phrasea\ControllerProvider\Admin\Setup' => [],
|
||||||
|
'Alchemy\Phrasea\ControllerProvider\Admin\Subdefs' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Admin\Users' => [],
|
'Alchemy\Phrasea\ControllerProvider\Admin\Users' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Datafiles' => [],
|
'Alchemy\Phrasea\ControllerProvider\Datafiles' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Lightbox' => [],
|
'Alchemy\Phrasea\ControllerProvider\Lightbox' => [],
|
||||||
@@ -624,7 +623,6 @@ class Application extends SilexApplication
|
|||||||
$this->mount('/developers/', new Developers());
|
$this->mount('/developers/', new Developers());
|
||||||
|
|
||||||
$this->mount('/admin/task-manager', new TaskManager());
|
$this->mount('/admin/task-manager', new TaskManager());
|
||||||
$this->mount('/admin/subdefs', new Subdefs());
|
|
||||||
|
|
||||||
$this->mount('/client/', new ClientRoot());
|
$this->mount('/client/', new ClientRoot());
|
||||||
|
|
||||||
@@ -677,6 +675,7 @@ class Application extends SilexApplication
|
|||||||
'/admin/publications' => 'Alchemy\Phrasea\ControllerProvider\Admin\Feeds',
|
'/admin/publications' => 'Alchemy\Phrasea\ControllerProvider\Admin\Feeds',
|
||||||
'/admin/search-engine' => 'Alchemy\Phrasea\ControllerProvider\Admin\SearchEngine',
|
'/admin/search-engine' => 'Alchemy\Phrasea\ControllerProvider\Admin\SearchEngine',
|
||||||
'/admin/setup' => 'Alchemy\Phrasea\ControllerProvider\Admin\Setup',
|
'/admin/setup' => 'Alchemy\Phrasea\ControllerProvider\Admin\Setup',
|
||||||
|
'/admin/subdefs' => 'Alchemy\Phrasea\ControllerProvider\Admin\Subdefs',
|
||||||
'/admin/users' => 'Alchemy\Phrasea\ControllerProvider\Admin\Users',
|
'/admin/users' => 'Alchemy\Phrasea\ControllerProvider\Admin\Users',
|
||||||
'/datafiles' => 'Alchemy\Phrasea\ControllerProvider\Datafiles',
|
'/datafiles' => 'Alchemy\Phrasea\ControllerProvider\Datafiles',
|
||||||
'/include/minify' => 'Alchemy\Phrasea\ControllerProvider\Minifier',
|
'/include/minify' => 'Alchemy\Phrasea\ControllerProvider\Minifier',
|
||||||
|
118
lib/Alchemy/Phrasea/Controller/Admin/SubdefsController.php
Normal file
118
lib/Alchemy/Phrasea/Controller/Admin/SubdefsController.php
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2015 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Controller\Admin;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Controller\Controller;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
class SubdefsController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param int $sbas_id
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
function indexAction($sbas_id) {
|
||||||
|
$databox = $this->findDataboxById((int) $sbas_id);
|
||||||
|
|
||||||
|
return $this->render('admin/subdefs.html.twig', [
|
||||||
|
'databox' => $databox,
|
||||||
|
'subdefs' => $databox->get_subdef_structure()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param int $sbas_id
|
||||||
|
* @return Response
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
function changeSubdefsAction(Request $request, $sbas_id) {
|
||||||
|
$delete_subdef = $request->request->get('delete_subdef');
|
||||||
|
$toadd_subdef = $request->request->get('add_subdef');
|
||||||
|
$Parmsubdefs = $request->request->get('subdefs', []);
|
||||||
|
|
||||||
|
$databox = $this->findDataboxById((int) $sbas_id);
|
||||||
|
|
||||||
|
$add_subdef = ['class' => null, 'name' => null, 'group' => null];
|
||||||
|
foreach ($add_subdef as $k => $v) {
|
||||||
|
if (!isset($toadd_subdef[$k]) || trim($toadd_subdef[$k]) === '') {
|
||||||
|
unset($add_subdef[$k]);
|
||||||
|
} else {
|
||||||
|
$add_subdef[$k] = $toadd_subdef[$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($delete_subdef) {
|
||||||
|
$delete_subef = explode('_', $delete_subdef, 2);
|
||||||
|
$group = $delete_subef[0];
|
||||||
|
$name = $delete_subef[1];
|
||||||
|
$subdefs = $databox->get_subdef_structure();
|
||||||
|
$subdefs->delete_subdef($group, $name);
|
||||||
|
} elseif (count($add_subdef) === 3) {
|
||||||
|
$subdefs = $databox->get_subdef_structure();
|
||||||
|
|
||||||
|
$group = $add_subdef['group'];
|
||||||
|
/** @var \unicode $unicode */
|
||||||
|
$unicode = $this->app['unicode'];
|
||||||
|
$name = $unicode->remove_nonazAZ09($add_subdef['name'], false);
|
||||||
|
$class = $add_subdef['class'];
|
||||||
|
|
||||||
|
$subdefs->add_subdef($group, $name, $class);
|
||||||
|
} else {
|
||||||
|
$subdefs = $databox->get_subdef_structure();
|
||||||
|
|
||||||
|
foreach ($Parmsubdefs as $post_sub) {
|
||||||
|
$options = [];
|
||||||
|
|
||||||
|
$post_sub_ex = explode('_', $post_sub, 2);
|
||||||
|
|
||||||
|
$group = $post_sub_ex[0];
|
||||||
|
$name = $post_sub_ex[1];
|
||||||
|
|
||||||
|
$class = $request->request->get($post_sub . '_class');
|
||||||
|
$downloadable = $request->request->get($post_sub . '_downloadable');
|
||||||
|
|
||||||
|
$defaults = ['path', 'meta', 'mediatype'];
|
||||||
|
|
||||||
|
foreach ($defaults as $def) {
|
||||||
|
$parm_loc = $request->request->get($post_sub . '_' . $def);
|
||||||
|
|
||||||
|
if ($def == 'meta' && !$parm_loc) {
|
||||||
|
$parm_loc = "no";
|
||||||
|
}
|
||||||
|
|
||||||
|
$options[$def] = $parm_loc;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mediatype = $request->request->get($post_sub . '_mediatype');
|
||||||
|
$media = $request->request->get($post_sub . '_' . $mediatype, []);
|
||||||
|
|
||||||
|
foreach ($media as $option => $value) {
|
||||||
|
|
||||||
|
if ($option == 'resolution' && $mediatype == 'image') {
|
||||||
|
$option = 'dpi';
|
||||||
|
}
|
||||||
|
|
||||||
|
$options[$option] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$labels = $request->request->get($post_sub . '_label', []);
|
||||||
|
|
||||||
|
$subdefs->set_subdef($group, $name, $class, $downloadable, $options, $labels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->app->redirectPath('admin_subdefs_subdef', [
|
||||||
|
'sbas_id' => $databox->get_sbas_id(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@@ -11,115 +11,47 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
namespace Alchemy\Phrasea\ControllerProvider\Admin;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
|
use Alchemy\Phrasea\Controller\Admin\SubdefsController;
|
||||||
|
use Alchemy\Phrasea\Security\Firewall;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
|
use Silex\ControllerCollection;
|
||||||
use Silex\ControllerProviderInterface;
|
use Silex\ControllerProviderInterface;
|
||||||
|
use Silex\ServiceProviderInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
class Subdefs implements ControllerProviderInterface
|
class Subdefs implements ControllerProviderInterface, ServiceProviderInterface
|
||||||
{
|
{
|
||||||
|
public function register(Application $app)
|
||||||
|
{
|
||||||
|
$app['controller.admin.subdefs'] = $app->share(function (PhraseaApplication $app) {
|
||||||
|
return new SubdefsController($app);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot(Application $app)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function connect(Application $app)
|
public function connect(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.admin.subdefs'] = $this;
|
/** @var ControllerCollection $controllers */
|
||||||
|
|
||||||
$controllers = $app['controllers_factory'];
|
$controllers = $app['controllers_factory'];
|
||||||
|
|
||||||
$app['firewall']->addMandatoryAuthentication($controllers);
|
/** @var Firewall $firewall */
|
||||||
|
$firewall = $app['firewall'];
|
||||||
|
$firewall->addMandatoryAuthentication($controllers);
|
||||||
|
|
||||||
$controllers->before(function (Request $request) use ($app) {
|
$controllers->before(function (Request $request) use ($firewall) {
|
||||||
$app['firewall']->requireAccessToModule('admin')
|
$firewall->requireAccessToModule('admin')
|
||||||
->requireRightOnSbas($request->attributes->get('sbas_id'), 'bas_modify_struct');
|
->requireRightOnSbas($request->attributes->get('sbas_id'), 'bas_modify_struct');
|
||||||
});
|
});
|
||||||
|
|
||||||
$controllers->get('/{sbas_id}/', function (Application $app, $sbas_id) {
|
$controllers->get('/{sbas_id}/', 'controller.admin.subdefs:indexAction')
|
||||||
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
|
|
||||||
|
|
||||||
return $app['twig']->render('admin/subdefs.html.twig', [
|
|
||||||
'databox' => $databox,
|
|
||||||
'subdefs' => $databox->get_subdef_structure()
|
|
||||||
]);
|
|
||||||
})
|
|
||||||
->bind('admin_subdefs_subdef')
|
->bind('admin_subdefs_subdef')
|
||||||
->assert('sbas_id', '\d+');
|
->assert('sbas_id', '\d+');
|
||||||
|
|
||||||
$controllers->post('/{sbas_id}/', function (Application $app, Request $request, $sbas_id) {
|
$controllers->post('/{sbas_id}/', 'controller.admin.subdefs:changeSubdefsAction')
|
||||||
$delete_subdef = $request->request->get('delete_subdef');
|
|
||||||
$toadd_subdef = $request->request->get('add_subdef');
|
|
||||||
$Parmsubdefs = $request->request->get('subdefs', []);
|
|
||||||
|
|
||||||
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
|
|
||||||
|
|
||||||
$add_subdef = ['class' => null, 'name' => null, 'group' => null];
|
|
||||||
foreach ($add_subdef as $k => $v) {
|
|
||||||
if (!isset($toadd_subdef[$k]) || trim($toadd_subdef[$k]) === '')
|
|
||||||
unset($add_subdef[$k]);
|
|
||||||
else
|
|
||||||
$add_subdef[$k] = $toadd_subdef[$k];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($delete_subdef) {
|
|
||||||
|
|
||||||
$delete_subef = explode('_', $delete_subdef, 2);
|
|
||||||
$group = $delete_subef[0];
|
|
||||||
$name = $delete_subef[1];
|
|
||||||
$subdefs = $databox->get_subdef_structure();
|
|
||||||
$subdefs->delete_subdef($group, $name);
|
|
||||||
} elseif (count($add_subdef) === 3) {
|
|
||||||
|
|
||||||
$subdefs = $databox->get_subdef_structure();
|
|
||||||
|
|
||||||
$group = $add_subdef['group'];
|
|
||||||
$name = $app['unicode']->remove_nonazAZ09($add_subdef['name'], false);
|
|
||||||
$class = $add_subdef['class'];
|
|
||||||
|
|
||||||
$subdefs->add_subdef($group, $name, $class);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
$subdefs = $databox->get_subdef_structure();
|
|
||||||
|
|
||||||
foreach ($Parmsubdefs as $post_sub) {
|
|
||||||
|
|
||||||
$options = [];
|
|
||||||
|
|
||||||
$post_sub_ex = explode('_', $post_sub, 2);
|
|
||||||
|
|
||||||
$group = $post_sub_ex[0];
|
|
||||||
$name = $post_sub_ex[1];
|
|
||||||
|
|
||||||
$class = $request->request->get($post_sub . '_class');
|
|
||||||
$downloadable = $request->request->get($post_sub . '_downloadable');
|
|
||||||
|
|
||||||
$defaults = ['path', 'meta', 'mediatype'];
|
|
||||||
|
|
||||||
foreach ($defaults as $def) {
|
|
||||||
$parm_loc = $request->request->get($post_sub . '_' . $def);
|
|
||||||
|
|
||||||
if ($def == 'meta' && !$parm_loc) {
|
|
||||||
$parm_loc = "no";
|
|
||||||
}
|
|
||||||
|
|
||||||
$options[$def] = $parm_loc;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mediatype = $request->request->get($post_sub . '_mediatype');
|
|
||||||
$media = $request->request->get($post_sub . '_' . $mediatype, []);
|
|
||||||
|
|
||||||
foreach ($media as $option => $value) {
|
|
||||||
|
|
||||||
if ($option == 'resolution' && $mediatype == 'image') {
|
|
||||||
$option = 'dpi';
|
|
||||||
}
|
|
||||||
|
|
||||||
$options[$option] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$labels = $request->request->get($post_sub . '_label', []);
|
|
||||||
|
|
||||||
$subdefs->set_subdef($group, $name, $class, $downloadable, $options, $labels);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $app->redirectPath('admin_subdefs_subdef', ['sbas_id' => $databox->get_sbas_id()]);
|
|
||||||
})
|
|
||||||
->bind('admin_subdefs_subdef_update')
|
->bind('admin_subdefs_subdef_update')
|
||||||
->assert('sbas_id', '\d+');
|
->assert('sbas_id', '\d+');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user