Files
Phraseanet/lib/Alchemy/Phrasea/Controller/Admin/Subdefs.php
Romain Neutron ea7523f1db Merge branch '3.8'
Conflicts:
	lib/Alchemy/Phrasea/Controller/Admin/Publications.php
	lib/Alchemy/Phrasea/Controller/Admin/TaskManager.php
	lib/Alchemy/Phrasea/Controller/Api/V1.php
	lib/Alchemy/Phrasea/Controller/Lightbox.php
	lib/Alchemy/Phrasea/Controller/Permalink.php
	lib/Alchemy/Phrasea/Controller/Prod/Feed.php
	lib/Alchemy/Phrasea/Controller/Prod/Order.php
	lib/Alchemy/Phrasea/Controller/Prod/Push.php
	lib/Alchemy/Phrasea/Controller/Prod/Share.php
	lib/Alchemy/Phrasea/Controller/Root/Login.php
	lib/Alchemy/Phrasea/Controller/Root/RSSFeeds.php
	lib/Alchemy/Phrasea/Controller/Root/Session.php
	lib/Alchemy/Phrasea/Controller/Setup.php
	lib/Alchemy/Phrasea/Core/CLIProvider/LessBuilderServiceProvider.php
	lib/Alchemy/Phrasea/Core/Provider/ORMServiceProvider.php
	lib/Alchemy/Phrasea/Core/Provider/TaskManagerServiceProvider.php
	lib/classes/Feed/Entry/Item.php
	lib/classes/record/adapter.php
	lib/classes/task/Scheduler.php
	lib/classes/task/manager.php
	lib/classes/task/period/RecordMover.php
	lib/classes/task/period/archive.php
	lib/classes/task/period/cindexer.php
	lib/classes/task/period/ftp.php
	lib/classes/task/period/ftpPull.php
	lib/classes/task/period/subdef.php
	lib/classes/task/period/writemeta.php
	tests/Alchemy/Tests/Phrasea/Border/ManagerTest.php
	tests/Alchemy/Tests/Phrasea/Controller/Root/RSSFeedTest.php
	tests/classes/Feed/Entry/Feed_Entry_ItemTest.php
	tests/classes/PhraseanetPHPUnitAbstract.php
2013-10-31 14:01:44 +01:00

132 lines
4.5 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 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 Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Subdefs implements ControllerProviderInterface
{
public function connect(Application $app)
{
$app['controller.admin.subdefs'] = $this;
$controllers = $app['controllers_factory'];
$controllers->before(function (Request $request) use ($app) {
$app['firewall']->requireAccessToModule('admin')
->requireRightOnSbas($request->attributes->get('sbas_id'), 'bas_modify_struct');
});
$controllers->get('/{sbas_id}/', function (Application $app, $sbas_id) {
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
return $app['twig']->render('admin/subdefs.html.twig', array(
'databox' => $databox,
'subdefs' => $databox->get_subdef_structure()
));
})
->bind('admin_subdefs_subdef')
->assert('sbas_id', '\d+');
$controllers->post('/{sbas_id}/', function (Application $app, Request $request, $sbas_id) {
$delete_subdef = $request->request->get('delete_subdef');
$toadd_subdef = $request->request->get('add_subdef');
$Parmsubdefs = $request->request->get('subdefs', array());
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
$add_subdef = array('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);
$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 = array();
$post_sub_ex = explode('_', $post_sub);
$group = array_shift($post_sub_ex);
$name = implode('_', $post_sub_ex);
$class = $request->request->get($post_sub . '_class');
$downloadable = $request->request->get($post_sub . '_downloadable');
$defaults = array('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, array());
foreach ($media as $option => $value) {
if ($option == 'resolution' && $mediatype == 'image') {
$option = 'dpi';
}
$options[$option] = $value;
}
$labels = $request->request->get($post_sub . '_label', array());
$subdefs->set_subdef($group, $name, $class, $downloadable, $options, $labels);
}
}
return $app->redirectPath('admin_subdefs_subdef', array('sbas_id' => $databox->get_sbas_id()));
})
->bind('admin_subdefs_subdef_update')
->assert('sbas_id', '\d+');
return $controllers;
}
}