diff --git a/lib/Alchemy/Phrasea/Controller/Client/Root.php b/lib/Alchemy/Phrasea/Controller/Client/Root.php index ef3bb47e1a..c5bb2cf3ab 100644 --- a/lib/Alchemy/Phrasea/Controller/Client/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Client/Root.php @@ -97,8 +97,8 @@ class Root implements ControllerProviderInterface $app['EM']->persist($userQuery); $app['EM']->flush(); - if ($app['authentication']->getUser()->getSettingValue('start_page') === 'LAST_QUERY') { - $app['authentication']->getUser()->setSettingValue('start_page_query', $query); + if ($app['settings']->getUserSetting($app['authentication']->getUser(), 'start_page') === 'LAST_QUERY') { + $app['manipulator.user']->setUserSetting($app['authentication']->getUser(), 'start_page_query', $query); } foreach ($options->getDataboxes() as $databox) { @@ -263,10 +263,10 @@ class Root implements ControllerProviderInterface 'module' => 'client', 'menubar' => $app['twig']->render('common/menubar.html.twig', ['module' => 'client']), 'css_file' => $this->getCssFile($app), - 'basket_status' => $app['authentication']->getUser()->getSettingValue('client_basket_status', '1'), - 'mod_pres' => $app['authentication']->getUser()->getSettingValue('client_view', '' ), - 'start_page' => $app['authentication']->getUser()->getSettingValue('start_page'), - 'start_page_query' => $app['authentication']->getUser()->getSettingValue('start_page_query', '') + 'basket_status' => $app['settings']->getUserSetting($app['authentication']->getUser(), 'client_basket_status', '1'), + 'mod_pres' => $app['settings']->getUserSetting($app['authentication']->getUser(), 'client_view', '' ), + 'start_page' => $app['settings']->getUserSetting($app['authentication']->getUser(), 'start_page'), + 'start_page_query' => $app['settings']->getUserSetting($app['authentication']->getUser(), 'start_page_query', '') ])); } @@ -350,7 +350,7 @@ class Root implements ControllerProviderInterface $cssPath = __DIR__ . '/../../../../../www/skins/client/'; $css = []; - $cssFile = $app['authentication']->getUser()->getSettingValue('client_css'); + $cssFile = $app['settings']->getUserSetting($app['authentication']->getUser(), 'client_css'); $finder = new Finder(); @@ -418,7 +418,7 @@ class Root implements ControllerProviderInterface */ private function getDefaultClientStartPage(Application $app) { - $startPage = strtoupper($app['authentication']->getUser()->getSettingValue('start_page')); + $startPage = strtoupper($app['settings']->getUserSetting($app['authentication']->getUser(), 'start_page')); if ($startPage === 'PUBLI') { return $this->getPublicationStartPage($app); @@ -441,7 +441,7 @@ class Root implements ControllerProviderInterface { $collections = $queryParameters = []; - $searchSet = json_decode($app['authentication']->getUser()->getSettingValue('search')); + $searchSet = json_decode($app['settings']->getUserSetting($app['authentication']->getUser(), 'search')); if ($searchSet && isset($searchSet->bases)) { foreach ($searchSet->bases as $bases) { @@ -451,9 +451,9 @@ class Root implements ControllerProviderInterface $collections = array_keys($app['acl']->get($app['authentication']->getUser())->get_granted_base()); } - $queryParameters["mod"] = $app['authentication']->getUser()->getSettingValue('client_view', '3X6'); + $queryParameters["mod"] = $app['settings']->getUserSetting($app['authentication']->getUser(), 'client_view', '3X6'); $queryParameters["bas"] = $collections; - $queryParameters["qry"] = $app['authentication']->getUser()->getSettingValue('start_page_query', 'all'); + $queryParameters["qry"] = $app['settings']->getUserSetting($app['authentication']->getUser(), 'start_page_query', 'all'); $queryParameters["pag"] = 0; $queryParameters["search_type"] = SearchEngineOptions::RECORD_RECORD; $queryParameters["qryAdv"] = ''; @@ -479,7 +479,7 @@ class Root implements ControllerProviderInterface { return $app['twig']->render('client/home_inter_pub_basket.html.twig', [ 'feeds' => Aggregate::createFromUser($app, $app['authentication']->getUser()), - 'image_size' => (int) $app['authentication']->getUser()->getSettingValue('images_size') + 'image_size' => (int) $app['settings']->getUserSetting($app['authentication']->getUser(), 'images_size') ]); } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Query.php b/lib/Alchemy/Phrasea/Controller/Prod/Query.php index bffb604049..da251c5452 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Query.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Query.php @@ -52,7 +52,7 @@ class Query implements ControllerProviderInterface { $query = (string) $request->request->get('qry'); - $mod = $app['authentication']->getUser()->getSettingValue('view'); + $mod = $app['settings']->getUserSetting($app['authentication']->getUser(), 'view'); $json = []; @@ -60,7 +60,7 @@ class Query implements ControllerProviderInterface $form = $options->serialize(); - $perPage = (int) $app['authentication']->getUser()->getSettingValue('images_per_page'); + $perPage = (int) $app['settings']->getUserSetting($app['authentication']->getUser(), 'images_per_page'); $page = (int) $request->request->get('pag'); $firstPage = $page < 1; @@ -72,15 +72,10 @@ class Query implements ControllerProviderInterface $result = $app['phraseanet.SE']->query($query, (($page - 1) * $perPage), $perPage, $options); - $userQuery = new UserQuery(); - $userQuery->setUser($app['authentication']->getUser()); - $userQuery->setQuery($result->getQuery()); + $app['manipulator.user']->logQuery($app['authentication']->getUser(), $result->getQuery()); - $app['EM']->persist($userQuery); - $app['EM']->flush(); - - if ($app['authentication']->getUser()->getSettingValue('start_page') === 'LAST_QUERY') { - $app['authentication']->getUser()->setSettingValue('start_page_query', $result->getQuery()); + if ($app['settings']->getUserSetting($app['authentication']->getUser(), 'start_page') === 'LAST_QUERY') { + $app['manipulator.user']->setUserSetting($app['authentication']->getUser(), 'start_page_query', $result->getQuery()); } foreach ($options->getDataboxes() as $databox) { diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Root.php b/lib/Alchemy/Phrasea/Controller/Prod/Root.php index c41b36e1c3..3c96a27cb8 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Root.php @@ -65,7 +65,7 @@ class Root implements ControllerProviderInterface $css[$baseName] = $baseName; } - $cssfile = $app['authentication']->getUser()->getSettingValue('css'); + $cssfile = $app['settings']->getUserSetting($app['authentication']->getUser(), 'css'); if (!$cssfile && isset($css['000000'])) { $cssfile = '000000'; diff --git a/lib/Alchemy/Phrasea/Controller/User/Preferences.php b/lib/Alchemy/Phrasea/Controller/User/Preferences.php index 21342fbd54..e0280822f8 100644 --- a/lib/Alchemy/Phrasea/Controller/User/Preferences.php +++ b/lib/Alchemy/Phrasea/Controller/User/Preferences.php @@ -85,7 +85,7 @@ class Preferences implements ControllerProviderInterface $success = false; if (null !== $prop && null !== $value) { - $app['authentication']->getUser()->setSettingValue($prop, $value); + $app['manipulator.user']->setUserSetting($app['authentication']->getUser(), $prop, $value); $success = true; $msg = $app->trans('Preference saved !'); } diff --git a/lib/Alchemy/Phrasea/Core/Configuration/DisplaySettingService.php b/lib/Alchemy/Phrasea/Core/Configuration/DisplaySettingService.php index 916f47da0e..040e4b1a26 100644 --- a/lib/Alchemy/Phrasea/Core/Configuration/DisplaySettingService.php +++ b/lib/Alchemy/Phrasea/Core/Configuration/DisplaySettingService.php @@ -91,6 +91,26 @@ class DisplaySettingService return $user->getSettings()->get($name)->getValue(); } + + /** + * Return a user notification setting given a user. + * + * @param User $user + * @param string $name + * @param mixed $default + * + * @return mixed + */ + public function getUserNotificationSetting(User $user, $name, $default = false) + { + if (false === $user->getNotificationSettings()->containsKey($name)) { + + return $default; + } + + return $user->getUserNotificationSetting()->get($name)->getValue(); + } + /** * Returns application setting value. * diff --git a/lib/Alchemy/Phrasea/Model/Entities/User.php b/lib/Alchemy/Phrasea/Model/Entities/User.php index 0ae4961ae2..24fc17cfa0 100644 --- a/lib/Alchemy/Phrasea/Model/Entities/User.php +++ b/lib/Alchemy/Phrasea/Model/Entities/User.php @@ -992,34 +992,6 @@ class User return $this; } - /** - * Sets the value of a user setting. - * - * @param $name - * @param $value - * - * @return $this - */ - public function setSettingValue($name, $value) - { - foreach ($this->settings as $setting) { - if ($name === $setting->getName()) { - $setting->setValue($value); - $this->cachedSettings = null; - - return $this; - } - } - - $setting = new UserSetting(); - $setting->setName($name); - $setting->setValue($value); - - $this->cachedSettings = null; - - return $this; - } - /** * @return ArrayCollection */ @@ -1040,51 +1012,6 @@ class User return $this; } - /** - * Sets the value of a notification setting. - * - * @param $name - * @param $value - * - * @return $this - */ - public function setNotificationSettingValue($name, $value) - { - foreach ($this->notificationSettings as $setting) { - if ($name === $setting->getName()) { - $setting->setValue((Boolean) $value); - - return $this; - } - } - - $notificationSetting = new UserNotificationSetting(); - $notificationSetting->setName($name); - $notificationSetting->setValue((Boolean) $value); - - $this->notificationSettings->add($notificationSetting); - - return $this; - } - - /** - * Retrieves user notification setting value. - * - * @param $name - * - * @return boolean - */ - public function getNotificationSettingValue($name) - { - foreach ($this->notificationSettings as $setting) { - if ($name === $setting->getName()) { - return (Boolean) $setting->getValue(); - } - } - - return true; - } - /** * @return boolean */ diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php index f4368c746f..95863228bc 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/UserManipulator.php @@ -184,13 +184,17 @@ class UserManipulator implements ManipulatorInterface * @param string $name * @param string $value */ - public function addUserSetting(User $user, $name, $value) + public function setUserSetting(User $user, $name, $value) { - $userSetting = new UserSetting(); - $userSetting->setUser($user); - $userSetting->setName($name); - $userSetting->setValue($value); - $user->addSetting($userSetting); + if ($user->getSettings()->containsKey($name)) { + $user->getSettings()->get($name)->setValue($value); + } else { + $userSetting = new UserSetting(); + $userSetting->setUser($user); + $userSetting->setName($name); + $userSetting->setValue($value); + $user->addSetting($userSetting); + } $this->manager->update($user); } @@ -202,13 +206,17 @@ class UserManipulator implements ManipulatorInterface * @param string $name * @param string $value */ - public function addNotificationSetting(User $user, $name, $value) + public function setNotificationSetting(User $user, $name, $value) { - $notifSetting = new UserNotificationSetting(); - $notifSetting->setName($name); - $notifSetting->setValue($value); - $notifSetting->setUser($user); - $user->addNotificationSettings($notifSetting); + if ($user->getNotificationSettings()->containsKey($name)) { + $user->getNotificationSettings()->get($name)->setValue((Boolean) $value); + } else { + $userSetting = new UserNotificationSetting(); + $userSetting->setUser($user); + $userSetting->setName($name); + $userSetting->setValue($value); + $user->addNotificationSettings($userSetting); + } $this->manager->update($user); } diff --git a/lib/classes/databox/cgu.php b/lib/classes/databox/cgu.php index 4574dad3b4..8d7f3fcf40 100644 --- a/lib/classes/databox/cgu.php +++ b/lib/classes/databox/cgu.php @@ -62,7 +62,7 @@ class databox_cgu if ( ! $app['acl']->get($app['authentication']->getUser())->has_access_to_sbas($databox->get_sbas_id())) { continue; } - $userValidation = ($app['authentication']->getUser()->getSettingValue('terms_of_use_' . $databox->get_sbas_id()) !== $update && trim($value) !== ''); + $userValidation = ($app['settings']->getUserSetting($app['authentication']->getUser(), 'terms_of_use_' . $databox->get_sbas_id()) !== $update && trim($value) !== ''); } if ($userValidation) diff --git a/lib/classes/eventsmanager/notifyAbstract.php b/lib/classes/eventsmanager/notifyAbstract.php index 8ec559d554..5e7e9385a5 100644 --- a/lib/classes/eventsmanager/notifyAbstract.php +++ b/lib/classes/eventsmanager/notifyAbstract.php @@ -32,15 +32,10 @@ abstract class eventsmanager_notifyAbstract extends eventsmanager_eventAbstract abstract public function icon_url(); - protected function get_prefs($class, $usr_id) + protected function shouldSendNotificationFor($usrId) { - $user = $this->app['manipulator.user']->getRepository()->find($usr_id); + $user = $this->app['manipulator.user']->getRepository()->find($usrId); - return $user->getNotificationSettingValue($class); - } - - protected function shouldSendNotificationFor($usr_id) - { - return 0 !== (int) $this->get_prefs(get_class($this), $usr_id); + return $this->app['settings']->getUserNotificationSetting($user, get_class($this)); } } diff --git a/templates/web/account/account.html.twig b/templates/web/account/account.html.twig index e06e8fd1af..302398cc72 100644 --- a/templates/web/account/account.html.twig +++ b/templates/web/account/account.html.twig @@ -154,7 +154,7 @@ {% for notification in nots %}