mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 14:33:14 +00:00
UserPreference split into provider/controller
This commit is contained in:
@@ -14,7 +14,6 @@ namespace Alchemy\Phrasea;
|
|||||||
use Alchemy\Geonames\GeonamesServiceProvider;
|
use Alchemy\Geonames\GeonamesServiceProvider;
|
||||||
use Alchemy\Phrasea\ControllerProvider\Thesaurus\Thesaurus;
|
use Alchemy\Phrasea\ControllerProvider\Thesaurus\Thesaurus;
|
||||||
use Alchemy\Phrasea\ControllerProvider\Thesaurus\Xmlhttp as ThesaurusXMLHttp;
|
use Alchemy\Phrasea\ControllerProvider\Thesaurus\Xmlhttp as ThesaurusXMLHttp;
|
||||||
use Alchemy\Phrasea\ControllerProvider\User\Preferences;
|
|
||||||
use Alchemy\Phrasea\Core\Event\Subscriber\BasketSubscriber;
|
use Alchemy\Phrasea\Core\Event\Subscriber\BasketSubscriber;
|
||||||
use Alchemy\Phrasea\Core\Event\Subscriber\BridgeSubscriber;
|
use Alchemy\Phrasea\Core\Event\Subscriber\BridgeSubscriber;
|
||||||
use Alchemy\Phrasea\Core\Event\Subscriber\ExportSubscriber;
|
use Alchemy\Phrasea\Core\Event\Subscriber\ExportSubscriber;
|
||||||
@@ -317,6 +316,7 @@ class Application extends SilexApplication
|
|||||||
'Alchemy\Phrasea\ControllerProvider\Root\RSSFeeds' => [],
|
'Alchemy\Phrasea\ControllerProvider\Root\RSSFeeds' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Root\Session' => [],
|
'Alchemy\Phrasea\ControllerProvider\Root\Session' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\User\Notifications' => [],
|
'Alchemy\Phrasea\ControllerProvider\User\Notifications' => [],
|
||||||
|
'Alchemy\Phrasea\ControllerProvider\User\Preferences' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Datafiles' => [],
|
'Alchemy\Phrasea\ControllerProvider\Datafiles' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\Lightbox' => [],
|
'Alchemy\Phrasea\ControllerProvider\Lightbox' => [],
|
||||||
'Alchemy\Phrasea\ControllerProvider\MediaAccessor' => [],
|
'Alchemy\Phrasea\ControllerProvider\MediaAccessor' => [],
|
||||||
@@ -621,8 +621,6 @@ class Application extends SilexApplication
|
|||||||
*/
|
*/
|
||||||
public function bindRoutes()
|
public function bindRoutes()
|
||||||
{
|
{
|
||||||
$this->mount('/user/preferences/', new Preferences());
|
|
||||||
|
|
||||||
$this->mount('/thesaurus', new Thesaurus());
|
$this->mount('/thesaurus', new Thesaurus());
|
||||||
$this->mount('/xmlhttp', new ThesaurusXMLHttp());
|
$this->mount('/xmlhttp', new ThesaurusXMLHttp());
|
||||||
|
|
||||||
@@ -680,6 +678,7 @@ class Application extends SilexApplication
|
|||||||
'/session/' => 'Alchemy\Phrasea\ControllerProvider\Root\Session',
|
'/session/' => 'Alchemy\Phrasea\ControllerProvider\Root\Session',
|
||||||
'/setup' => 'Alchemy\Phrasea\ControllerProvider\Setup',
|
'/setup' => 'Alchemy\Phrasea\ControllerProvider\Setup',
|
||||||
'/user/notifications/' => 'Alchemy\Phrasea\ControllerProvider\User\Notifications',
|
'/user/notifications/' => 'Alchemy\Phrasea\ControllerProvider\User\Notifications',
|
||||||
|
'/user/preferences/' => 'Alchemy\Phrasea\ControllerProvider\User\Preferences',
|
||||||
'/' => 'Alchemy\Phrasea\ControllerProvider\Root\Root',
|
'/' => 'Alchemy\Phrasea\ControllerProvider\Root\Root',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@@ -0,0 +1,72 @@
|
|||||||
|
<?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\User;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application;
|
||||||
|
use Alchemy\Phrasea\Controller\Controller;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
class UserPreferenceController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Save temporary user preferences
|
||||||
|
*
|
||||||
|
* @param Application $app
|
||||||
|
* @param Request $request
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function saveTemporaryPref(Application $app, Request $request)
|
||||||
|
{
|
||||||
|
if (!$request->isXmlHttpRequest()) {
|
||||||
|
$app->abort(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$prop = $request->request->get('prop');
|
||||||
|
$value = $request->request->get('value');
|
||||||
|
$success = false;
|
||||||
|
$msg = $app->trans('Error while saving preference');
|
||||||
|
|
||||||
|
if ($prop && $value) {
|
||||||
|
$app['session']->set('phraseanet.' . $prop, $value);
|
||||||
|
$success = true;
|
||||||
|
$msg = $app->trans('Preference saved !');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new JsonResponse(['success' => $success, 'message' => $msg]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save user preferenes
|
||||||
|
*
|
||||||
|
* @param Application $app
|
||||||
|
* @param Request $request
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function saveUserPref(Application $app, Request $request)
|
||||||
|
{
|
||||||
|
if (!$request->isXmlHttpRequest()) {
|
||||||
|
$app->abort(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$msg = $app->trans('Error while saving preference');
|
||||||
|
$prop = $request->request->get('prop');
|
||||||
|
$value = $request->request->get('value');
|
||||||
|
|
||||||
|
$success = false;
|
||||||
|
if (null !== $prop && null !== $value) {
|
||||||
|
$app['manipulator.user']->setUserSetting($app['authentication']->getUser(), $prop, $value);
|
||||||
|
$success = true;
|
||||||
|
$msg = $app->trans('Preference saved !');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new JsonResponse(['success' => $success, 'message' => $msg]);
|
||||||
|
}
|
||||||
|
}
|
@@ -11,23 +11,34 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\ControllerProvider\User;
|
namespace Alchemy\Phrasea\ControllerProvider\User;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
|
use Alchemy\Phrasea\Controller\User\UserPreferenceController;
|
||||||
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
|
use Alchemy\Phrasea\ControllerProvider\ControllerProviderTrait;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ControllerProviderInterface;
|
use Silex\ControllerProviderInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Silex\ServiceProviderInterface;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
||||||
|
|
||||||
class Preferences implements ControllerProviderInterface
|
class Preferences implements ControllerProviderInterface, ServiceProviderInterface
|
||||||
{
|
{
|
||||||
use ControllerProviderTrait;
|
use ControllerProviderTrait;
|
||||||
|
|
||||||
|
public function register(Application $app)
|
||||||
|
{
|
||||||
|
$app['controller.user.preferences'] = $app->share(function (PhraseaApplication $app) {
|
||||||
|
return (new UserPreferenceController($app));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot(Application $app)
|
||||||
|
{
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function connect(Application $app)
|
public function connect(Application $app)
|
||||||
{
|
{
|
||||||
$app['controller.user.preferences'] = $this;
|
|
||||||
|
|
||||||
$controllers = $this->createAuthenticatedCollection($app);
|
$controllers = $this->createAuthenticatedCollection($app);
|
||||||
|
|
||||||
$controllers->post('/', 'controller.user.preferences:saveUserPref')
|
$controllers->post('/', 'controller.user.preferences:saveUserPref')
|
||||||
@@ -38,58 +49,4 @@ class Preferences implements ControllerProviderInterface
|
|||||||
|
|
||||||
return $controllers;
|
return $controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Save temporary user preferences
|
|
||||||
*
|
|
||||||
* @param Application $app
|
|
||||||
* @param Request $request
|
|
||||||
* @return JsonResponse
|
|
||||||
*/
|
|
||||||
public function saveTemporaryPref(Application $app, Request $request)
|
|
||||||
{
|
|
||||||
if (!$request->isXmlHttpRequest()) {
|
|
||||||
$app->abort(400);
|
|
||||||
}
|
|
||||||
|
|
||||||
$prop = $request->request->get('prop');
|
|
||||||
$value = $request->request->get('value');
|
|
||||||
$success = false;
|
|
||||||
$msg = $app->trans('Error while saving preference');
|
|
||||||
|
|
||||||
if ($prop && $value) {
|
|
||||||
$app['session']->set('phraseanet.' . $prop, $value);
|
|
||||||
$success = true;
|
|
||||||
$msg = $app->trans('Preference saved !');
|
|
||||||
}
|
|
||||||
|
|
||||||
return new JsonResponse(['success' => $success, 'message' => $msg]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save user preferenes
|
|
||||||
*
|
|
||||||
* @param Application $app
|
|
||||||
* @param Request $request
|
|
||||||
* @return JsonResponse
|
|
||||||
*/
|
|
||||||
public function saveUserPref(Application $app, Request $request)
|
|
||||||
{
|
|
||||||
if (!$request->isXmlHttpRequest()) {
|
|
||||||
$app->abort(400);
|
|
||||||
}
|
|
||||||
|
|
||||||
$msg = $app->trans('Error while saving preference');
|
|
||||||
$prop = $request->request->get('prop');
|
|
||||||
$value = $request->request->get('value');
|
|
||||||
|
|
||||||
$success = false;
|
|
||||||
if (null !== $prop && null !== $value) {
|
|
||||||
$app['manipulator.user']->setUserSetting($app['authentication']->getUser(), $prop, $value);
|
|
||||||
$success = true;
|
|
||||||
$msg = $app->trans('Preference saved !');
|
|
||||||
}
|
|
||||||
|
|
||||||
return new JsonResponse(['success' => $success, 'message' => $msg]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user