mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 13:33:14 +00:00
Move methods from Story provider to controller
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
namespace Alchemy\Phrasea;
|
||||
|
||||
use Alchemy\Geonames\GeonamesServiceProvider;
|
||||
use Alchemy\Phrasea\ControllerProvider\Prod\Story;
|
||||
use Alchemy\Phrasea\ControllerProvider\Prod\Tools;
|
||||
use Alchemy\Phrasea\ControllerProvider\Prod\Tooltip;
|
||||
use Alchemy\Phrasea\ControllerProvider\Prod\TOU;
|
||||
@@ -315,6 +314,7 @@ class Application extends SilexApplication
|
||||
'Alchemy\Phrasea\ControllerProvider\Prod\Record' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\Prod\Root' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\Prod\Share' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\Prod\Story' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\Datafiles' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\Lightbox' => [],
|
||||
'Alchemy\Phrasea\ControllerProvider\MediaAccessor' => [],
|
||||
@@ -625,7 +625,6 @@ class Application extends SilexApplication
|
||||
$this->mount('/login/', new Login());
|
||||
$this->mount('/developers/', new Developers());
|
||||
|
||||
$this->mount('/prod/story', new Story());
|
||||
$this->mount('/prod/WorkZone', new WorkZone());
|
||||
$this->mount('/prod/lists', new UsrLists());
|
||||
$this->mount('/prod/TOU/', new TOU());
|
||||
@@ -681,6 +680,7 @@ class Application extends SilexApplication
|
||||
'/prod/records/movecollection' => 'Alchemy\Phrasea\ControllerProvider\Prod\MoveCollection',
|
||||
'/prod/records/property' => 'Alchemy\Phrasea\ControllerProvider\Prod\Property',
|
||||
'/prod/share/' => 'Alchemy\Phrasea\ControllerProvider\Prod\Share',
|
||||
'/prod/story' => 'Alchemy\Phrasea\ControllerProvider\Prod\Story',
|
||||
'/prod/' => 'Alchemy\Phrasea\ControllerProvider\Prod\Root',
|
||||
'/setup' => 'Alchemy\Phrasea\ControllerProvider\Setup',
|
||||
];
|
||||
|
224
lib/Alchemy/Phrasea/Controller/Prod/StoryController.php
Normal file
224
lib/Alchemy/Phrasea/Controller/Prod/StoryController.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?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 Alchemy\Phrasea\Controller\Exception as ControllerException;
|
||||
use Alchemy\Phrasea\Core\Event\RecordEdit;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Alchemy\Phrasea\Model\Entities\StoryWZ;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
class StoryController extends Controller
|
||||
{
|
||||
public function displayCreateFormAction(Application $app)
|
||||
{
|
||||
return $app['twig']->render('prod/Story/Create.html.twig', []);
|
||||
}
|
||||
|
||||
public function postCreateFormAction(Application $app, Request $request)
|
||||
{
|
||||
/* @var $request \Symfony\Component\HttpFoundation\Request */
|
||||
$collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
|
||||
|
||||
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($collection->get_base_id(), 'canaddrecord')) {
|
||||
throw new AccessDeniedHttpException('You can not create a story on this collection');
|
||||
}
|
||||
|
||||
$Story = \record_adapter::createStory($app, $collection);
|
||||
|
||||
$records = RecordsRequest::fromRequest($app, $request, true);
|
||||
|
||||
foreach ($records as $record) {
|
||||
if ($Story->hasChild($record)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$Story->appendChild($record);
|
||||
}
|
||||
|
||||
$metadatas = [];
|
||||
|
||||
foreach ($collection->get_databox()->get_meta_structure() as $meta) {
|
||||
if ($meta->get_thumbtitle()) {
|
||||
$value = $request->request->get('name');
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$metadatas[] = [
|
||||
'meta_struct_id' => $meta->get_id()
|
||||
, 'meta_id' => null
|
||||
, 'value' => $value
|
||||
];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$Story->set_metadatas($metadatas)->rebuild_subdefs();
|
||||
|
||||
$StoryWZ = new StoryWZ();
|
||||
$StoryWZ->setUser($app['authentication']->getUser());
|
||||
$StoryWZ->setRecord($Story);
|
||||
|
||||
$app['orm.em']->persist($StoryWZ);
|
||||
|
||||
$app['orm.em']->flush();
|
||||
|
||||
if ($request->getRequestFormat() == 'json') {
|
||||
$data = [
|
||||
'success' => true
|
||||
, 'message' => $app->trans('Story created')
|
||||
, 'WorkZone' => $StoryWZ->getId()
|
||||
, 'story' => [
|
||||
'sbas_id' => $Story->get_sbas_id(),
|
||||
'record_id' => $Story->get_record_id(),
|
||||
]
|
||||
];
|
||||
|
||||
return $app->json($data);
|
||||
} else {
|
||||
return $app->redirectPath('prod_stories_story', [
|
||||
'sbas_id' => $StoryWZ->getSbasId(),
|
||||
'record_id' => $StoryWZ->getRecordId(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function showAction(Application $app, $sbas_id, $record_id)
|
||||
{
|
||||
$Story = new \record_adapter($app, $sbas_id, $record_id);
|
||||
|
||||
$html = $app['twig']->render('prod/WorkZone/Story.html.twig', ['Story' => $Story]);
|
||||
|
||||
return new Response($html);
|
||||
}
|
||||
|
||||
public function addElementsAction(Application $app, Request $request, $sbas_id, $record_id)
|
||||
{
|
||||
$Story = new \record_adapter($app, $sbas_id, $record_id);
|
||||
|
||||
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($Story->get_base_id(), 'canmodifrecord'))
|
||||
throw new AccessDeniedHttpException('You can not add document to this Story');
|
||||
|
||||
$n = 0;
|
||||
|
||||
$records = RecordsRequest::fromRequest($app, $request, true);
|
||||
|
||||
foreach ($records as $record) {
|
||||
if ($Story->hasChild($record)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$Story->appendChild($record);
|
||||
$n++;
|
||||
}
|
||||
|
||||
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($Story));
|
||||
|
||||
$data = [
|
||||
'success' => true
|
||||
, 'message' => $app->trans('%quantity% records added', ['%quantity%' => $n])
|
||||
];
|
||||
|
||||
if ($request->getRequestFormat() == 'json') {
|
||||
return $app->json($data);
|
||||
} else {
|
||||
return $app->redirectPath('prod_stories_story', ['sbas_id' => $sbas_id,'record_id' => $record_id]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeElementAction(Application $app, Request $request, $sbas_id, $record_id, $child_sbas_id, $child_record_id) {
|
||||
$Story = new \record_adapter($app, $sbas_id, $record_id);
|
||||
|
||||
$record = new \record_adapter($app, $child_sbas_id, $child_record_id);
|
||||
|
||||
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($Story->get_base_id(), 'canmodifrecord'))
|
||||
throw new AccessDeniedHttpException('You can not add document to this Story');
|
||||
|
||||
$Story->removeChild($record);
|
||||
|
||||
$data = [
|
||||
'success' => true
|
||||
, 'message' => $app->trans('Record removed from story')
|
||||
];
|
||||
|
||||
|
||||
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($Story));
|
||||
|
||||
if ($request->getRequestFormat() == 'json') {
|
||||
return $app->json($data);
|
||||
} else {
|
||||
return $app->redirectPath('prod_stories_story', ['sbas_id' => $sbas_id,'record_id' => $record_id]);
|
||||
}
|
||||
}
|
||||
|
||||
public function displayReorderFormAction(Application $app, $sbas_id, $record_id)
|
||||
{
|
||||
$story = new \record_adapter($app, $sbas_id, $record_id);
|
||||
|
||||
if (!$story->is_grouping()) {
|
||||
throw new \Exception('This is not a story');
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$app['twig']->render(
|
||||
'prod/Story/Reorder.html.twig'
|
||||
, ['story' => $story]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function reorderAction(Application $app, $sbas_id, $record_id)
|
||||
{
|
||||
$ret = ['success' => false, 'message' => $app->trans('An error occured')];
|
||||
try {
|
||||
|
||||
$story = new \record_adapter($app, $sbas_id, $record_id);
|
||||
|
||||
if (!$story->is_grouping()) {
|
||||
throw new \Exception('This is not a story');
|
||||
}
|
||||
|
||||
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($story->get_base_id(), 'canmodifrecord')) {
|
||||
throw new ControllerException($app->trans('You can not edit this story'));
|
||||
}
|
||||
|
||||
$sql = 'UPDATE regroup SET ord = :ord
|
||||
WHERE rid_parent = :parent_id AND rid_child = :children_id';
|
||||
$stmt = $story->get_databox()->get_connection()->prepare($sql);
|
||||
|
||||
foreach ($app['request']->request->get('element') as $record_id => $ord) {
|
||||
$params = [
|
||||
':ord' => $ord,
|
||||
':parent_id' => $story->get_record_id(),
|
||||
':children_id' => $record_id
|
||||
];
|
||||
$stmt->execute($params);
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = ['success' => true, 'message' => $app->trans('Story updated')];
|
||||
|
||||
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($story));
|
||||
} catch (ControllerException $e) {
|
||||
$ret = ['success' => false, 'message' => $e->getMessage()];
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
return $app->json($ret);
|
||||
}
|
||||
}
|
@@ -11,26 +11,32 @@
|
||||
|
||||
namespace Alchemy\Phrasea\ControllerProvider\Prod;
|
||||
|
||||
use Alchemy\Phrasea\Controller\Exception as ControllerException;
|
||||
use Alchemy\Phrasea\Controller\RecordsRequest;
|
||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||
use Alchemy\Phrasea\Controller\Prod\StoryController;
|
||||
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
|
||||
use Alchemy\Phrasea\Model\Entities\StoryWZ;
|
||||
use Alchemy\Phrasea\Core\Event\RecordEdit;
|
||||
use Alchemy\Phrasea\Core\PhraseaEvents;
|
||||
use Silex\Application;
|
||||
use Silex\ControllerProviderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Silex\ServiceProviderInterface;
|
||||
|
||||
class Story implements ControllerProviderInterface
|
||||
class Story implements ControllerProviderInterface, ServiceProviderInterface
|
||||
{
|
||||
use ControllerProviderTrait;
|
||||
|
||||
public function register(Application $app)
|
||||
{
|
||||
$app['controller.prod.story'] = $app->share(function (PhraseaApplication $app) {
|
||||
return (new StoryController($app))
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
public function boot(Application $app)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
public function connect(Application $app)
|
||||
{
|
||||
$app['controller.prod.story'] = $this;
|
||||
|
||||
$controllers = $this->createAuthenticatedCollection($app);
|
||||
|
||||
$controllers->get('/create/', 'controller.prod.story:displayCreateFormAction')
|
||||
@@ -66,204 +72,4 @@ class Story implements ControllerProviderInterface
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
public function displayCreateFormAction(Application $app)
|
||||
{
|
||||
return $app['twig']->render('prod/Story/Create.html.twig', []);
|
||||
}
|
||||
|
||||
public function postCreateFormAction(Application $app, Request $request)
|
||||
{
|
||||
/* @var $request \Symfony\Component\HttpFoundation\Request */
|
||||
$collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
|
||||
|
||||
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($collection->get_base_id(), 'canaddrecord')) {
|
||||
throw new AccessDeniedHttpException('You can not create a story on this collection');
|
||||
}
|
||||
|
||||
$Story = \record_adapter::createStory($app, $collection);
|
||||
|
||||
$records = RecordsRequest::fromRequest($app, $request, true);
|
||||
|
||||
foreach ($records as $record) {
|
||||
if ($Story->hasChild($record)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$Story->appendChild($record);
|
||||
}
|
||||
|
||||
$metadatas = [];
|
||||
|
||||
foreach ($collection->get_databox()->get_meta_structure() as $meta) {
|
||||
if ($meta->get_thumbtitle()) {
|
||||
$value = $request->request->get('name');
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$metadatas[] = [
|
||||
'meta_struct_id' => $meta->get_id()
|
||||
, 'meta_id' => null
|
||||
, 'value' => $value
|
||||
];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$Story->set_metadatas($metadatas)->rebuild_subdefs();
|
||||
|
||||
$StoryWZ = new StoryWZ();
|
||||
$StoryWZ->setUser($app['authentication']->getUser());
|
||||
$StoryWZ->setRecord($Story);
|
||||
|
||||
$app['orm.em']->persist($StoryWZ);
|
||||
|
||||
$app['orm.em']->flush();
|
||||
|
||||
if ($request->getRequestFormat() == 'json') {
|
||||
$data = [
|
||||
'success' => true
|
||||
, 'message' => $app->trans('Story created')
|
||||
, 'WorkZone' => $StoryWZ->getId()
|
||||
, 'story' => [
|
||||
'sbas_id' => $Story->get_sbas_id(),
|
||||
'record_id' => $Story->get_record_id(),
|
||||
]
|
||||
];
|
||||
|
||||
return $app->json($data);
|
||||
} else {
|
||||
return $app->redirectPath('prod_stories_story', [
|
||||
'sbas_id' => $StoryWZ->getSbasId(),
|
||||
'record_id' => $StoryWZ->getRecordId(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function showAction(Application $app, $sbas_id, $record_id)
|
||||
{
|
||||
$Story = new \record_adapter($app, $sbas_id, $record_id);
|
||||
|
||||
$html = $app['twig']->render('prod/WorkZone/Story.html.twig', ['Story' => $Story]);
|
||||
|
||||
return new Response($html);
|
||||
}
|
||||
|
||||
public function addElementsAction(Application $app, Request $request, $sbas_id, $record_id)
|
||||
{
|
||||
$Story = new \record_adapter($app, $sbas_id, $record_id);
|
||||
|
||||
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($Story->get_base_id(), 'canmodifrecord'))
|
||||
throw new AccessDeniedHttpException('You can not add document to this Story');
|
||||
|
||||
$n = 0;
|
||||
|
||||
$records = RecordsRequest::fromRequest($app, $request, true);
|
||||
|
||||
foreach ($records as $record) {
|
||||
if ($Story->hasChild($record)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$Story->appendChild($record);
|
||||
$n++;
|
||||
}
|
||||
|
||||
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($Story));
|
||||
|
||||
$data = [
|
||||
'success' => true
|
||||
, 'message' => $app->trans('%quantity% records added', ['%quantity%' => $n])
|
||||
];
|
||||
|
||||
if ($request->getRequestFormat() == 'json') {
|
||||
return $app->json($data);
|
||||
} else {
|
||||
return $app->redirectPath('prod_stories_story', ['sbas_id' => $sbas_id,'record_id' => $record_id]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeElementAction(Application $app, Request $request, $sbas_id, $record_id, $child_sbas_id, $child_record_id) {
|
||||
$Story = new \record_adapter($app, $sbas_id, $record_id);
|
||||
|
||||
$record = new \record_adapter($app, $child_sbas_id, $child_record_id);
|
||||
|
||||
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($Story->get_base_id(), 'canmodifrecord'))
|
||||
throw new AccessDeniedHttpException('You can not add document to this Story');
|
||||
|
||||
$Story->removeChild($record);
|
||||
|
||||
$data = [
|
||||
'success' => true
|
||||
, 'message' => $app->trans('Record removed from story')
|
||||
];
|
||||
|
||||
|
||||
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($Story));
|
||||
|
||||
if ($request->getRequestFormat() == 'json') {
|
||||
return $app->json($data);
|
||||
} else {
|
||||
return $app->redirectPath('prod_stories_story', ['sbas_id' => $sbas_id,'record_id' => $record_id]);
|
||||
}
|
||||
}
|
||||
|
||||
public function displayReorderFormAction(Application $app, $sbas_id, $record_id)
|
||||
{
|
||||
$story = new \record_adapter($app, $sbas_id, $record_id);
|
||||
|
||||
if (!$story->is_grouping()) {
|
||||
throw new \Exception('This is not a story');
|
||||
}
|
||||
|
||||
return new Response(
|
||||
$app['twig']->render(
|
||||
'prod/Story/Reorder.html.twig'
|
||||
, ['story' => $story]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function reorderAction(Application $app, $sbas_id, $record_id)
|
||||
{
|
||||
$ret = ['success' => false, 'message' => $app->trans('An error occured')];
|
||||
try {
|
||||
|
||||
$story = new \record_adapter($app, $sbas_id, $record_id);
|
||||
|
||||
if (!$story->is_grouping()) {
|
||||
throw new \Exception('This is not a story');
|
||||
}
|
||||
|
||||
if (!$app['acl']->get($app['authentication']->getUser())->has_right_on_base($story->get_base_id(), 'canmodifrecord')) {
|
||||
throw new ControllerException($app->trans('You can not edit this story'));
|
||||
}
|
||||
|
||||
$sql = 'UPDATE regroup SET ord = :ord
|
||||
WHERE rid_parent = :parent_id AND rid_child = :children_id';
|
||||
$stmt = $story->get_databox()->get_connection()->prepare($sql);
|
||||
|
||||
foreach ($app['request']->request->get('element') as $record_id => $ord) {
|
||||
$params = [
|
||||
':ord' => $ord,
|
||||
':parent_id' => $story->get_record_id(),
|
||||
':children_id' => $record_id
|
||||
];
|
||||
$stmt->execute($params);
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = ['success' => true, 'message' => $app->trans('Story updated')];
|
||||
|
||||
$app['dispatcher']->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($story));
|
||||
} catch (ControllerException $e) {
|
||||
$ret = ['success' => false, 'message' => $e->getMessage()];
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
return $app->json($ret);
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,8 @@
|
||||
use Alchemy\Phrasea\CLI;
|
||||
|
||||
return call_user_func(function (CLI $cli) {
|
||||
$app = $cli;
|
||||
$app = $cli; if ($app['plugins.manager']->isEnabled('web-gallery-plugin')) {
|
||||
$cli->command(Alchemy\WebGallery\Command\InstallCommand::create()); $cli->command(Alchemy\WebGallery\Command\UninstallCommand::create()); $cli->command(Alchemy\WebGallery\Command\UpdateCommand::create()); }
|
||||
|
||||
return $cli;
|
||||
}, $cli);
|
||||
|
Reference in New Issue
Block a user