Merge branch '2.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / option / SelectOptionType.class.php
CommitLineData
158bd3ca
TD
1<?php
2namespace wcf\system\option;
3use wcf\data\option\Option;
158bd3ca
TD
4use wcf\system\WCF;
5
6/**
a17de04e
MS
7 * Option type implementation for select lists.
8 *
158bd3ca 9 * @author Marcel Werk
ca4ba303 10 * @copyright 2001-2014 WoltLab GmbH
158bd3ca
TD
11 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12 * @package com.woltlab.wcf
13 * @subpackage system.option
9f959ced 14 * @category Community Framework
158bd3ca 15 */
d683863c 16class SelectOptionType extends RadioButtonOptionType {
b6319d7b
MW
17 protected $allowEmptyValue = false;
18
158bd3ca 19 /**
0ad90fc3 20 * @see \wcf\system\option\IOptionType::getFormElement()
158bd3ca
TD
21 */
22 public function getFormElement(Option $option, $value) {
158bd3ca
TD
23 $options = $this->parseEnableOptions($option);
24
25 WCF::getTPL()->assign(array(
26 'disableOptions' => $options['disableOptions'],
27 'enableOptions' => $options['enableOptions'],
28 'option' => $option,
29 'selectOptions' => $option->parseSelectOptions(),
b6319d7b
MW
30 'value' => $value,
31 'allowEmptyValue' => ($this->allowEmptyValue || $option->allowEmptyValue)
158bd3ca 32 ));
79d5661c 33 return WCF::getTPL()->fetch('selectOptionType');
158bd3ca
TD
34 }
35
36 /**
0ad90fc3 37 * @see \wcf\system\option\ISearchableUserOption::getSearchFormElement()
158bd3ca
TD
38 */
39 public function getSearchFormElement(Option $option, $value) {
567b90a3
MS
40 $options = $this->parseEnableOptions($option);
41
42 WCF::getTPL()->assign(array(
43 'disableOptions' => $options['disableOptions'],
44 'enableOptions' => $options['enableOptions'],
45 'option' => $option,
46 'searchOption' => isset($_POST['searchOptions'][$option->optionName]),
47 'selectOptions' => $option->parseSelectOptions(),
48 'value' => $value
49 ));
50 return WCF::getTPL()->fetch('selectSearchableOptionType');
158bd3ca
TD
51 }
52
53 /**
6286572b
AE
54 * Prepares JSON-encoded values for disabling or enabling dependent options.
55 *
0ad90fc3 56 * @param \wcf\data\option\Option $option
158bd3ca
TD
57 * @return array
58 */
59 protected function parseEnableOptions(Option $option) {
60 $disableOptions = $enableOptions = '';
61
62 if (!empty($option->enableOptions)) {
63 $options = $option->parseMultipleEnableOptions();
64
65 foreach ($options as $key => $optionData) {
8e2c12f5 66 $tmp = explode(',', $optionData);
158bd3ca 67
92c8bcf2 68 foreach ($tmp as $item) {
158bd3ca
TD
69 if ($item{0} == '!') {
70 if (!empty($disableOptions)) $disableOptions .= ',';
838e315b 71 $disableOptions .= "{ value: '".$key."', option: '".mb_substr($item, 1)."' }";
158bd3ca
TD
72 }
73 else {
74 if (!empty($enableOptions)) $enableOptions .= ',';
75 $enableOptions .= "{ value: '".$key."', option: '".$item."' }";
76 }
77 }
78 }
79 }
80
81 return array(
82 'disableOptions' => $disableOptions,
83 'enableOptions' => $enableOptions
84 );
85 }
dcb3a44c 86}