*/
protected static $databaseTableIndexName = 'optionID';
+ // equals to an empty bitmask, NOT a valid bit!
const VISIBILITY_NONE = 0;
+
const VISIBILITY_OWNER = 1;
const VISIBILITY_ADMINISTRATOR = 2;
- const VISIBILITY_OTHER = 4;
- const VISIBILITY_ALL = 7;
+ const VISIBILITY_REGISTERED = 4;
+ const VISIBILITY_GUEST = 8;
+
+ // equals to VISIBILITY_GUEST, NOT a valid bit!
+ const VISIBILITY_ALL = 15;
/**
* @see wcf\data\DatabaseObject::handleData()
<?php
namespace wcf\data\user\option;
use wcf\data\option\Option;
+use wcf\data\user\User;
use wcf\system\option\user\IUserOptionOutput;
+use wcf\system\WCF;
/**
* Represents a user option.
*/
public $outputData = array();
+ /**
+ * user object
+ * @var wcf\data\user\User
+ */
+ public $user = null;
+
+ /**
+ * Sets target user object.
+ *
+ * @param wcf\data\user\User $user
+ */
+ public function setUser(User $user) {
+ $this->user = $user;
+ }
+
/**
* @see wcf\data\option\Option::isVisible()
*/
public function isVisible() {
- $bitmask = $this->options[$optionName]->visible;
// check if option is hidden
- if ($bitmask & Option::VISIBILITY_NONE) {
- $visible = false;
+ if (!$this->visible) {
+ return false;
}
+
// proceed if option is visible for all
- else if ($bitmask & Option::VISIBILITY_OTHER) {
+ if ($this->visible & Option::VISIBILITY_GUEST) {
+ $visible = true;
+ }
+ // proceed if option is visible for registered users and current user is logged in
+ else if (($this->visible & Option::VISIBILITY_REGISTERED) && WCF::getUser()->userID) {
$visible = true;
}
else {
$isAdmin = $isOwner = $visible = false;
// check admin permissions
- if ($bitmask & Option::VISIBILITY_ADMINISTRATOR) {
+ if ($this->visible & Option::VISIBILITY_ADMINISTRATOR) {
if (WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) {
$isAdmin = true;
}
}
// check owner state
- if ($bitmask & Option::VISIBILITY_OWNER) {
- if ($user->userID == WCF::getUser()->userID) {
+ if ($this->visible & Option::VISIBILITY_OWNER) {
+ if ($this->user->userID == WCF::getUser()->userID) {
$isOwner = true;
}
}
* option structure
* @var array
*/
- protected $cachedOptionToCategories = null;
+ public $cachedOptionToCategories = null;
/**
* Name of the active option category.
*/
public $supportI18n = false;
+ /**
+ * cache initialization state
+ * @var boolean
+ */
+ public $didInit = false;
+
/**
* @see wcf\system\option\IOptionHandler::__construct()
*/
- public function __construct($cacheName, $cacheClass, $supportI18n, $languageItemPattern = '', $categoryName = '') {
+ public function __construct($cacheName, $cacheClass, $supportI18n, $languageItemPattern = '', $categoryName = '', $loadActiveOptions = true) {
$this->cacheName = $cacheName;
$this->cacheClass = $cacheClass;
$this->categoryName = $categoryName;
$this->supportI18n = $supportI18n;
// load cache on init
- $this->readCache();
+ $this->readCache($loadActiveOptions);
}
/**
/**
* Gets all options and option categories from cache.
+ *
+ * @param boolean $loadActiveOptions
*/
- protected function readCache() {
+ protected function readCache($loadActiveOptions) {
$cacheName = $this->cacheName . '-' . PACKAGE_ID;
CacheHandler::getInstance()->addResource($cacheName, WCF_DIR.'cache/cache.'.$cacheName.'.php', $this->cacheClass);
$this->cachedCategoryStructure = CacheHandler::getInstance()->get($cacheName, 'categoryStructure');
$this->cachedOptionToCategories = CacheHandler::getInstance()->get($cacheName, 'optionToCategories');
- // get active options
- $this->loadActiveOptions($this->categoryName);
+ if ($loadActiveOptions) {
+ // get active options
+ $this->loadActiveOptions($this->categoryName);
+
+ // mark options as initialized
+ $this->didInit = true;
+ }
}
/**
if (!$hasEnabledOption) return false;
}
- if (!$option->isVisible()) {
+ if (!$this->checkVisibility($option)) {
return false;
}
return true;
}
+
+ /**
+ * Checks visibility of an option.
+ *
+ * @param wcf\data\option\Option $option
+ * @return boolean
+ */
+ protected function checkVisibility(Option $option) {
+ return $option->isVisible();
+ }
}
$userOption = 'userOption' . $option->optionID;
$this->optionValues[$option->optionName] = $this->user->{$userOption};
}
+
+ if (!$this->didInit) {
+ $this->loadActiveOptions($this->categoryName);
+
+ $this->didInit = true;
+ }
}
/**
return parent::checkCategory($category);
}
+
+ /**
+ * @see wcf\system\option\OptionHandler::checkVisibility()
+ */
+ protected function checkVisibility(Option $option) {
+ $option->setUser($this->user);
+
+ return $option->isVisible();
+ }
}