From 614111a5f0bf3aba2a6075d21aced9e7d289e173 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 3 Oct 2014 20:55:37 +0200 Subject: [PATCH] Changed user settings to be stored as arrays --- public_html/js/BrowsingSettings.js | 2 +- src/Dao/EntityConverters/UserEntityConverter.php | 4 ++-- src/FormData/UserEditFormData.php | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/public_html/js/BrowsingSettings.js b/public_html/js/BrowsingSettings.js index 0e214f53..957e18aa 100644 --- a/public_html/js/BrowsingSettings.js +++ b/public_html/js/BrowsingSettings.js @@ -26,7 +26,7 @@ App.BrowsingSettings = function( function getDefaultSettings() { return { hideDownvoted: true, - endlessScroll: true, + endlessScroll: false, listPosts: { safe: true, sketchy: true, diff --git a/src/Dao/EntityConverters/UserEntityConverter.php b/src/Dao/EntityConverters/UserEntityConverter.php index 0e7d2695..e192082d 100644 --- a/src/Dao/EntityConverters/UserEntityConverter.php +++ b/src/Dao/EntityConverters/UserEntityConverter.php @@ -16,7 +16,7 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv 'registrationTime' => $this->entityTimeToDbTime($entity->getRegistrationTime()), 'lastLoginTime' => $this->entityTimeToDbTime($entity->getLastLoginTime()), 'avatarStyle' => $entity->getAvatarStyle(), - 'browsingSettings' => $entity->getBrowsingSettings(), + 'browsingSettings' => json_encode($entity->getBrowsingSettings()), 'accountConfirmed' => $entity->isAccountConfirmed(), 'banned' => $entity->isBanned(), ]; @@ -33,7 +33,7 @@ class UserEntityConverter extends AbstractEntityConverter implements IEntityConv $entity->setRegistrationTime($this->dbTimeToEntityTime($array['registrationTime'])); $entity->setLastLoginTime($this->dbTimeToEntityTime($array['lastLoginTime'])); $entity->setAvatarStyle(intval($array['avatarStyle'])); - $entity->setBrowsingSettings($array['browsingSettings']); + $entity->setBrowsingSettings(json_decode($array['browsingSettings'])); $entity->setAccountConfirmed($array['accountConfirmed']); $entity->setBanned($array['banned']); return $entity; diff --git a/src/FormData/UserEditFormData.php b/src/FormData/UserEditFormData.php index 9a25832f..9f5bbcc9 100644 --- a/src/FormData/UserEditFormData.php +++ b/src/FormData/UserEditFormData.php @@ -24,7 +24,7 @@ class UserEditFormData implements \Szurubooru\IValidatable if ($inputReader->avatarStyle !== null) $this->avatarStyle = \Szurubooru\Helpers\EnumHelper::avatarStyleFromString($inputReader->avatarStyle); $this->avatarContent = $inputReader->decodeBase64($inputReader->avatarContent); - $this->browsingSettings = $inputReader->browsingSettings; + $this->browsingSettings = json_decode($inputReader->browsingSettings); $this->banned = boolval($inputReader->banned); } } @@ -52,9 +52,9 @@ class UserEditFormData implements \Szurubooru\IValidatable if ($this->browsingSettings !== null) { - if (!is_string($this->browsingSettings)) - throw new \InvalidArgumentException('Browsing settings must be stringified JSON.'); - else if (strlen($this->browsingSettings) > 300) + if (!is_object($this->browsingSettings)) + throw new \InvalidArgumentException('Browsing settings must be valid JSON.'); + else if (strlen(json_encode($this->browsingSettings)) > 300) throw new \InvalidArgumentException('Stringified browsing settings can have at most 300 characters.'); } }