mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Split MoveCollection controller
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
namespace Alchemy\Phrasea;
|
||||
|
||||
use Alchemy\Geonames\GeonamesServiceProvider;
|
||||
use Alchemy\Phrasea\ControllerProvider\Prod\MoveCollection;
|
||||
use Alchemy\Phrasea\ControllerProvider\Prod\Order;
|
||||
use Alchemy\Phrasea\ControllerProvider\Prod\Printer;
|
||||
use Alchemy\Phrasea\ControllerProvider\Prod\Property;
|
||||
@@ -315,6 +314,7 @@ class Application extends SilexApplication
|
||||
'Alchemy\Phrasea\ControllerProvider\Prod\Feed' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\Prod\Language' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\Prod\Lazaret' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\Prod\MoveCollection' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\Datafiles' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\Lightbox' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\Minifier' => [],
|
||||
@@ -631,7 +631,6 @@ class Application extends SilexApplication
|
||||
$this->mount('/prod/lists', new UsrLists());
|
||||
$this->mount('/prod/records/', new Records());
|
||||
$this->mount('/prod/records/property', new Property());
|
||||
$this->mount('/prod/records/movecollection', new MoveCollection());
|
||||
$this->mount('/prod/push/', new Push());
|
||||
$this->mount('/prod/printer/', new Printer());
|
||||
$this->mount('/prod/share/', new Share());
|
||||
@@ -681,6 +680,7 @@ class Application extends SilexApplication
|
||||
'/prod/language' => 'Alchemy\Phrasea\ControllerProvider\Prod\Language',
|
||||
'/prod/lazaret/' => 'Alchemy\Phrasea\ControllerProvider\Prod\Lazaret',
|
||||
'/prod/records/edit' => 'Alchemy\Phrasea\ControllerProvider\Prod\Edit',
|
||||
'/prod/records/movecollection' => 'Alchemy\Phrasea\ControllerProvider\Prod\MoveCollection',
|
||||
'/setup' => 'Alchemy\Phrasea\ControllerProvider\Setup',
|
||||
];
|
||||
foreach ($providers as $prefix => $class) {
|
||||
|
@@ -0,0 +1,95 @@
|
||||
<?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\Prod;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Controller\Controller;
|
||||
use Alchemy\Phrasea\Controller\RecordsRequest;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class MoveCollectionController extends Controller
|
||||
{
|
||||
|
||||
public function displayForm(Application $app, Request $request)
|
||||
{
|
||||
$records = RecordsRequest::fromRequest($app, $request, false, ['candeleterecord']);
|
||||
|
||||
$sbas_ids = array_map(function (\databox $databox) {
|
||||
return $databox->get_sbas_id();
|
||||
}, $records->databoxes());
|
||||
|
||||
$collections = $app['acl']->get($app['authentication']->getUser())
|
||||
->get_granted_base(['canaddrecord'], $sbas_ids);
|
||||
|
||||
$parameters = [
|
||||
'records' => $records,
|
||||
'message' => '',
|
||||
'collections' => $collections,
|
||||
];
|
||||
|
||||
return $app['twig']->render('prod/actions/collection_default.html.twig', $parameters);
|
||||
}
|
||||
|
||||
public function apply(Application $app, Request $request)
|
||||
{
|
||||
$records = RecordsRequest::fromRequest($app, $request, false, ['candeleterecord']);
|
||||
|
||||
$datas = [
|
||||
'success' => false,
|
||||
'message' => '',
|
||||
];
|
||||
|
||||
try {
|
||||
if (null === $request->request->get('base_id')) {
|
||||
$datas['message'] = $app->trans('Missing target collection');
|
||||
|
||||
return $app->json($datas);
|
||||
}
|
||||
|
||||
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($request->request->get('base_id'), 'canaddrecord')) {
|
||||
$datas['message'] = $app->trans("You do not have the permission to move records to %collection%", ['%collection%', \phrasea::bas_labels($request->request->get('base_id'), $app)]);
|
||||
|
||||
return $app->json($datas);
|
||||
}
|
||||
|
||||
try {
|
||||
$collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
|
||||
} catch (\Exception_Databox_CollectionNotFound $e) {
|
||||
$datas['message'] = $app->trans('Invalid target collection');
|
||||
|
||||
return $app->json($datas);
|
||||
}
|
||||
|
||||
foreach ($records as $record) {
|
||||
$record->move_to_collection($collection, $app['phraseanet.appbox']);
|
||||
|
||||
if ($request->request->get("chg_coll_son") == "1") {
|
||||
foreach ($record->get_children() as $child) {
|
||||
if ($app['acl']->get($app['authentication']->getUser())->has_right_on_base($child->get_base_id(), 'candeleterecord')) {
|
||||
$child->move_to_collection($collection, $app['phraseanet.appbox']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ret = [
|
||||
'success' => true,
|
||||
'message' => $app->trans('Records have been successfuly moved'),
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
$ret = [
|
||||
'success' => false,
|
||||
'message' => $app->trans('An error occured'),
|
||||
];
|
||||
}
|
||||
|
||||
return $app->json($ret);
|
||||
}
|
||||
}
|
@@ -11,24 +11,37 @@
|
||||
|
||||
namespace Alchemy\Phrasea\ControllerProvider\Prod;
|
||||
|
||||
use Alchemy\Phrasea\Controller\RecordsRequest;
|
||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||
use Alchemy\Phrasea\Controller\Prod\MoveCollectionController;
|
||||
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Silex\ServiceProviderInterface;
|
||||
|
||||
class MoveCollection implements ControllerProviderInterface
|
||||
class MoveCollection implements ControllerProviderInterface, ServiceProviderInterface
|
||||
{
|
||||
use ControllerProviderTrait;
|
||||
|
||||
public function register(Application $app)
|
||||
{
|
||||
$app['controller.prod.move-collection'] = $app->share(function (PhraseaApplication $app) {
|
||||
return (new MoveCollectionController($app));
|
||||
});
|
||||
}
|
||||
|
||||
public function boot(Application $app)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$app['controller.prod.move-collection'] = $this;
|
||||
|
||||
$controllers = $this->createAuthenticatedCollection($app);
|
||||
$firewall = $this->getFirewall($app);
|
||||
|
||||
$controllers->before(function (Request $request) use ($app) {
|
||||
$app['firewall']->requireRight('addrecord')
|
||||
$controllers->before(function () use ($firewall) {
|
||||
$firewall
|
||||
->requireRight('addrecord')
|
||||
->requireRight('deleterecord');
|
||||
});
|
||||
|
||||
@@ -40,80 +53,4 @@ class MoveCollection implements ControllerProviderInterface
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
public function displayForm(Application $app, Request $request)
|
||||
{
|
||||
$records = RecordsRequest::fromRequest($app, $request, false, ['candeleterecord']);
|
||||
|
||||
$sbas_ids = array_map(function (\databox $databox) {
|
||||
return $databox->get_sbas_id();
|
||||
}, $records->databoxes());
|
||||
|
||||
$collections = $app['acl']->get($app['authentication']->getUser())
|
||||
->get_granted_base(['canaddrecord'], $sbas_ids);
|
||||
|
||||
$parameters = [
|
||||
'records' => $records,
|
||||
'message' => '',
|
||||
'collections' => $collections,
|
||||
];
|
||||
|
||||
return $app['twig']->render('prod/actions/collection_default.html.twig', $parameters);
|
||||
}
|
||||
|
||||
public function apply(Application $app, Request $request)
|
||||
{
|
||||
$records = RecordsRequest::fromRequest($app, $request, false, ['candeleterecord']);
|
||||
|
||||
$datas = [
|
||||
'success' => false,
|
||||
'message' => '',
|
||||
];
|
||||
|
||||
try {
|
||||
if (null === $request->request->get('base_id')) {
|
||||
$datas['message'] = $app->trans('Missing target collection');
|
||||
|
||||
return $app->json($datas);
|
||||
}
|
||||
|
||||
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($request->request->get('base_id'), 'canaddrecord')) {
|
||||
$datas['message'] = $app->trans("You do not have the permission to move records to %collection%", ['%collection%', \phrasea::bas_labels($request->request->get('base_id'), $app)]);
|
||||
|
||||
return $app->json($datas);
|
||||
}
|
||||
|
||||
try {
|
||||
$collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
|
||||
} catch (\Exception_Databox_CollectionNotFound $e) {
|
||||
$datas['message'] = $app->trans('Invalid target collection');
|
||||
|
||||
return $app->json($datas);
|
||||
}
|
||||
|
||||
foreach ($records as $record) {
|
||||
$record->move_to_collection($collection, $app['phraseanet.appbox']);
|
||||
|
||||
if ($request->request->get("chg_coll_son") == "1") {
|
||||
foreach ($record->get_children() as $child) {
|
||||
if ($app['acl']->get($app['authentication']->getUser())->has_right_on_base($child->get_base_id(), 'candeleterecord')) {
|
||||
$child->move_to_collection($collection, $app['phraseanet.appbox']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ret = [
|
||||
'success' => true,
|
||||
'message' => $app->trans('Records have been successfuly moved'),
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
$ret = [
|
||||
'success' => false,
|
||||
'message' => $app->trans('An error occured'),
|
||||
];
|
||||
}
|
||||
|
||||
return $app->json($ret);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user