Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / option / RadioButtonOptionType.class.php
1 <?php
2 namespace wcf\system\option;
3 use wcf\data\option\Option;
4 use wcf\system\database\util\PreparedStatementConditionBuilder;
5 use wcf\system\exception\UserInputException;
6 use wcf\system\WCF;
7 use wcf\util\StringUtil;
8
9 /**
10 * Option type implementation for radio buttons.
11 *
12 * @author Marcel Werk
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
18 */
19 class RadioButtonOptionType extends AbstractOptionType implements ISearchableUserOption {
20 /**
21 * name of the template that contains the form element of this option type
22 * @var string
23 */
24 public $templateName = 'radioButtonOptionType';
25
26 /**
27 * @see \wcf\system\option\IOptionType::getFormElement()
28 */
29 public function getFormElement(Option $option, $value) {
30 // get options
31 $selectOptions = $option->parseSelectOptions();
32
33 $availableOptions = $option->parseMultipleEnableOptions();
34 $options = array(
35 'disableOptions' => array(),
36 'enableOptions' => array()
37 );
38
39 foreach ($availableOptions as $key => $enableOptions) {
40 $optionData = Option::parseEnableOptions($enableOptions);
41
42 $options['disableOptions'][$key] = $optionData['disableOptions'];
43 $options['enableOptions'][$key] = $optionData['enableOptions'];
44 }
45
46 WCF::getTPL()->assign(array(
47 'disableOptions' => $options['disableOptions'],
48 'enableOptions' => $options['enableOptions'],
49 'option' => $option,
50 'selectOptions' => $selectOptions,
51 'value' => $value
52 ));
53 return WCF::getTPL()->fetch($this->templateName);
54 }
55
56 /**
57 * @see \wcf\system\option\IOptionType::validate()
58 */
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');
64 }
65 }
66 }
67
68 /**
69 * @see \wcf\system\option\ISearchableUserOption::getSearchFormElement()
70 */
71 public function getSearchFormElement(Option $option, $value) {
72 return $this->getFormElement($option, $value);
73 }
74
75 /**
76 * @see \wcf\system\option\ISearchableUserOption::getCondition()
77 */
78 public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) {
79 $value = StringUtil::trim($value);
80 if (!$value) return false;
81
82 $conditions->add("option_value.userOption".$option->optionID." = ?", array($value));
83 return true;
84 }
85 }