Labelize collections

This commit is contained in:
Romain Neutron
2013-05-30 20:00:14 +02:00
parent 55a6469aa4
commit c084f20f85
37 changed files with 301 additions and 61 deletions

View File

@@ -183,6 +183,10 @@ class Collection implements ControllerProviderInterface
->assert('bas_id', '\d+')
->bind('admin_collection_rename');
$controllers->post('/{bas_id}/labels/', $this->call('labels'))
->assert('bas_id', '\d+')
->bind('admin_collection_labels');
/**
* Empty a collection
*
@@ -888,6 +892,40 @@ class Collection implements ControllerProviderInterface
return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success . '&reload-tree=1');
}
public function labels(Application $app, Request $request, $bas_id)
{
if (null === $labels = $request->request->get('labels')) {
$app->abort(400, _('Missing labels parameter'));
}
if (false === is_array($labels)) {
$app->abort(400, _('Invalid labels parameter'));
}
$collection = \collection::get_from_base_id($app, $bas_id);
$success = true;
try {
foreach ($app['locales.I18n.available'] as $code => $language) {
if (!isset($labels[$code])) {
continue;
}
$value = $labels[$code] ?: null;
$collection->set_label($code, $value);
}
} catch (\Exception $e) {
$success = false;
}
if ('json' === $app['request']->getRequestFormat()) {
return $app->json(array(
'success' => $success,
'msg' => $success ? _('Successful update') : _('An error occured')
));
}
return $app->redirect('/admin/collection/' . $collection->get_base_id() . '/?success=' . (int) $success . '&reload-tree=1');
}
/**
* Set public presentation watermark
*