From: Alexander Ebert Date: Fri, 18 Nov 2011 16:21:36 +0000 (+0100) Subject: Modified user options to reuse code X-Git-Tag: 2.0.0_Beta_1~1586 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=743d2a6aaeacf736610920697cf6aa2df7c4cac9;p=GitHub%2FWoltLab%2FWCF.git Modified user options to reuse code --- diff --git a/wcfsetup/install/files/lib/data/user/option/IUserOptionOutput.class.php b/wcfsetup/install/files/lib/data/user/option/IUserOptionOutput.class.php deleted file mode 100644 index eb4d7815b1..0000000000 --- a/wcfsetup/install/files/lib/data/user/option/IUserOptionOutput.class.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage data.user.option - * @category Community Framework - */ -interface IUserOptionOutput { - /** - * Returns a short version of the html code for the output of the given user option. - * - * @param User $user - * @param array $optionData - * @param string $value - * @return string - */ - public function getShortOutput(User $user, $optionData, $value); - - /** - * Returns a medium version of the html code for the output of the given user option. - * - * @param User $user - * @param array $optionData - * @param string $value - * @return string - */ - public function getMediumOutput(User $user, $optionData, $value); - - /** - * Returns the html code for the output of the given user option. - * - * @param User $user - * @param array $optionData - * @param string $value - * @return string - */ - public function getOutput(User $user, $optionData, $value); -} diff --git a/wcfsetup/install/files/lib/data/user/option/UserOption.class.php b/wcfsetup/install/files/lib/data/user/option/UserOption.class.php index 5f1cb023b5..ce9732206a 100644 --- a/wcfsetup/install/files/lib/data/user/option/UserOption.class.php +++ b/wcfsetup/install/files/lib/data/user/option/UserOption.class.php @@ -1,6 +1,7 @@ + */ + public static $outputObjects = array(); + + /** + * user option value + * @var string + */ + public $optionValue = ''; + + /** + * user option output data + * @var array + */ + public $outputData = array(); + + /** + * Sets option values for a specific user. + * + * @param wcf\data\user\User $user + */ + public function setOptionValue(User $user) { + $userOption = 'userOption' . $this->optionID; + $optionValue = $user->{$userOption}; + + // use output class + if ($this->outputClass) { + $outputObj = $this->getOutputObject($this->outputClass); + + if ($outputObj instanceof IUserOptionOutputContactInformation) { + $this->outputData = $outputObj->getOutputData($user, $this->getDecoratedObject(), $optionValue); + } + + if ($this->outputType == 'normal') $this->optionValue = $outputObj->getOutput($user, $this->getDecoratedObject(), $optionValue); + else if ($this->outputType == 'short') $this->optionValue = $outputObj->getShortOutput($user, $this->getDecoratedObject(), $optionValue); + else $this->optionValue = $outputObj->getMediumOutput($user, $this->getDecoratedObject(), $optionValue); + } + else { + $this->optionValue = StringUtil::encodeHTML($optionValue); + } + } + + /** + * Returns the output object for current user option. + * + * @return wcf\system\option\user\IUserOptionOutput + */ + public function getOutputObject() { + if (!isset(self::$outputObjects[$this->className])) { + // create instance + if (!class_exists($this->className)) { + throw new SystemException("unable to find class '".$this->className."'"); + } + + // validate interface + if (!ClassUtil::isInstanceOf($this->className, 'wcf\system\user\option\IUserOptionOutput')) { + throw new SystemException("'".$this->className."' should implement wcf\system\user\option\IUserOptionOutput"); + } + + self::$outputObjects[$this->className] = new $this->className(); + } + + return self::$outputObjects[$this->className]; + } +} diff --git a/wcfsetup/install/files/lib/system/option/user/IUserOptionOutput.class.php b/wcfsetup/install/files/lib/system/option/user/IUserOptionOutput.class.php new file mode 100644 index 0000000000..0df3d17552 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/user/IUserOptionOutput.class.php @@ -0,0 +1,47 @@ + + * @package com.woltlab.wcf + * @subpackage system.option.user + * @category Community Framework + */ +interface IUserOptionOutput { + /** + * Returns a short version of the html code for the output of the given user option. + * + * @param wcf\data\user\User $user + * @param wcf\data\user\option\UserOption $option + * @param string $value + * @return string + */ + public function getShortOutput(User $user, UserOption $option, $value); + + /** + * Returns a medium version of the html code for the output of the given user option. + * + * @param wcf\data\user\User $user + * @param wcf\data\user\option\UserOption $option + * @param string $value + * @return string + */ + public function getMediumOutput(User $user, UserOption $option, $value); + + /** + * Returns the html code for the output of the given user option. + * + * @param wcf\data\user\User $user + * @param wcf\data\user\option\UserOption $option + * @param string $value + * @return string + */ + public function getOutput(User $user, UserOption $option, $value); +} +?> diff --git a/wcfsetup/install/files/lib/system/option/user/IUserOptionOutputContactInformation.class.php b/wcfsetup/install/files/lib/system/option/user/IUserOptionOutputContactInformation.class.php new file mode 100644 index 0000000000..419c6958e4 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/user/IUserOptionOutputContactInformation.class.php @@ -0,0 +1,27 @@ + + * @package com.woltlab.wcf + * @subpackage system.option.user + * @category Community Framework + */ +interface IUserOptionOutputContactInformation { + /** + * Returns the output data of this user option. + * + * @param wcf\data\user\User $user + * @param wcf\data\user\option\UserOption $optionData + * @param string $value + * @return array + */ + public function getOutputData(User $user, UserOption $option, $value); +} +?> 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 1b474eac2f..eb21035a39 100644 --- a/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php +++ b/wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php @@ -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\ViewableUserOption; use wcf\data\user\User; use wcf\system\exception\UserInputException; use wcf\system\option\OptionHandler; @@ -17,15 +18,36 @@ use wcf\system\option\OptionHandler; * @category Community Framework */ class UserOptionHandler extends OptionHandler { + /** + * current user + * @var wcf\data\user\User + */ + public $user = null; + + /** + * Sets option values for a certain user. + * + * @param wcf\data\user\User + */ public function setUser(User $user) { $this->optionValues = array(); + $this->user = $user; foreach ($this->options as $option) { $userOption = 'userOption' . $option->optionID; - $this->optionValues[$option->optionName] = $user->{$userOption}; + $this->optionValues[$option->optionName] = $this->user->{$userOption}; } } + /** + * @see wcf\system\option\OptionHandler::getCategoryOptions() + */ + public function getCategoryOptions($categoryName = '', $inherit = true) { + $options = parent::getCategoryOptions($categoryName, $inherit); + + die('
'.print_r($options, true));
+	}
+	
 	/**
 	 * @see	wcf\system\option\OptionHandler::validateOption()
 	 */