parent::readParameters();
$this->optionHandler = new $this->optionHandlerClassName($this->cacheName, $this->cacheClass, $this->supportI18n, $this->languageItemPattern, $this->categoryName, $this->loadActiveOptions);
+ $this->initOptionHandler();
+ }
+
+ /**
+ * Initializes the option handler.
+ */
+ protected function initOptionHandler() {
+ $this->optionHandler->init();
}
/**
*/
public $additionalFields = array();
- /**
- * @see wcf\page\IPage::readParameters()
- */
- public function readParameters() {
- parent::readParameters();
-
- $this->optionHandler->overrideVisibility();
- }
-
/**
* @see wcf\form\IForm::readFormParameters()
*/
$this->username = $this->email = $this->confirmEmail = $this->password = $this->confirmPassword = '';
$this->groupIDs = array();
$this->languageID = $this->getDefaultFormLanguageID();
- $this->optionValues = array();
+ $this->optionHandler->resetOptionValues();
}
/**
*/
public $user = null;
- /**
- * @see wcf\acp\form\AbstractOptionListForm::$loadActiveOptions
- */
- public $loadActiveOptions = false;
-
/**
* @see wcf\page\IPage::readParameters()
*/
public function readParameters() {
- parent::readParameters();
-
if (isset($_REQUEST['id'])) $this->userID = intval($_REQUEST['id']);
-
$user = new User($this->userID);
if (!$user->userID) {
throw new IllegalLinkException();
throw new PermissionDeniedException();
}
+ parent::readParameters();
+ }
+
+ /**
+ * wcf\acp\form\AbstractOptionListForm::initOptionHandler()
+ */
+ protected function initOptionHandler() {
$this->optionHandler->setUser($this->user->getDecoratedObject());
- $this->optionHandler->showEmptyOptions();
}
/**
parent::readData();
}
- /**
- * @see wcf\acp\form\UserAddForm::readOptionTree()
- */
- protected function readOptionTree() {
- if (empty($_POST)) {
- $this->optionHandler->setUser($this->user->getDecoratedObject());
- }
-
- parent::readOptionTree();
- }
-
/**
* Gets the selected languages.
*/
*/
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_REGISTERED = 4;
- const VISIBILITY_GUEST = 8;
-
- // equals to VISIBILITY_GUEST, NOT a valid bit!
- const VISIBILITY_ALL = 15;
-
/**
* @see wcf\data\DatabaseObject::handleData()
*/
/**
* Returns true, if option is visible
*
- * @param boolean $overrideVisibility
* @return boolean
*/
- public function isVisible($overrideVisibility = false) {
+ public function isVisible() {
return !$this->hidden;
}
* @category Community Framework
*/
class UserOption extends Option {
+ /**
+ * visible for no one (no valid bit)
+ * @var integer
+ */
+ const VISIBILITY_NONE = 0;
+
+ /**
+ * visible for the owner
+ * @var integer
+ */
+ const VISIBILITY_OWNER = 1;
+
+ /**
+ * visible for admins
+ * @var integer
+ */
+ const VISIBILITY_ADMINISTRATOR = 2;
+
+ /**
+ * visible for users
+ * @var integer
+ */
+ const VISIBILITY_REGISTERED = 4;
+
+ /**
+ * visible for guests
+ * @var integer
+ */
+ const VISIBILITY_GUEST = 8;
+
+ /**
+ * visible for all (no valid bit)
+ * @var integer
+ */
+ const VISIBILITY_ALL = 15;
+
+ /**
+ * editable for no one (no valid bit)
+ * @var integer
+ */
+ const EDITABILITY_NONE = 0;
+
+ /**
+ * editable for the owner
+ * @var integer
+ */
+ const EDITABILITY_OWNER = 1;
+
+ /**
+ * editable for admins
+ * @var integer
+ */
+ const EDITABILITY_ADMINISTRATOR = 2;
+
+ /**
+ * editable for all (no valid bit)
+ * @var integer
+ */
+ const EDITABILITY_ALL = 3;
+
/**
* @see wcf\data\DatabaseObject::$databaseTableName
*/
/**
* @see wcf\data\option\Option::isVisible()
*/
- public function isVisible($overrideVisibility = false) {
- // check if option is hidden
- if (!$this->visible || $this->disabled) {
- return false;
- }
-
- // ACP visibility override
- if ($overrideVisibility) {
+ public function isVisible() {
+ // proceed if option is visible for all
+ if ($this->visible & UserOption::VISIBILITY_GUEST) {
return true;
}
- // proceed if option is visible for all
- 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;
+ if (($this->visible & UserOption::VISIBILITY_REGISTERED) && WCF::getUser()->userID) {
+ return true;
}
- else {
- $isAdmin = $isOwner = $visible = false;
- // check admin permissions
- if ($this->visible & Option::VISIBILITY_ADMINISTRATOR) {
- if (WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) {
- $isAdmin = true;
- }
+
+ // check admin permissions
+ if ($this->visible & UserOption::VISIBILITY_ADMINISTRATOR) {
+ if (WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) {
+ return true;
}
-
- // check owner state
- if ($this->visible & Option::VISIBILITY_OWNER) {
- if ($this->user !== null && $this->user->userID == WCF::getUser()->userID) {
- $isOwner = true;
- }
+ }
+
+ // check owner state
+ if ($this->visible & UserOption::VISIBILITY_OWNER) {
+ if ($this->user !== null && $this->user->userID == WCF::getUser()->userID) {
+ return true;
}
-
- if ($isAdmin) {
- $visible = true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns true, if this option is editable.
+ *
+ * @return boolean
+ */
+ public function isEditable() {
+ // check admin permissions
+ if ($this->editable & UserOption::EDITABILITY_ADMINISTRATOR) {
+ if (WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) {
+ return true;
}
- else if ($isOwner) {
- $visible = true;
+ }
+
+ // check owner state
+ if ($this->editable & UserOption::VISIBILITY_OWNER) {
+ if ($this->user === null || $this->user->userID == WCF::getUser()->userID) {
+ return true;
}
}
- if (!$visible || $this->disabled) return false;
-
- return true;
+ return false;
}
}
*/
public $optionValues = array();
- /**
- * visibility override
- * @var boolean
- */
- public $overrideVisibility = false;
-
/**
* raw option values
* @var array<mixed>
/**
* @see wcf\system\option\IOptionHandler::__construct()
*/
- public function __construct($cacheName, $cacheClass, $supportI18n, $languageItemPattern = '', $categoryName = '', $loadActiveOptions = true) {
+ public function __construct($cacheName, $cacheClass, $supportI18n, $languageItemPattern = '', $categoryName = '') {
$this->cacheName = $cacheName;
$this->cacheClass = $cacheClass;
$this->categoryName = $categoryName;
$this->supportI18n = $supportI18n;
// load cache on init
- $this->readCache($loadActiveOptions);
+ $this->readCache();
}
/**
/**
* Gets all options and option categories from cache.
- *
- * @param boolean $loadActiveOptions
*/
- protected function readCache($loadActiveOptions) {
+ protected function readCache() {
CacheHandler::getInstance()->addResource(
$this->cacheName,
WCF_DIR.'cache/cache.'.$this->cacheName.'.php',
$this->cachedOptions = CacheHandler::getInstance()->get($this->cacheName, 'options');
$this->cachedCategoryStructure = CacheHandler::getInstance()->get($this->cacheName, 'categoryStructure');
$this->cachedOptionToCategories = CacheHandler::getInstance()->get($this->cacheName, 'optionToCategories');
-
- if ($loadActiveOptions) {
+ }
+
+ /**
+ * Initializes active options.
+ */
+ public function init() {
+ if (!$this->didInit) {
// get active options
$this->loadActiveOptions($this->categoryName);
-
+
// mark options as initialized
$this->didInit = true;
}
* Creates a list of all active options.
*
* @param string $parentCategoryName
- * @param array<string> $ignoreCategories
*/
- protected function loadActiveOptions($parentCategoryName, array $ignoreCategories = array()) {
- // skip ignored categories
- if (in_array($parentCategoryName, $ignoreCategories)) {
- return;
- }
-
+ protected function loadActiveOptions($parentCategoryName) {
if (!isset($this->cachedCategories[$parentCategoryName]) || $this->checkCategory($this->cachedCategories[$parentCategoryName])) {
if (isset($this->cachedOptionToCategories[$parentCategoryName])) {
foreach ($this->cachedOptionToCategories[$parentCategoryName] as $optionName) {
if (isset($this->cachedCategoryStructure[$parentCategoryName])) {
foreach ($this->cachedCategoryStructure[$parentCategoryName] as $categoryName) {
- $this->loadActiveOptions($categoryName, $ignoreCategories);
+ $this->loadActiveOptions($categoryName);
}
}
}
* @return boolean
*/
protected function checkOption(Option $option) {
- if ($option->permissions && !$this->overrideVisibility) {
+ if ($option->permissions) {
$hasPermission = false;
$permissions = explode(',', $option->permissions);
foreach ($permissions as $permission) {
* @return boolean
*/
protected function checkVisibility(Option $option) {
- return $option->isVisible($this->overrideVisibility);
- }
-
- /**
- * Overrides option visibility for administrative purposes.
- */
- public function overrideVisibility() {
- $this->overrideVisibility = true;
+ return $option->isVisible();
}
}
*/
public $inRegistration = false;
+ /**
+ * true, if within edit mode
+ * @var boolean
+ */
+ public $editMode = true;
+
/**
* true, if empty options should be removed
* @var boolean
*/
public $user = null;
- /**
- * Hides empty options.
- */
- public function hideEmptyOptions() {
- $this->removeEmptyOptions = true;
- }
-
/**
* Shows empty options.
*/
- public function showEmptyOptions() {
- $this->removeEmptyOptions = false;
+ public function showEmptyOptions($show = true) {
+ $this->removeEmptyOptions = !$show;
}
/**
- * Sets registration mode and disables visibility override.
+ * Sets registration mode.
*
* @param boolean $inRegistration
*/
- public function setInRegistration($inRegistration) {
+ public function setInRegistration($inRegistration = true) {
$this->inRegistration = $inRegistration;
- $this->overrideVisibility = false;
+ if ($inRegistration) $this->enableEditMode();
+ }
+
+ /**
+ * Enables edit mode.
+ *
+ * @param boolean $enable
+ */
+ public function enableEditMode($enable = true) {
+ $this->editMode = $enable;
}
/**
* Sets option values for a certain user.
*
* @param wcf\data\user\User $user
- * @param array<string> $ignoreCategories
*/
- public function setUser(User $user, array $ignoreCategories = array()) {
+ public function setUser(User $user) {
$this->optionValues = array();
$this->user = $user;
- if (!$this->didInit) {
- $this->loadActiveOptions($this->categoryName, $ignoreCategories);
-
- $this->didInit = true;
- }
-
+ $this->init();
foreach ($this->options as $option) {
$userOption = 'userOption' . $option->optionID;
$this->optionValues[$option->optionName] = $this->user->{$userOption};
}
}
+ /**
+ * Resets the option values.
+ */
+ public function resetOptionValues() {
+ $this->optionValues = array();
+ }
+
/**
* @see wcf\system\option\OptionHandler::getOption()
*/
* @see wcf\system\option\OptionHandler::checkVisibility()
*/
protected function checkVisibility(Option $option) {
- if ($this->user !== null) {
- $option->setUser($this->user);
+ if ($this->inRegistration && !$option->askDuringRegistration && !$option->required) {
+ return false;
}
- if ($this->inRegistration && !$option->askDuringRegistration && !$option->required) {
+ if ($option->disabled) {
return false;
}
- return $option->isVisible($this->overrideVisibility);
+ if ($this->user !== null) {
+ $option->setUser($this->user);
+ }
+
+ if ($this->editMode) {
+ return $option->isEditable();
+ }
+ else {
+ return $option->isVisible();
+ }
}
/**
return $options;
}
+
+ /**
+ * @see wcf\system\option\IOptionHandler::readData()
+ */
+ public function readData() {
+ foreach ($this->options as $option) {
+ if (!isset($this->optionValues[$option->optionName])) $this->optionValues[$option->optionName] = $option->defaultValue;
+ }
+ }
}