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\ArrayUtil
;
10 * Option type implementation for multiple select lists.
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 MultiSelectOptionType
extends SelectOptionType
{
21 * @see \wcf\system\option\IOptionType::getFormElement()
23 public function getFormElement(Option
$option, $value) {
24 WCF
::getTPL()->assign(array(
26 'selectOptions' => $option->parseSelectOptions(),
27 'value' => (!is_array($value) ?
explode("\n", $value) : $value)
29 return WCF
::getTPL()->fetch('multiSelectOptionType');
33 * @see \wcf\system\option\IOptionType::validate()
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');
46 * @see \wcf\system\option\IOptionType::getData()
48 public function getData(Option
$option, $newValue) {
49 if (!is_array($newValue)) $newValue = array();
50 return implode("\n", $newValue);
54 * @see \wcf\system\option\ISearchableUserOption::getCondition()
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;
61 $conditions->add("option_value.userOption".$option->optionID
." REGEXP '".'(^|\n)'.implode('\n([^\n]*\n)*', array_map('escapeString', $value)).'($|\n)'."'");