Add EDITABILITY_OWNER_DURING_REGISTRATION option
authorjoshuaruesweg <josh@joshsboard.de>
Mon, 10 Aug 2015 15:18:58 +0000 (17:18 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Sun, 10 Jan 2016 17:37:50 +0000 (18:37 +0100)
Closes #1935

wcfsetup/install/files/acp/templates/userOptionAdd.tpl
wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php
wcfsetup/install/files/lib/data/user/option/UserOption.class.php
wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 1aaba8b6168532ce7eabead2835c3f88495b85e0..d89ddbeb0bbed61d4e5c8cc050fecdec88e7299f 100644 (file)
                                                        <option value="1"{if $editable == 1} selected="selected"{/if}>{lang}wcf.acp.user.option.editable.1{/lang}</option>
                                                        <option value="2"{if $editable == 2} selected="selected"{/if}>{lang}wcf.acp.user.option.editable.2{/lang}</option>
                                                        <option value="3"{if $editable == 3} selected="selected"{/if}>{lang}wcf.acp.user.option.editable.3{/lang}</option>
+                                                       <option value="6"{if $editable == 6} selected="selected"{/if}>{lang}wcf.acp.user.option.editable.6{/lang}</option>
                                                </select>
                                        </dd>
                                </dl>
index d8ec3574b6b8c7f943de43dcad5cb8ee51842f81..bd2be4e8769a71a6ed7117d2c83cc8918ecc0908 100644 (file)
@@ -1,6 +1,7 @@
 <?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;
@@ -13,7 +14,7 @@ use wcf\util\StringUtil;
  * 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
@@ -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<string>
+        * @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<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();
@@ -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
-               ));
+               ]);
        }
 }
index 9896ab66d889750b8dd46196da359e7b3df4a9ed..107a7d338c1aaeea07b573bb90257da544ec5c89 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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
         */
index bc0b10b253dc90bf4f5c86f086fe048d05d7e28b..8b7037706fcb43a5d1b663e5634983031ce73cd7 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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]);
                                }
                        }
index 827b4defc76714be0a13b2b2c71d676c72b30af7..413f002e071da91730f7d32876f822cdbd70cfbb 100644 (file)
@@ -1655,6 +1655,7 @@ Wenn Sie unter <em>System -&gt; Optionen -&gt; Allgemein -&gt; E-Mails</em> alle
                <item name="wcf.acp.user.option.editable.1"><![CDATA[Eigentümer]]></item>
                <item name="wcf.acp.user.option.editable.2"><![CDATA[Administrator]]></item>
                <item name="wcf.acp.user.option.editable.3"><![CDATA[Eigentümer und Administrator]]></item>
+               <item name="wcf.acp.user.option.editable.6"><![CDATA[Eigentümer bei Erstanmeldung und Administrator]]></item>
                <item name="wcf.acp.user.option.optionType"><![CDATA[Feldtyp]]></item>
                <item name="wcf.acp.user.option.optionType.description"><![CDATA[Die Namen entsprechen in der Regel den HTML-Elementen, die benötigt werden, um so ein Feld beim Benutzer abzufragen.]]></item>
                <item name="wcf.acp.user.option.askDuringRegistration"><![CDATA[Das Feld wird im Registrierungs-Formular angezeigt.]]></item>
index 9817f07522f884ecda4f8e7ef50e96aca379cabf..3d9bb85b4459fdf266c35778846671a96bcfdfc7 100644 (file)
@@ -1654,6 +1654,7 @@ You can define the default sender in <em>System -&gt; Options -&gt; General -&gt
                <item name="wcf.acp.user.option.editable.1"><![CDATA[Owner]]></item>
                <item name="wcf.acp.user.option.editable.2"><![CDATA[Administrator]]></item>
                <item name="wcf.acp.user.option.editable.3"><![CDATA[Owner and Administrator]]></item>
+               <item name="wcf.acp.user.option.editable.6"><![CDATA[Owner during registration and Administrator]]></item>
                <item name="wcf.acp.user.option.optionType"><![CDATA[Option Type]]></item>
                <item name="wcf.acp.user.option.optionType.description"><![CDATA[Option names usually equal the HTML-tag used as input element.]]></item>
                <item name="wcf.acp.user.option.askDuringRegistration"><![CDATA[Field will be visible during registration.]]></item>