protected function getFieldElement() {
$options = $this->getOptions();
- $fieldElement = '<select name="'.$this->fieldName.'[]" id="'.$this->fieldName.'" multiple="multiple" size="'.(count($options) > 10 ? 10 : count($options)).'">';
- foreach ($options as $value => $label) {
- $fieldElement .= '<option value="'.$value.'"'.(in_array($value, $this->fieldValue) ? ' selected="selected"' : '').'>'.WCF::getLanguage()->get($label).'</option>';
+ $fieldElement = '<select name="'.$this->fieldName.'[]" id="'.$this->fieldName.'" multiple="multiple" size="'.(count($options, COUNT_RECURSIVE) > 10 ? 10 : count($options)).'">';
+ foreach ($options as $key => $value) {
+ if (is_array($value)) {
+ $fieldElement .= $this->getOptGroupCode($key, $value);
+ }
+ else {
+ $fieldElement .= $this->getOptionCode($key, $value);
+ }
}
$fieldElement .= "</select>";
return $fieldElement;
}
+ /**
+ * @see \wcf\system\condition\AbstractSelectCondition::getOptionCode()
+ */
+ protected function getOptionCode($value, $label) {
+ return '<option value="'.$value.'"'.(in_array($value, $this->fieldValue) ? ' selected="selected"' : '').'>'.WCF::getLanguage()->get($label).'</option>';
+ }
+
/**
* @see \wcf\system\condition\ICondition::readFormParameters()
*/
$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');
$options = $this->getOptions();
$fieldElement = '<select name="'.$this->fieldName.'">';
- foreach ($options as $value => $label) {
- $fieldElement .= '<option value="'.$value.'"'.($this->fieldValue == $value ? ' selected="selected"' : '').'>'.WCF::getLanguage()->get($label).'</option>';
+ foreach ($options as $key => $value) {
+ if (is_array($value)) {
+ $fieldElement .= $this->getOptGroupCode($key, $value);
+ }
+ else {
+ $fieldElement .= $this->getOptionCode($key, $value);
+ }
}
$fieldElement .= "</select>";
return $fieldElement;
}
+ /**
+ * Returns the html code for an opt group.
+ *
+ * @param string $label
+ * @param array<string> $options
+ * @return string
+ */
+ protected function getOptGroupCode($label, array $options) {
+ $html = '<optgroup label="'.$label.'">';
+ foreach ($options as $key => $value) {
+ $html .= $this->getOptionCode($key, $value);
+ }
+ $html .= '</optgroup>';
+
+ return $html;
+ }
+
+ /**
+ * Returns the html code for an option.
+ *
+ * @param string $value
+ * @param string $label
+ * @return string
+ */
+ protected function getOptionCode($value, $label) {
+ return '<option value="'.$value.'"'.($this->fieldValue == $value ? ' selected="selected"' : '').'>'.WCF::getLanguage()->get($label).'</option>';
+ }
+
/**
* Returns the selectable options.
*/
$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');
protected $label = 'wcf.page.requestedPage';
/**
- * @see \wcf\system\condition\AbstractSingleFieldCondition::getFieldElement()
+ * @see \wcf\system\condition\AbstractSelectCondition::getOptionCode()
*/
- protected function getFieldElement() {
- $options = $this->getOptions();
-
- $fieldElement = '<select name="'.$this->fieldName.'[]" id="'.$this->fieldName.'" multiple="multiple" size="'.(count($options) > 10 ? 10 : count($options)).'">';
- foreach ($options as $value => $label) {
- $fieldElement .= '<option value="'.$value.'" data-object-type="'.ObjectTypeCache::getInstance()->getObjectType($value)->objectType.'"'.(in_array($value, $this->fieldValue) ? ' selected="selected"' : '').'>'.WCF::getLanguage()->get($label).'</option>';
- }
- $fieldElement .= "</select>";
-
- return $fieldElement;
+ protected function getOptionCode($value, $label) {
+ return '<option value="'.$value.'" data-object-type="'.ObjectTypeCache::getInstance()->getObjectType($value)->objectType.'"'.(in_array($value, $this->fieldValue) ? ' selected="selected"' : '').'>'.WCF::getLanguage()->get($label).'</option>';
}
/**