2 namespace wcf\data\custom\option
;
3 use wcf\data\option\Option
;
4 use wcf\system\bbcode\MessageParser
;
5 use wcf\system\bbcode\SimpleMessageParser
;
6 use wcf\system\exception\NotImplementedException
;
9 use wcf\util\OptionUtil
;
10 use wcf\util\StringUtil
;
13 * Default implementation for custom options.
15 * @author Alexander Ebert
16 * @copyright 2001-2017 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package WoltLabSuite\Core\Data\Custom\Option
21 * @property-read integer $optionID unique id of the option
22 * @property-read string $optionTitle title of the option or name of language item which contains the title
23 * @property-read string $optionDescription description of the option or name of language item which contains the description
24 * @property-read string $optionType type of the option which determines its input and output
25 * @property-read string $defaultValue default value of the option
26 * @property-read string $validationPattern regular expression used to validate the value of the option
27 * @property-read string $selectOptions possible values of the option separated by newlines
28 * @property-read integer $required is `1` if the option has to be filled out, otherwise `0`
29 * @property-read integer $showOrder position of the option relation tp the other options
30 * @property-read integer $isDisabled is `1` if the option is disabled, otherwise `0`
31 * @property-read integer $originIsSystem is `1` if the option has been delivered by a package, otherwise `0` (i.e. the option has been created in the ACP)
33 abstract class CustomOption
extends Option
{
38 protected $optionValue = '';
41 * Returns true if the option is visible
45 public function isVisible() {
46 return !$this->isDisabled
;
52 public static function getDatabaseTableAlias() {
53 throw new NotImplementedException();
57 * Returns the value of this option.
61 public function getOptionValue() {
62 return $this->optionValue
;
66 * Sets the value of this option.
68 * @param string $value
70 public function setOptionValue($value) {
71 $this->optionValue
= $value;
75 * Returns the formatted value of this option.
79 public function getFormattedOptionValue() {
80 switch ($this->optionType
) {
82 return WCF
::getLanguage()->get('wcf.acp.option.optionType.boolean.'.($this->optionValue ?
'yes' : 'no'));
85 $year = $month = $day = 0;
86 $optionValue = explode('-', $this->optionValue
);
87 if (isset($optionValue[0])) $year = intval($optionValue[0]);
88 if (isset($optionValue[1])) $month = intval($optionValue[1]);
89 if (isset($optionValue[2])) $day = intval($optionValue[2]);
90 return DateUtil
::format(DateUtil
::getDateTimeByTimestamp(gmmktime(12, 1, 1, $month, $day, $year)), DateUtil
::DATE_FORMAT
);
93 return StringUtil
::formatDouble(intval($this->optionValue
));
96 return StringUtil
::formatInteger(intval($this->optionValue
));
100 $selectOptions = OptionUtil
::parseSelectOptions($this->selectOptions
);
101 if (isset($selectOptions[$this->optionValue
])) return WCF
::getLanguage()->get($selectOptions[$this->optionValue
]);
106 $selectOptions = OptionUtil
::parseSelectOptions($this->selectOptions
);
107 $values = explode("\n", $this->optionValue
);
109 foreach ($values as $value) {
110 if (isset($selectOptions[$value])) {
111 if (!empty($result)) $result .= "<br>\n";
112 $result .= WCF
::getLanguage()->get($selectOptions[$value]);
118 return SimpleMessageParser
::getInstance()->parse($this->optionValue
);
121 return MessageParser
::getInstance()->parse($this->optionValue
);
124 return StringUtil
::getAnchorTag($this->optionValue
);
127 return StringUtil
::encodeHTML($this->optionValue
);
132 * Returns true if this option can be deleted, defaults to false for
133 * options created through the package system.
137 public function canDelete() {
138 return !$this->originIsSystem
;