diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-04-07 05:56:40 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2015-04-08 03:16:38 +0300 |
commit | 54e5df41d7a6a48f61a4ac0ba4e1a5b68e286ad0 (patch) | |
tree | df0bfb323a4b50876f3bc75f2f586d752aec79e5 /core/Settings | |
parent | bd9efbb7341f0d6b1d650949c3de82f82f81e165 (diff) |
load all site ids only if needed. Makes dashboard much faster if one is superuser and has many sites
Diffstat (limited to 'core/Settings')
-rw-r--r-- | core/Settings/Setting.php | 6 | ||||
-rw-r--r-- | core/Settings/SystemSetting.php | 26 | ||||
-rw-r--r-- | core/Settings/UserSetting.php | 33 |
3 files changed, 59 insertions, 6 deletions
diff --git a/core/Settings/Setting.php b/core/Settings/Setting.php index 3288387671..4b1b36e5a1 100644 --- a/core/Settings/Setting.php +++ b/core/Settings/Setting.php @@ -147,8 +147,6 @@ abstract class Setting protected $key; protected $name; - protected $writableByCurrentUser = false; - protected $readableByCurrentUser = false; /** * @var StorageInterface @@ -188,7 +186,7 @@ abstract class Setting */ public function isWritableByCurrentUser() { - return $this->writableByCurrentUser; + return false; } /** @@ -198,7 +196,7 @@ abstract class Setting */ public function isReadableByCurrentUser() { - return $this->readableByCurrentUser; + return false; } /** diff --git a/core/Settings/SystemSetting.php b/core/Settings/SystemSetting.php index 935aec1388..94f7416c19 100644 --- a/core/Settings/SystemSetting.php +++ b/core/Settings/SystemSetting.php @@ -32,6 +32,11 @@ class SystemSetting extends Setting public $readableByCurrentUser = false; /** + * @var bool + */ + private $writableByCurrentUser = false; + + /** * Constructor. * * @param string $name The persisted name of the setting. @@ -46,6 +51,27 @@ class SystemSetting extends Setting } /** + * Returns `true` if this setting is writable for the current user, `false` if otherwise. In case it returns + * writable for the current user it will be visible in the Plugin settings UI. + * + * @return bool + */ + public function isWritableByCurrentUser() + { + return $this->writableByCurrentUser; + } + + /** + * Returns `true` if this setting can be displayed for the current user, `false` if otherwise. + * + * @return bool + */ + public function isReadableByCurrentUser() + { + return $this->readableByCurrentUser; + } + + /** * Returns the display order. System settings are displayed before user settings. * * @return int diff --git a/core/Settings/UserSetting.php b/core/Settings/UserSetting.php index 80cf66ebf2..60f63e3037 100644 --- a/core/Settings/UserSetting.php +++ b/core/Settings/UserSetting.php @@ -23,6 +23,12 @@ class UserSetting extends Setting private $userLogin = null; /** + * Null while not initialized, bool otherwise. + * @var null|bool + */ + private $hasReadAndWritePermission = null; + + /** * Constructor. * * @param string $name The setting's persisted name. @@ -34,9 +40,32 @@ class UserSetting extends Setting parent::__construct($name, $title); $this->setUserLogin($userLogin); + } + + /** + * Returns `true` if this setting can be displayed for the current user, `false` if otherwise. + * + * @return bool + */ + public function isReadableByCurrentUser() + { + return $this->isWritableByCurrentUser(); + } + + /** + * Returns `true` if this setting can be displayed for the current user, `false` if otherwise. + * + * @return bool + */ + public function isWritableByCurrentUser() + { + if (isset($this->hasReadAndWritePermission)) { + return $this->hasReadAndWritePermission; + } + + $this->hasReadAndWritePermission = Piwik::isUserHasSomeViewAccess(); - $this->writableByCurrentUser = Piwik::isUserHasSomeViewAccess(); - $this->readableByCurrentUser = Piwik::isUserHasSomeViewAccess(); + return $this->hasReadAndWritePermission; } /** |