User settings DB column greatly compressed
This commit is contained in:
parent
319a9852fc
commit
7f9aaad324
2 changed files with 17 additions and 11 deletions
|
@ -43,32 +43,33 @@ class Model_User extends RedBean_SimpleModel
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const SETTING_SAFETY = 1;
|
||||||
|
const SETTING_ENDLESS_SCROLLING = 2;
|
||||||
|
|
||||||
public function hasEnabledSafety($safety)
|
public function hasEnabledSafety($safety)
|
||||||
{
|
{
|
||||||
return $this->getSetting('safety-' . $safety) !== false;
|
return $this->getSetting(self::SETTING_SAFETY) & PostSafety::toFlag($safety);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enableSafety($safety, $enabled)
|
public function enableSafety($safety, $enabled)
|
||||||
{
|
{
|
||||||
|
$new = $this->getSetting(self::SETTING_SAFETY);
|
||||||
if (!$enabled)
|
if (!$enabled)
|
||||||
{
|
{
|
||||||
$this->setSetting('safety-' . $safety, false);
|
$new &= ~PostSafety::toFlag($safety);
|
||||||
$anythingEnabled = false;
|
if (!$new)
|
||||||
foreach (PostSafety::getAll() as $safety)
|
$new = PostSafety::toFlag(PostSafety::Safe);
|
||||||
if (self::hasEnabledSafety($safety))
|
|
||||||
$anythingEnabled = true;
|
|
||||||
if (!$anythingEnabled)
|
|
||||||
$this->setSetting('safety-' . PostSafety::Safe, true);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->setSetting('safety-' . $safety, true);
|
$new |= PostSafety::toFlag($safety);
|
||||||
}
|
}
|
||||||
|
$this->setSetting(self::SETTING_SAFETY, $new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasEnabledEndlessScrolling()
|
public function hasEnabledEndlessScrolling()
|
||||||
{
|
{
|
||||||
$ret = $this->getSetting('endless-scrolling');
|
$ret = $this->getSetting(self::SETTING_ENDLESS_SCROLLING);
|
||||||
if ($ret === null)
|
if ($ret === null)
|
||||||
$ret = \Chibi\Registry::getConfig()->browsing->endlessScrollingDefault;
|
$ret = \Chibi\Registry::getConfig()->browsing->endlessScrollingDefault;
|
||||||
return $ret;
|
return $ret;
|
||||||
|
@ -76,7 +77,7 @@ class Model_User extends RedBean_SimpleModel
|
||||||
|
|
||||||
public function enableEndlessScrolling($enabled)
|
public function enableEndlessScrolling($enabled)
|
||||||
{
|
{
|
||||||
$this->setSetting('endless-scrolling', (bool) $enabled);
|
$this->setSetting(self::SETTING_ENDLESS_SCROLLING, $enabled ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,4 +4,9 @@ class PostSafety extends Enum
|
||||||
const Safe = 1;
|
const Safe = 1;
|
||||||
const Sketchy = 2;
|
const Sketchy = 2;
|
||||||
const Unsafe = 3;
|
const Unsafe = 3;
|
||||||
|
|
||||||
|
public static function toFlag($safety)
|
||||||
|
{
|
||||||
|
return pow(2, $safety);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue