From 5d21092489fcc0d592d1b02c6524a00eef7727a3 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 23 Jan 2012 21:04:02 +0100 Subject: [PATCH] Fixing group add form --- .../lib/acp/form/UserGroupAddForm.class.php | 17 ++++++--- .../builder/OptionCacheBuilder.class.php | 26 ++++++++----- .../lib/system/option/OptionHandler.class.php | 31 +++++++++++---- .../group/UserGroupOptionHandler.class.php | 38 +++++++++++++++++++ 4 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/option/user/group/UserGroupOptionHandler.class.php diff --git a/wcfsetup/install/files/lib/acp/form/UserGroupAddForm.class.php b/wcfsetup/install/files/lib/acp/form/UserGroupAddForm.class.php index 94da5422c1..596d8a6607 100755 --- a/wcfsetup/install/files/lib/acp/form/UserGroupAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserGroupAddForm.class.php @@ -42,7 +42,7 @@ class UserGroupAddForm extends AbstractOptionListForm { /** * @see wcf\acp\form\AbstractOptionListForm::$cacheName */ - public $cacheName = 'user_group-option-'; + public $cacheName = 'userGroup-option'; /** * active tab menu item name @@ -62,6 +62,11 @@ class UserGroupAddForm extends AbstractOptionListForm { */ public $optionTree = array(); + /** + * @see wcf\acp\form\AbstractOptionListForm::$optionHandlerClassName + */ + public $optionHandlerClassName = 'wcf\system\option\user\group\UserGroupOptionHandler'; + /** * group name * @var string @@ -74,6 +79,9 @@ class UserGroupAddForm extends AbstractOptionListForm { */ public $additionalFields = array(); + /** + * @see wcf\page\IPage::readParameters() + */ public function readParameters() { parent::readParameters(); @@ -165,9 +173,9 @@ class UserGroupAddForm extends AbstractOptionListForm { * @see wcf\page\IPage::readData() */ public function readData() { - AbstractOptionListForm::readData(); + parent::readData(); - $this->optionTree = $this->getOptionTree(); + $this->optionTree = $this->optionHandler->getOptionTree(); if (!count($_POST)) { $this->activeTabMenuItem = $this->optionTree[0]['object']->categoryName; } @@ -200,9 +208,6 @@ class UserGroupAddForm extends AbstractOptionListForm { // check master password WCFACP::checkMasterPassword(); - // get user options and categories from cache - $this->readCache(); - // show form parent::show(); } diff --git a/wcfsetup/install/files/lib/system/cache/builder/OptionCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/OptionCacheBuilder.class.php index 33652b4844..52ebce81cb 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/OptionCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/OptionCacheBuilder.class.php @@ -21,9 +21,18 @@ class OptionCacheBuilder implements ICacheBuilder { */ public function getData(array $cacheResource) { $information = explode('-', $cacheResource['cache']); + $tableName = ''; + if (count($information) == 3) { - $type = $information[0].'_'; + $type = $information[0]; $packageID = $information[2]; + + preg_match_all('~((?:^|[A-Z])[a-z]+)~', $information[0], $matches); + if (isset($matches[1])) { + for ($i = 0, $length = count($matches[1]); $i < $length; $i++) { + $tableName .= strtolower($matches[1][$i]) . '_'; + } + } } else { $type = ''; @@ -36,11 +45,11 @@ class OptionCacheBuilder implements ICacheBuilder { 'categoryStructure' => array(), 'optionToCategories' => array() ); - + // option categories // get all option categories and sort categories by priority $sql = "SELECT categoryName, categoryID - FROM wcf".WCF_N."_".$type."option_category option_category + FROM wcf".WCF_N."_".$tableName."option_category option_category LEFT JOIN wcf".WCF_N."_package_dependency package_dependency ON (package_dependency.dependency = option_category.packageID) WHERE package_dependency.packageID = ? @@ -58,7 +67,7 @@ class OptionCacheBuilder implements ICacheBuilder { $conditions->add("categoryID IN (?)", array($optionCategories)); $sql = "SELECT option_category.*, package.packageDir - FROM wcf".WCF_N."_".$type."option_category option_category + FROM wcf".WCF_N."_".$tableName."option_category option_category LEFT JOIN wcf".WCF_N."_package package ON (package.packageID = option_category.packageID) ".$conditions." @@ -79,7 +88,7 @@ class OptionCacheBuilder implements ICacheBuilder { // get all options and sort options by priority $optionIDs = array(); $sql = "SELECT optionName, optionID - FROM wcf".WCF_N."_".$type."option option_table + FROM wcf".WCF_N."_".$tableName."option option_table LEFT JOIN wcf".WCF_N."_package_dependency package_dependency ON (package_dependency.dependency = option_table.packageID) WHERE package_dependency.packageID = ? @@ -95,14 +104,13 @@ class OptionCacheBuilder implements ICacheBuilder { $className = 'wcf\data\option\Option'; if (!empty($type)) { // strip trailing underscore - $rawType = substr($type, 0, -1); - preg_match_all('~((?:^|[A-Z])[a-z]+)~', $rawType, $matches); + preg_match_all('~((?:^|[A-Z])[a-z]+)~', $type, $matches); if (isset($matches[1])) { $className = 'wcf\data\\'; for ($i = 0, $length = count($matches[1]); $i < $length; $i++) { $className .= $matches[1][$i] . '\\'; } - $className .= 'option\\' . ucfirst($rawType) . 'Option'; + $className .= 'option\\' . ucfirst($type) . 'Option'; } } @@ -111,7 +119,7 @@ class OptionCacheBuilder implements ICacheBuilder { $conditions->add("optionID IN (?)", array($optionIDs)); $sql = "SELECT * - FROM wcf".WCF_N."_".$type."option + FROM wcf".WCF_N."_".$tableName."option ".$conditions." ORDER BY showOrder ASC"; $statement = WCF::getDB()->prepareStatement($sql); diff --git a/wcfsetup/install/files/lib/system/option/OptionHandler.class.php b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php index 7d78e7d604..a4d5e85685 100644 --- a/wcfsetup/install/files/lib/system/option/OptionHandler.class.php +++ b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php @@ -325,14 +325,9 @@ class OptionHandler implements IOptionHandler { */ protected function getTypeObject($type) { if (!isset($this->typeObjects[$type])) { - $className = 'wcf\system\option\\'.ucfirst($type).'OptionType'; - - // validate class - if (!class_exists($className)) { - throw new SystemException("unable to find class '".$className."'"); - } - if (!ClassUtil::isInstanceOf($className, 'wcf\system\option\IOptionType')) { - throw new SystemException("'".$className."' should implement wcf\system\option\IOptionType"); + $className = $this->getClassName($type); + if ($className === null) { + throw new SystemException("unable to find class for option type '".$type."'"); } // create instance @@ -342,6 +337,26 @@ class OptionHandler implements IOptionHandler { return $this->typeObjects[$type]; } + /** + * Returns class name for option type. + * + * @param string $type + * @return string + */ + protected function getClassName($type) { + $className = 'wcf\system\option\\'.ucfirst($type).'OptionType'; + + // validate class + if (!class_exists($className)) { + return null; + } + if (!ClassUtil::isInstanceOf($className, 'wcf\system\option\IOptionType')) { + throw new SystemException("'".$className."' should implement wcf\system\option\IOptionType"); + } + + return $className; + } + /** * Gets all options and option categories from cache. * diff --git a/wcfsetup/install/files/lib/system/option/user/group/UserGroupOptionHandler.class.php b/wcfsetup/install/files/lib/system/option/user/group/UserGroupOptionHandler.class.php new file mode 100644 index 0000000000..79b8904ca4 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/user/group/UserGroupOptionHandler.class.php @@ -0,0 +1,38 @@ + + * @package com.woltlab.wcf + * @subpackage system.option.user.group + * @category Community Framework + */ +class UserGroupOptionHandler extends OptionHandler { + /** + * @see wcf\system\option\OptionHandler::getClassName() + */ + protected function getClassName($type) { + $className = parent::getClassName($type); + + if ($className === null) { + $className = 'wcf\system\option\user\group\\'.ucfirst($type).'UserGroupOptionType'; + + // validate class + if (!class_exists($className)) { + return null; + } + if (!ClassUtil::isInstanceOf($className, 'wcf\system\option\IOptionType')) { + throw new SystemException("'".$className."' should implement wcf\system\option\IOptionType"); + } + } + + return $className; + } +} \ No newline at end of file -- 2.20.1