User options working again
authorAlexander Ebert <ebert@woltlab.com>
Mon, 21 Nov 2011 18:44:21 +0000 (19:44 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 21 Nov 2011 18:44:21 +0000 (19:44 +0100)
wcfsetup/install/files/lib/acp/form/UserEditForm.class.php
wcfsetup/install/files/lib/acp/page/UserListPage.class.php
wcfsetup/install/files/lib/system/option/OptionHandler.class.php
wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php

index 2efbfae6eb9ee9e9e954585099dd5248b98da5df..2661c9b8d6e2588f58936b40d3e2ae6be101343a 100755 (executable)
@@ -43,6 +43,11 @@ class UserEditForm extends UserAddForm {
         */
        public $user = null;
        
+       /**
+        * @see wcf\acp\form\AbstractOptionListForm::$loadActiveOptions
+        */
+       public $loadActiveOptions = false;
+       
        /**
         * @see wcf\page\IPage::readParameters()
         */
@@ -60,6 +65,9 @@ class UserEditForm extends UserAddForm {
                if (!UserGroup::isAccessibleGroup($this->user->getGroupIDs())) {
                        throw new PermissionDeniedException();
                }
+               
+               $this->optionHandler->setUser($this->user->getDecoratedObject());
+               $this->optionHandler->showEmptyOptions();
        }
        
        /**
index 972976cc9b1bbc5e1477da7ca0e202e15fc8b353..5610ac666eb49930eb21fdce2d035e7396234fd0 100755 (executable)
@@ -3,6 +3,7 @@ namespace wcf\acp\page;
 use wcf\system\menu\acp\ACPMenu;
 use wcf\data\user\User;
 use wcf\data\user\group\UserGroup;
+use wcf\data\user\option\ViewableUserOption;
 use wcf\page\SortablePage;
 use wcf\system\cache\CacheHandler;
 use wcf\system\clipboard\ClipboardHandler;
@@ -10,7 +11,6 @@ use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\event\EventHandler;
 use wcf\system\exception\SystemException;
 use wcf\system\request\LinkHandler;
-use wcf\system\user\option\UserOptions;
 use wcf\system\WCF;
 use wcf\util\DateUtil;
 use wcf\util\StringUtil;
@@ -68,6 +68,8 @@ class UserListPage extends SortablePage {
        public $columnHeads = array();
        public $sqlConditions = '';
        
+       protected $optionHandler = null;
+       
        /**
         * @see wcf\page\IPage::readParameters()
         */
@@ -217,24 +219,27 @@ class UserListPage extends SortablePage {
                        // get special columns
                        foreach ($this->users as $key => $user) {
                                foreach ($this->columns as $column) {
-                                       if (isset($this->options[$column])) {
-                                               if ($this->options[$column]->outputClass) {
-                                                       $outputObj = UserOptions::getInstance()->getOutputObject($this->options[$column]->outputClass);
-                                                       $this->columnValues[$user->userID][$column] = $outputObj->getOutput($user, $this->options[$column], $user->{$column});
-                                               }
-                                               else {
-                                                       $this->columnValues[$user->userID][$column] = StringUtil::encodeHTML($user->{$column});
-                                               }
-                                       }
-                                       else {
-                                               switch ($column) {
-                                                       case 'email':
-                                                               $this->columnValues[$user->userID][$column] = '<a href="mailto:'.StringUtil::encodeHTML($user->email).'">'.StringUtil::encodeHTML($user->email).'</a>';
-                                                               break;
-                                                       case 'registrationDate':
-                                                               $this->columnValues[$user->userID][$column] = DateUtil::format(DateUtil::getDateTimeByTimestamp($user->{$column}), DateUtil::DATE_FORMAT);
-                                                               break;
-                                               }
+                                       switch ($column) {
+                                               case 'email':
+                                                       $this->columnValues[$user->userID][$column] = '<a href="mailto:'.StringUtil::encodeHTML($user->email).'">'.StringUtil::encodeHTML($user->email).'</a>';
+                                               break;
+                                               
+                                               case 'registrationDate':
+                                                       $this->columnValues[$user->userID][$column] = DateUtil::format(DateUtil::getDateTimeByTimestamp($user->{$column}), DateUtil::DATE_FORMAT);
+                                               break;
+                                               
+                                               default:
+                                                       if (isset($this->options[$column])) {
+                                                               if ($this->options[$column]->outputClass) {
+                                                                       $this->options[$column]->setOptionValue($user);
+                                                                       $outputObj = $this->options[$column]->getOutputObject();
+                                                                       $this->columnValues[$user->userID][$column] = $outputObj->getOutput($user, $this->options[$column]->getDecoratedObject(), $user->{$column});
+                                                               }
+                                                               else {
+                                                                       $this->columnValues[$user->userID][$column] = StringUtil::encodeHTML($user->{$column});
+                                                               }
+                                                       }
+                                               break;
                                        }
                                }
                        }
@@ -280,6 +285,11 @@ class UserListPage extends SortablePage {
                        'wcf\system\cache\builder\OptionCacheBuilder'
                );
                $this->options = CacheHandler::getInstance()->get($cacheName, 'options');
+               
+               foreach ($this->options as &$option) {
+                       $option = new ViewableUserOption($option);
+               }
+               unset($option);
        }
        
        /**
index 5ca9d1293ce71b57dd4425750251e61c88cd5b39..554ebb73176704b1a629bf5566975954b067dbcf 100644 (file)
@@ -173,14 +173,15 @@ class OptionHandler implements IOptionHandler {
                                        if ($level <= 1) {
                                                $superCategory['categories'] = $this->getOptionTree($superCategoryName, $level + 1);
                                        }
-                                       if ($level > 1 || count($superCategory['categories']) == 0) {
+                                       
+                                       if ($level > 1 || empty($superCategory['categories'])) {
                                                $superCategory['options'] = $this->getCategoryOptions($superCategoryName);
                                        }
                                        else {
                                                $superCategory['options'] = $this->getCategoryOptions($superCategoryName, false);
                                        }
                                        
-                                       if (count($superCategory['categories']) > 0 || count($superCategory['options']) > 0) {
+                                       if (!empty($superCategory['categories']) || !empty($superCategory['options'])) {
                                                $tree[] = $superCategory;
                                        }
                                }
@@ -209,7 +210,10 @@ class OptionHandler implements IOptionHandler {
                                if (!isset($this->options[$optionName]) || !$this->checkOption($this->options[$optionName])) continue;
                                
                                // add option to list
-                               $children[] = $this->getOption($optionName);
+                               $option = $this->getOption($optionName);
+                               if ($option !== null) {
+                                       $children[] = $this->getOption($optionName);
+                               }
                        }
                }
                
index c692513f3cdf09cd4554f3d55f70915499ab94aa..1eef943e3e44d3a8fdc5801b9e5d8b63875edf10 100644 (file)
@@ -18,12 +18,32 @@ use wcf\system\option\OptionHandler;
  * @category   Community Framework
  */
 class UserOptionHandler extends OptionHandler {
+       /**
+        * true, if empty options should be removed
+        * @var boolean
+        */
+       public $removeEmptyOptions = false;
+       
        /**
         * current user
         * @var wcf\data\user\User
         */
        public $user = null;
        
+       /**
+        * Hides empty options.
+        */
+       public function hideEmptyOptions() {
+               $this->removeEmptyOptions = true;
+       }
+       
+       /**
+        * Shows empty options.
+        */
+       public function showEmptyOptions() {
+               $this->removeEmptyOptions = false;
+       }
+       
        /**
         * Sets option values for a certain user.
         * 
@@ -46,16 +66,19 @@ class UserOptionHandler extends OptionHandler {
        }
        
        /**
-        * @see wcf\system\option\OptionHandler::getCategoryOptions()
+        * @see wcf\system\option\OptionHandler::getOption()
         */
-       public function getCategoryOptions($categoryName = '', $inherit = true) {
-               $options = parent::getCategoryOptions($categoryName, $inherit);
+       public function getOption($optionName) {
+               $optionData = parent::getOption($optionName);
+               
+               $optionData['object'] = new ViewableUserOption($optionData['object']);
+               $optionData['object']->setOptionValue($this->user);
                
-               foreach ($options as $optionData) {
-                       $optionData['object'] = new ViewableUserOption($optionData['object']);
-                       $optionData['object']->setOptionValue($this->user);
+               if ($this->removeEmptyOptions && empty($optionData['object']->optionValue)) {
+                       return null;
                }
-               die('<pre>'.print_r($options, true));
+               
+               return $optionData;
        }
        
        /**