From 5e67d784db7525676f40e055e58c0d27b539b309 Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Mon, 10 Aug 2015 17:18:58 +0200 Subject: [PATCH] Add EDITABILITY_OWNER_DURING_REGISTRATION option Closes #1935 --- .../files/acp/templates/userOptionAdd.tpl | 1 + .../lib/acp/form/UserOptionAddForm.class.php | 71 +++++++++++-------- .../lib/data/user/option/UserOption.class.php | 35 ++++++--- .../option/user/UserOptionHandler.class.php | 11 +-- wcfsetup/install/lang/de.xml | 1 + wcfsetup/install/lang/en.xml | 1 + 6 files changed, 77 insertions(+), 43 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/userOptionAdd.tpl b/wcfsetup/install/files/acp/templates/userOptionAdd.tpl index 1aaba8b616..d89ddbeb0b 100644 --- a/wcfsetup/install/files/acp/templates/userOptionAdd.tpl +++ b/wcfsetup/install/files/acp/templates/userOptionAdd.tpl @@ -174,6 +174,7 @@ + diff --git a/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php b/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php index d8ec3574b6..bd2be4e876 100644 --- a/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php @@ -1,6 +1,7 @@ * @package com.woltlab.wcf * @subpackage acp.form @@ -21,14 +22,14 @@ use wcf\util\StringUtil; */ class UserOptionAddForm extends AbstractForm { /** - * @see \wcf\page\AbstractPage::$activeMenuItem + * @inheritDoc */ public $activeMenuItem = 'wcf.acp.menu.link.user.option.add'; /** - * @see \wcf\page\AbstractPage::$neededPermissions + * @inheritDoc */ - public $neededPermissions = array('admin.user.canManageUserOption'); + public $neededPermissions = ['admin.user.canManageUserOption']; /** * option name @@ -116,15 +117,27 @@ class UserOptionAddForm extends AbstractForm { /** * available option categories - * @var array<\wcf\data\user\option\UserOptionCategory> + * @var \wcf\data\user\option\UserOptionCategory[] */ - public $availableCategories = array(); - + public $availableCategories = []; + + /** + * valid editability bits for UserOptions + * @var int[] + */ + public $validEditableBits = [ + UserOption::EDITABILITY_NONE, + UserOption::EDITABILITY_OWNER, + UserOption::EDITABILITY_ADMINISTRATOR, + UserOption::EDITABILITY_ALL, + UserOption::EDITABILITY_OWNER_DURING_REGISTRATION_AND_ADMINISTRATOR + ]; + /** * available option types - * @var array + * @var string[] */ - public static $availableOptionTypes = array( + public static $availableOptionTypes = [ 'aboutMe', 'birthday', 'boolean', @@ -140,21 +153,21 @@ class UserOptionAddForm extends AbstractForm { 'textarea', 'message', 'URL' - ); + ]; /** * list of option type that require select options - * @var array + * @var string[] */ - public static $optionTypesUsingSelectOptions = array( + public static $optionTypesUsingSelectOptions = [ 'checkboxes', 'multiSelect', 'radioButton', 'select' - ); + ]; /** - * @see \wcf\page\IPage::readParameters() + * @inheritDoc */ public function readParameters() { parent::readParameters(); @@ -164,13 +177,13 @@ class UserOptionAddForm extends AbstractForm { // get available categories $categoryList = new UserOptionCategoryList(); - $categoryList->getConditionBuilder()->add('parentCategoryName = ?', array('profile')); + $categoryList->getConditionBuilder()->add('parentCategoryName = ?', ['profile']); $categoryList->readObjects(); $this->availableCategories = $categoryList->getObjects(); } /** - * @see \wcf\form\IForm::readFormParameters() + * @inheritDoc */ public function readFormParameters() { parent::readFormParameters(); @@ -201,7 +214,7 @@ class UserOptionAddForm extends AbstractForm { } /** - * @see \wcf\form\IForm::validate() + * @inheritDoc */ public function validate() { parent::validate(); @@ -219,7 +232,7 @@ class UserOptionAddForm extends AbstractForm { FROM wcf".WCF_N."_user_option_category WHERE categoryName = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($this->categoryName)); + $statement->execute([$this->categoryName]); if ($statement->fetchArray() === false) { throw new UserInputException('categoryName'); } @@ -238,18 +251,18 @@ class UserOptionAddForm extends AbstractForm { throw new UserInputException('outputClass', 'doesNotExist'); } - if ($this->editable < 1 || $this->editable > 3) { - $this->editable = 3; + if (!in_array($this->editable, $this->validEditableBits)) { + $this->editable = UserOption::EDITABILITY_ALL; } } /** - * @see \wcf\form\IForm::save() + * @inheritDoc */ public function save() { parent::save(); - $this->objectAction = new UserOptionAction(array(), 'create', array('data' => array_merge($this->additionalFields, array( + $this->objectAction = new UserOptionAction([], 'create', ['data' => array_merge($this->additionalFields, [ 'optionName' => StringUtil::getRandomID(), 'categoryName' => $this->categoryName, 'optionType' => $this->optionType, @@ -264,8 +277,8 @@ class UserOptionAddForm extends AbstractForm { 'editable' => $this->editable, 'visible' => $this->visible, 'packageID' => 1, - 'additionalData' => ($this->optionType == 'select' ? serialize(array('allowEmptyValue' => true)) : '') - )))); + 'additionalData' => ($this->optionType == 'select' ? serialize(['allowEmptyValue' => true]) : '') + ])]); $this->objectAction->executeAction(); $returnValues = $this->objectAction->getReturnValues(); @@ -275,9 +288,9 @@ class UserOptionAddForm extends AbstractForm { I18nHandler::getInstance()->save('optionName', 'wcf.user.option.option'.$userOption->optionID, 'wcf.user.option'); I18nHandler::getInstance()->save('optionDescription', 'wcf.user.option.option'.$userOption->optionID.'.description', 'wcf.user.option'); $editor = new UserOptionEditor($userOption); - $editor->update(array( + $editor->update([ 'optionName' => 'option'.$userOption->optionID - )); + ]); $this->saved(); // reset values @@ -294,14 +307,14 @@ class UserOptionAddForm extends AbstractForm { } /** - * @see \wcf\page\IPage::assignVariables() + * @inheritDoc */ public function assignVariables() { parent::assignVariables(); I18nHandler::getInstance()->assignVariables(); - WCF::getTPL()->assign(array( + WCF::getTPL()->assign([ 'optionName' => $this->optionName, 'optionDescription' => $this->optionDescription, 'categoryName' => $this->categoryName, @@ -320,6 +333,6 @@ class UserOptionAddForm extends AbstractForm { 'action' => 'add', 'availableCategories' => $this->availableCategories, 'availableOptionTypes' => self::$availableOptionTypes - )); + ]); } } diff --git a/wcfsetup/install/files/lib/data/user/option/UserOption.class.php b/wcfsetup/install/files/lib/data/user/option/UserOption.class.php index 9896ab66d8..107a7d338c 100644 --- a/wcfsetup/install/files/lib/data/user/option/UserOption.class.php +++ b/wcfsetup/install/files/lib/data/user/option/UserOption.class.php @@ -7,8 +7,8 @@ use wcf\system\WCF; /** * Represents a user option. * - * @author Marcel Werk - * @copyright 2001-2015 WoltLab GmbH + * @author Joshua Rüsweg, Marcel Werk + * @copyright 2001-2016 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage data.user.option @@ -74,14 +74,26 @@ class UserOption extends Option { * @var integer */ const EDITABILITY_ALL = 3; + + /** + * editable for owner during registration + * @var integer + */ + const EDITABILITY_OWNER_DURING_REGISTRATION = 4; + + /** + * editable for owner during registration and admins (no valid bit) + * @var integer + */ + const EDITABILITY_OWNER_DURING_REGISTRATION_AND_ADMINISTRATOR = 6; /** - * @see \wcf\data\DatabaseObject::$databaseTableName + * @inheritDoc */ protected static $databaseTableName = 'user_option'; /** - * @see \wcf\data\DatabaseObject::$databaseTableIndexName + * @inheritDoc */ protected static $databaseTableIndexName = 'optionID'; @@ -107,7 +119,7 @@ class UserOption extends Option { } /** - * @see \wcf\data\option\Option::isVisible() + * @inheritDoc */ public function isVisible() { // proceed if option is visible for all @@ -138,11 +150,12 @@ class UserOption extends Option { } /** - * Returns true if this option is editable. - * + * Returns true iff this option is editable. + * + * @param boolean $inRegistration True iff the user currently is in registration. * @return boolean */ - public function isEditable() { + public function isEditable($inRegistration = false) { // check admin permissions if ($this->editable & self::EDITABILITY_ADMINISTRATOR) { if (WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) { @@ -157,11 +170,15 @@ class UserOption extends Option { } } + if ($inRegistration && $this->editable & self::EDITABILITY_OWNER_DURING_REGISTRATION) { + return true; + } + return false; } /** - * Returns true if this user option can be deleted. + * Returns true iff this user option can be deleted. * * @return boolean */ diff --git a/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php b/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php index bc0b10b253..8b7037706f 100644 --- a/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php +++ b/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php @@ -2,6 +2,7 @@ namespace wcf\system\option\user; use wcf\data\option\category\OptionCategory; use wcf\data\option\Option; +use wcf\data\user\option\UserOption; use wcf\data\user\option\ViewableUserOption; use wcf\data\user\User; use wcf\system\exception\UserInputException; @@ -13,8 +14,8 @@ use wcf\util\MessageUtil; /** * Handles user options. * - * @author Alexander Ebert - * @copyright 2001-2015 WoltLab GmbH + * @author Alexander Ebert, Joshua Rüsweg + * @copyright 2001-2016 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.option.user @@ -224,7 +225,7 @@ class UserOptionHandler extends OptionHandler { } // in registration - if ($this->inRegistration && !$option->askDuringRegistration && !$option->required && ($option->optionName != 'birthday' || !REGISTER_MIN_USER_AGE)) { + if ($this->inRegistration && !$option->askDuringRegistration && !$option->required && !($option->editable & UserOption::EDITABILITY_OWNER_DURING_REGISTRATION) && ($option->optionName != 'birthday' || !REGISTER_MIN_USER_AGE)) { return false; } @@ -242,7 +243,7 @@ class UserOptionHandler extends OptionHandler { } if ($this->editMode) { - return $option->isEditable(); + return $option->isEditable($this->inRegistration); } else { return $option->isVisible(); @@ -258,7 +259,7 @@ class UserOptionHandler extends OptionHandler { // remove options which are not asked during registration if ($this->inRegistration && !empty($options)) { foreach ($this->options as $option) { - if (!$option->askDuringRegistration && array_key_exists($option->optionID, $options)) { + if (!$option->askDuringRegistration && !($option->editable & UserOption::EDITABILITY_OWNER_DURING_REGISTRATION) && array_key_exists($option->optionID, $options)) { unset($options[$option->optionID]); } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 827b4defc7..413f002e07 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1655,6 +1655,7 @@ Wenn Sie unter System -> Optionen -> Allgemein -> E-Mails alle + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 9817f07522..3d9bb85b44 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1654,6 +1654,7 @@ You can define the default sender in System -> Options -> General -> + -- 2.20.1