2 namespace wcf\system\option
;
3 use wcf\data\option\Option
;
4 use wcf\system\database\util\PreparedStatementConditionBuilder
;
5 use wcf\system\exception\UserInputException
;
7 use wcf\util\StringUtil
;
10 * Option type implementation for radio buttons.
13 * @copyright 2001-2014 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage system.option
17 * @category Community Framework
19 class RadioButtonOptionType
extends AbstractOptionType
implements ISearchableUserOption
{
21 * name of the template that contains the form element of this option type
24 public $templateName = 'radioButtonOptionType';
27 * @see \wcf\system\option\IOptionType::getFormElement()
29 public function getFormElement(Option
$option, $value) {
31 $selectOptions = $option->parseSelectOptions();
33 $availableOptions = $option->parseMultipleEnableOptions();
35 'disableOptions' => array(),
36 'enableOptions' => array()
39 foreach ($availableOptions as $key => $enableOptions) {
40 $optionData = Option
::parseEnableOptions($enableOptions);
42 $options['disableOptions'][$key] = $optionData['disableOptions'];
43 $options['enableOptions'][$key] = $optionData['enableOptions'];
46 WCF
::getTPL()->assign(array(
47 'disableOptions' => $options['disableOptions'],
48 'enableOptions' => $options['enableOptions'],
50 'selectOptions' => $selectOptions,
53 return WCF
::getTPL()->fetch($this->templateName
);
57 * @see \wcf\system\option\IOptionType::validate()
59 public function validate(Option
$option, $newValue) {
60 if (!empty($newValue)) {
61 $options = $option->parseSelectOptions();
62 if (!isset($options[$newValue])) {
63 throw new UserInputException($option->optionName
, 'validationFailed');
69 * @see \wcf\system\option\ISearchableUserOption::getSearchFormElement()
71 public function getSearchFormElement(Option
$option, $value) {
72 return $this->getFormElement($option, $value);
76 * @see \wcf\system\option\ISearchableUserOption::getCondition()
78 public function getCondition(PreparedStatementConditionBuilder
&$conditions, Option
$option, $value) {
79 $value = StringUtil
::trim($value);
80 if (!$value) return false;
82 $conditions->add("option_value.userOption".$option->optionID
." = ?", array($value));