Fixing group add form
authorAlexander Ebert <ebert@woltlab.com>
Mon, 23 Jan 2012 20:04:02 +0000 (21:04 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 23 Jan 2012 20:04:02 +0000 (21:04 +0100)
wcfsetup/install/files/lib/acp/form/UserGroupAddForm.class.php
wcfsetup/install/files/lib/system/cache/builder/OptionCacheBuilder.class.php
wcfsetup/install/files/lib/system/option/OptionHandler.class.php
wcfsetup/install/files/lib/system/option/user/group/UserGroupOptionHandler.class.php [new file with mode: 0644]

index 94da5422c1f44bb416edea43338c259be9d0318f..596d8a660716af8cbc4f5e1544bcd7d43c0c89f3 100755 (executable)
@@ -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();
        }
index 33652b4844997c13d594ff4a371838b2666ef6f6..52ebce81cb16b1cc3200be115aa3a8e265872e56 100644 (file)
@@ -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);
index 7d78e7d6044356f367ab274ea29dc493fa6017d4..a4d5e85685c80bea82e1d8a6003890d2d5a65119 100644 (file)
@@ -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 (file)
index 0000000..79b8904
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+namespace wcf\system\option\user\group;
+use wcf\system\exception\SystemException;
+use wcf\system\option\OptionHandler;
+use wcf\util\ClassUtil;
+
+/**
+ * Handles user group options.
+ *
+ * @author     Alexander Ebert
+ * @copyright  2001-2012 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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