From 0e6ed74682c3e88b360a63cf9be92c3398a7bdd8 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Mon, 12 May 2014 15:15:23 +0200 Subject: [PATCH] Fixed post safety user settings --- public_html/media/js/core.js | 28 ---------------------------- src/Controllers/UserController.php | 2 +- src/Models/Entities/UserEntity.php | 10 +++++----- src/Models/Enums/PostSafety.php | 2 +- 4 files changed, 7 insertions(+), 35 deletions(-) diff --git a/public_html/media/js/core.js b/public_html/media/js/core.js index 0fa7cf7a..9b6d338a 100644 --- a/public_html/media/js/core.js +++ b/public_html/media/js/core.js @@ -50,34 +50,6 @@ $.fn.bindOnce = function(name, eventName, callback) -//safety trigger -$(function() -{ - $('.safety a').click(function(e) - { - e.preventDefault(); - - var aDom = $(this); - if (aDom.hasClass('inactive')) - return; - aDom.addClass('inactive'); - - var url = $(this).attr('href') + '?json'; - $.get(url).success(function(data) - { - window.location.reload(); - }).error(function(xhr) - { - alert(xhr.responseJSON - ? xhr.responseJSON.message - : 'Fatal error'); - aDom.removeClass('inactive'); - }); - }); -}); - - - //basic event listeners $(function() { diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 018f1d56..65196406 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -83,7 +83,7 @@ class UserController if (!is_array($suppliedSafety)) $suppliedSafety = []; foreach (PostSafety::getAll() as $safety) - $user->enableSafety($safety, in_array($safety, $suppliedSafety)); + $user->enableSafety($safety, in_array($safety->toInteger(), $suppliedSafety)); $user->enableEndlessScrolling(InputHelper::get('endless-scrolling')); $user->enablePostTagTitles(InputHelper::get('post-tag-titles')); diff --git a/src/Models/Entities/UserEntity.php b/src/Models/Entities/UserEntity.php index 0f340577..493c5e46 100644 --- a/src/Models/Entities/UserEntity.php +++ b/src/Models/Entities/UserEntity.php @@ -48,6 +48,9 @@ final class UserEntity extends AbstractEntity implements IValidatable $this->validateAccessRank(); $this->validateEmails(); + if (!$this->getSetting(UserModel::SETTING_SAFETY)) + $this->setSetting(UserModel::SETTING_SAFETY, (new PostSafety(PostSafety::Safe))->toFlag()); + if (empty($this->getAccessRank())) throw new Exception('No access rank detected'); @@ -275,8 +278,8 @@ final class UserEntity extends AbstractEntity implements IValidatable { $all = $this->getSetting(UserModel::SETTING_SAFETY); if (!$all) - return $safety->toInteger() == PostSafety::Safe; - return $all & $safety->toFlag(); + return $safety->toInteger() == (new PostSafety(PostSafety::Safe))->toInteger(); + return ($all & $safety->toFlag()) == $safety->toFlag(); } public function enableSafety(PostSafety $safety, $enabled) @@ -293,9 +296,6 @@ final class UserEntity extends AbstractEntity implements IValidatable $new |= $safety->toFlag(); } - if (!$new) - $new = (new PostSafety(PostSafety::Safe))->toFlag(); - $this->setSetting(UserModel::SETTING_SAFETY, $new); } diff --git a/src/Models/Enums/PostSafety.php b/src/Models/Enums/PostSafety.php index 99a4342e..3014ac63 100644 --- a/src/Models/Enums/PostSafety.php +++ b/src/Models/Enums/PostSafety.php @@ -19,7 +19,7 @@ class PostSafety extends Enum implements IValidatable public function toFlag() { - return pow(2, $this->safety); + return pow(2, $this->safety - 1); } public function toString()