From: Marcel Werk Date: Wed, 24 Jul 2013 19:37:30 +0000 (+0200) Subject: Moved code from blog into wcf X-Git-Tag: 2.0.0_Beta_5~14 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=200568c045ec1cf9cb3768c2c03969e8befcce76;p=GitHub%2FWoltLab%2FWCF.git Moved code from blog into wcf --- diff --git a/wcfsetup/install/files/acp/templates/categoryMultiSelectOptionType.tpl b/wcfsetup/install/files/acp/templates/categoryMultiSelectOptionType.tpl new file mode 100644 index 0000000000..491351007d --- /dev/null +++ b/wcfsetup/install/files/acp/templates/categoryMultiSelectOptionType.tpl @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/wcfsetup/install/files/lib/system/option/AbstractCategoryMultiSelectOptionType.class.php b/wcfsetup/install/files/lib/system/option/AbstractCategoryMultiSelectOptionType.class.php new file mode 100644 index 0000000000..b76b62c22d --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/AbstractCategoryMultiSelectOptionType.class.php @@ -0,0 +1,70 @@ + + * @package com.woltlab.wcf + * @subpackage system.option + * @category Community Framework + */ +class AbstractCategoryMultiSelectOptionType extends AbstractOptionType { + /** + * object type name + * @var string + */ + public $objectType = ''; + + /** + * node tree class + * @var string + */ + public $nodeTreeClassname = 'wcf\data\category\CategoryNodeTree'; + + /** + * @see wcf\system\option\IOptionType::getFormElement() + */ + public function getFormElement(Option $option, $value) { + $categoryTree = new $this->nodeTreeClassname($this->objectType); + $categoryList = $categoryTree->getIterator(); + $categoryList->setMaxDepth(0); + + WCF::getTPL()->assign(array( + 'categoryList' => $categoryList, + 'option' => $option, + 'value' => (!is_array($value) ? explode("\n", $value) : $value) + )); + return WCF::getTPL()->fetch('categoryMultiSelectOptionType'); + } + + /** + * @see wcf\system\option\IOptionType::validate() + */ + public function validate(Option $option, $newValue) { + if (!is_array($newValue)) $newValue = array(); + $newValue = ArrayUtil::toIntegerArray($newValue); + + foreach ($newValue as $categoryID) { + $category = CategoryHandler::getInstance()->getCategory($categoryID); + if ($category === null) throw new UserInputException($option->optionName, 'validationFailed'); + if ($category->getObjectType()->objectType != $this->objectType) throw new UserInputException($option->optionName, 'validationFailed'); + } + } + + /** + * @see wcf\system\option\IOptionType::getData() + */ + public function getData(Option $option, $newValue) { + if (!is_array($newValue)) $newValue = array(); + return implode("\n", ArrayUtil::toIntegerArray($newValue)); + } +}