From b5fe4972f921a1c507e87ec119d755c8b22ed052 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 13 Feb 2012 14:43:26 +0100 Subject: [PATCH] Added support for DatabaseObjectList for options Closes #255 --- ...tmlOptionsFunctionTemplatePlugin.class.php | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/wcfsetup/install/files/lib/system/template/plugin/HtmlOptionsFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/HtmlOptionsFunctionTemplatePlugin.class.php index 3bf178b03c..73db745e8b 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/HtmlOptionsFunctionTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/HtmlOptionsFunctionTemplatePlugin.class.php @@ -1,5 +1,6 @@ * @package com.woltlab.wcf * @subpackage system.template.plugin @@ -28,7 +31,10 @@ class HtmlOptionsFunctionTemplatePlugin extends HtmlCheckboxesFunctionTemplatePl * @see wcf\system\template\IFunctionTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { - if (isset($tagArgs['output']) && is_array($tagArgs['output'])) { + if (isset($tagArgs['object']) && ($tagArgs['object'] instanceof DatabaseObjectList)) { + $tagArgs['options'] = $tagArgs['object']; + } + else if (isset($tagArgs['output']) && is_array($tagArgs['output'])) { if (count($tagArgs['output'])) { if (isset($tagArgs['values']) && is_array($tagArgs['values'])) { if (count($tagArgs['output']) == count($tagArgs['values'])) { @@ -47,8 +53,8 @@ class HtmlOptionsFunctionTemplatePlugin extends HtmlCheckboxesFunctionTemplatePl } } - if (!isset($tagArgs['options']) || !is_array($tagArgs['options'])) { - throw new SystemException("missing 'options' argument in htmlOptions tag"); + if (!isset($tagArgs['options']) || (!is_array($tagArgs['options']) && !($tagArgs['options'] instanceof DatabaseObjectList))) { + throw new SystemException("missing 'options' or 'object' argument in htmlOptions tag"); } if (isset($tagArgs['disableEncoding']) && $tagArgs['disableEncoding']) { @@ -71,7 +77,7 @@ class HtmlOptionsFunctionTemplatePlugin extends HtmlCheckboxesFunctionTemplatePl // create also a 'select' tag if (isset($tagArgs['name'])) { // unset all system vars - unset($tagArgs['options'], $tagArgs['selected'], $tagArgs['output'], $tagArgs['values'], $tagArgs['disableEncoding']); + unset($tagArgs['object'], $tagArgs['options'], $tagArgs['selected'], $tagArgs['output'], $tagArgs['values'], $tagArgs['disableEncoding']); // generate 'select' parameters $params = ''; @@ -98,14 +104,21 @@ class HtmlOptionsFunctionTemplatePlugin extends HtmlCheckboxesFunctionTemplatePl $html = ''."\n"; } - foreach ($values as $childKey => $value) { - if (is_array($value)) { - $html .= $this->makeOptionGroup($childKey, $value); - } - else { + if ($values instanceof DatabaseObjectList) { + foreach ($values as $childKey => $value) { $html .= $this->makeOption($childKey, $value); } } + else { + foreach ($values as $childKey => $value) { + if (is_array($value)) { + $html .= $this->makeOptionGroup($childKey, $value); + } + else { + $html .= $this->makeOption($childKey, $value); + } + } + } if ($key !== null) { $html .= "\n"; -- 2.20.1