Added switch to handle user options during registration
authorAlexander Ebert <ebert@woltlab.com>
Mon, 12 Mar 2012 16:35:48 +0000 (17:35 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 12 Mar 2012 16:35:48 +0000 (17:35 +0100)
wcfsetup/install/files/lib/acp/form/UserAddForm.class.php
wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php

index 46330a6987fef29812ba486cf64570f37897f48d..a985beef90df69a07462a9f2934a4e2095e3ab66 100644 (file)
@@ -157,7 +157,7 @@ class UserAddForm extends UserOptionListForm {
                
                // validate user language
                $language = LanguageFactory::getInstance()->getLanguage($this->languageID);
-               if (!$language->languageID) {
+               if ($language === null || !$language->languageID) {
                        // use default language
                        $this->languageID = LanguageFactory::getInstance()->getDefaultLanguageID();
                }
index 7036dc88eaece756f866786000a555102d8d4bd7..a6fda43f964d4fb46afe2a7cec2fcb39d4d7121f 100644 (file)
@@ -18,6 +18,12 @@ use wcf\system\option\OptionHandler;
  * @category   Community Framework
  */
 class UserOptionHandler extends OptionHandler {
+       /**
+        * true, if within registration process
+        * @var boolean
+        */
+       public $inRegistration = false;
+       
        /**
         * true, if empty options should be removed
         * @var boolean
@@ -44,6 +50,15 @@ class UserOptionHandler extends OptionHandler {
                $this->removeEmptyOptions = false;
        }
        
+       /**
+        * Sets registration mode.
+        * 
+        * @param       boolean         $inRegistration
+        */
+       public function setInRegistration($inRegistration) {
+               $this->inRegistration = $inRegistration;
+       }
+       
        /**
         * Sets option values for a certain user.
         * 
@@ -114,6 +129,28 @@ class UserOptionHandler extends OptionHandler {
                        $option->setUser($this->user);
                }
                
+               if ($this->inRegistration && !$option->askDuringRegistration) {
+                       return false;
+               }
+               
                return $option->isVisible();
        }
+       
+       /**
+        * @see wcf\system\option\OptionHandler::save()
+        */
+       public function save($categoryName = null, $optionPrefix = null) {
+               $options = parent::save($categoryName, $optionPrefix);
+               
+               // 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)) {
+                                       unset($options[$option->optionID]);
+                               }
+                       }
+               }
+               
+               return $options;
+       }
 }