From 6bea96a7fde19f836fc33a511e2a78758190c890 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 4 Jul 2014 22:13:00 +0200 Subject: [PATCH] Add optgroup support for AbstractSelectCondition --- .../AbstractMultiSelectCondition.class.php | 24 +++++++++-- .../AbstractSelectCondition.class.php | 43 ++++++++++++++++++- .../MultiPageControllerCondition.class.php | 14 ++---- 3 files changed, 65 insertions(+), 16 deletions(-) diff --git a/wcfsetup/install/files/lib/system/condition/AbstractMultiSelectCondition.class.php b/wcfsetup/install/files/lib/system/condition/AbstractMultiSelectCondition.class.php index f5752c7c2d..f01a2add7e 100644 --- a/wcfsetup/install/files/lib/system/condition/AbstractMultiSelectCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/AbstractMultiSelectCondition.class.php @@ -39,15 +39,27 @@ abstract class AbstractMultiSelectCondition extends AbstractSelectCondition { protected function getFieldElement() { $options = $this->getOptions(); - $fieldElement = ''; + foreach ($options as $key => $value) { + if (is_array($value)) { + $fieldElement .= $this->getOptGroupCode($key, $value); + } + else { + $fieldElement .= $this->getOptionCode($key, $value); + } } $fieldElement .= ""; return $fieldElement; } + /** + * @see \wcf\system\condition\AbstractSelectCondition::getOptionCode() + */ + protected function getOptionCode($value, $label) { + return ''; + } + /** * @see \wcf\system\condition\ICondition::readFormParameters() */ @@ -69,6 +81,12 @@ abstract class AbstractMultiSelectCondition extends AbstractSelectCondition { $options = $this->getOptions(); foreach ($this->fieldValue as $value) { if (!isset($options[$value])) { + foreach ($options as $optionValue) { + if (is_array($optionValue) && isset($optionValue[$value])) { + return; + } + } + $this->errorMessage = 'wcf.global.form.error.noValidSelection'; throw new UserInputException($this->fieldName, 'noValidSelection'); diff --git a/wcfsetup/install/files/lib/system/condition/AbstractSelectCondition.class.php b/wcfsetup/install/files/lib/system/condition/AbstractSelectCondition.class.php index e236f1b300..320703c04c 100644 --- a/wcfsetup/install/files/lib/system/condition/AbstractSelectCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/AbstractSelectCondition.class.php @@ -53,14 +53,47 @@ abstract class AbstractSelectCondition extends AbstractSingleFieldCondition { $options = $this->getOptions(); $fieldElement = '"; return $fieldElement; } + /** + * Returns the html code for an opt group. + * + * @param string $label + * @param array $options + * @return string + */ + protected function getOptGroupCode($label, array $options) { + $html = ''; + foreach ($options as $key => $value) { + $html .= $this->getOptionCode($key, $value); + } + $html .= ''; + + return $html; + } + + /** + * Returns the html code for an option. + * + * @param string $value + * @param string $label + * @return string + */ + protected function getOptionCode($value, $label) { + return ''; + } + /** * Returns the selectable options. */ @@ -95,6 +128,12 @@ abstract class AbstractSelectCondition extends AbstractSingleFieldCondition { $options = $this->getOptions(); if (!isset($options[$this->fieldValue])) { + foreach ($options as $key => $value) { + if (is_array($value) && isset($value[$this->fieldValue])) { + return; + } + } + $this->errorMessage = 'wcf.global.form.error.noValidSelection'; throw new UserInputException($this->fieldName, 'noValidSelection'); diff --git a/wcfsetup/install/files/lib/system/condition/MultiPageControllerCondition.class.php b/wcfsetup/install/files/lib/system/condition/MultiPageControllerCondition.class.php index cd83919574..40cb07f707 100644 --- a/wcfsetup/install/files/lib/system/condition/MultiPageControllerCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/MultiPageControllerCondition.class.php @@ -33,18 +33,10 @@ class MultiPageControllerCondition extends AbstractMultiSelectCondition implemen protected $label = 'wcf.page.requestedPage'; /** - * @see \wcf\system\condition\AbstractSingleFieldCondition::getFieldElement() + * @see \wcf\system\condition\AbstractSelectCondition::getOptionCode() */ - protected function getFieldElement() { - $options = $this->getOptions(); - - $fieldElement = '"; - - return $fieldElement; + protected function getOptionCode($value, $label) { + return ''; } /** -- 2.20.1