Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / option / MultiSelectOptionType.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\ArrayUtil;
8
9 /**
10 * Option type implementation for multiple select lists.
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 MultiSelectOptionType extends SelectOptionType {
20 /**
21 * @see \wcf\system\option\IOptionType::getFormElement()
22 */
23 public function getFormElement(Option $option, $value) {
24 WCF::getTPL()->assign(array(
25 'option' => $option,
26 'selectOptions' => $option->parseSelectOptions(),
27 'value' => (!is_array($value) ? explode("\n", $value) : $value)
28 ));
29 return WCF::getTPL()->fetch('multiSelectOptionType');
30 }
31
32 /**
33 * @see \wcf\system\option\IOptionType::validate()
34 */
35 public function validate(Option $option, $newValue) {
36 if (!is_array($newValue)) $newValue = array();
37 $options = $option->parseSelectOptions();
38 foreach ($newValue as $value) {
39 if (!isset($options[$value])) {
40 throw new UserInputException($option->optionName, 'validationFailed');
41 }
42 }
43 }
44
45 /**
46 * @see \wcf\system\option\IOptionType::getData()
47 */
48 public function getData(Option $option, $newValue) {
49 if (!is_array($newValue)) $newValue = array();
50 return implode("\n", $newValue);
51 }
52
53 /**
54 * @see \wcf\system\option\ISearchableUserOption::getCondition()
55 */
56 public function getCondition(PreparedStatementConditionBuilder &$conditions, Option $option, $value) {
57 if (!is_array($value) || empty($value)) return false;
58 $value = ArrayUtil::trim($value);
59 if (empty($value)) return false;
60
61 $conditions->add("option_value.userOption".$option->optionID." REGEXP '".'(^|\n)'.implode('\n([^\n]*\n)*', array_map('escapeString', $value)).'($|\n)'."'");
62 return true;
63 }
64 }