+++ /dev/null
-<?php
-namespace wcf\data\user\option;
-use wcf\data\User;
-
-/**
- * Any user option output class should implement this interface.
- *
- * @author Marcel Werk
- * @copyright 2001-2011 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @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);
-}
<?php
namespace wcf\data\user\option;
use wcf\data\option\Option;
+use wcf\system\option\user\IUserOptionOutput;
/**
* Represents a user option.
--- /dev/null
+<?php
+namespace wcf\data\user\option;
+use wcf\data\user\User;
+use wcf\data\DatabaseObjectDecorator;
+use wcf\system\option\user\IUserOptionOutputContactInformation;
+use wcf\util\ClassUtil;
+use wcf\util\StringUtil;
+
+class ViewableUserOption extends DatabaseObjectDecorator {
+ /**
+ * @see wcf\data\DatabaseObjectDecorator::$baseClass
+ */
+ protected static $baseClass = 'wcf\data\user\option\UserOption';
+
+ /**
+ * list of output objects
+ * @var array<wcf\system\option\user\IUserOptionOutput>
+ */
+ 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];
+ }
+}
--- /dev/null
+<?php
+namespace wcf\system\option\user;
+use wcf\data\user\option\UserOption;
+use wcf\data\user\User;
+
+/**
+ * Any user option output class should implement this interface.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2011 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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);
+}
+?>
--- /dev/null
+<?php
+namespace wcf\system\option\user;
+use wcf\data\user\option\UserOption;
+use wcf\data\user\User;
+
+/**
+ * Any user option output class should implement this interface.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2011 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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);
+}
+?>
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;
* @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('<pre>'.print_r($options, true));
+ }
+
/**
* @see wcf\system\option\OptionHandler::validateOption()
*/