<?php
namespace wcf\acp\form;
use wcf\data\user\option\category\UserOptionCategoryList;
+use wcf\data\user\option\UserOption;
use wcf\data\user\option\UserOptionAction;
use wcf\data\user\option\UserOptionEditor;
use wcf\form\AbstractForm;
* Shows the user option add form.
*
* @author Marcel Werk
- * @copyright 2001-2015 WoltLab GmbH
+ * @copyright 2001-2016 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage acp.form
*/
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
/**
* 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<string>
+ * @var string[]
*/
- public static $availableOptionTypes = array(
+ public static $availableOptionTypes = [
'aboutMe',
'birthday',
'boolean',
'textarea',
'message',
'URL'
- );
+ ];
/**
* list of option type that require select options
- * @var array<string>
+ * @var string[]
*/
- public static $optionTypesUsingSelectOptions = array(
+ public static $optionTypesUsingSelectOptions = [
'checkboxes',
'multiSelect',
'radioButton',
'select'
- );
+ ];
/**
- * @see \wcf\page\IPage::readParameters()
+ * @inheritDoc
*/
public function readParameters() {
parent::readParameters();
// 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();
}
/**
- * @see \wcf\form\IForm::validate()
+ * @inheritDoc
*/
public function validate() {
parent::validate();
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');
}
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,
'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();
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
}
/**
- * @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,
'action' => 'add',
'availableCategories' => $this->availableCategories,
'availableOptionTypes' => self::$availableOptionTypes
- ));
+ ]);
}
}
/**
* 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 <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage data.user.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';
}
/**
- * @see \wcf\data\option\Option::isVisible()
+ * @inheritDoc
*/
public function isVisible() {
// proceed if option is visible for all
}
/**
- * 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')) {
}
}
+ 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
*/
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;
/**
* 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 <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.option.user
}
// 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;
}
}
if ($this->editMode) {
- return $option->isEditable();
+ return $option->isEditable($this->inRegistration);
}
else {
return $option->isVisible();
// 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]);
}
}