From: Alexander Ebert Date: Mon, 21 Nov 2011 18:44:21 +0000 (+0100) Subject: User options working again X-Git-Tag: 2.0.0_Beta_1~1583^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c897c9b41edabc6904ed8df8e12168a8e15f9775;p=GitHub%2FWoltLab%2FWCF.git User options working again --- diff --git a/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php index 2efbfae6eb..2661c9b8d6 100755 --- a/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php @@ -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(); } /** diff --git a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php index 972976cc9b..5610ac666e 100755 --- a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php @@ -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] = ''.StringUtil::encodeHTML($user->email).''; - 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] = ''.StringUtil::encodeHTML($user->email).''; + 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); } /** diff --git a/wcfsetup/install/files/lib/system/option/OptionHandler.class.php b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php index 5ca9d1293c..554ebb7317 100644 --- a/wcfsetup/install/files/lib/system/option/OptionHandler.class.php +++ b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php @@ -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); + } } } 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 c692513f3c..1eef943e3e 100644 --- a/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php +++ b/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php @@ -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('
'.print_r($options, true));
+		
+		return $optionData;
 	}
 	
 	/**