Fixed some option handler issues
authorMarcel Werk <burntime@woltlab.com>
Fri, 21 Dec 2012 23:01:16 +0000 (00:01 +0100)
committerMarcel Werk <burntime@woltlab.com>
Fri, 21 Dec 2012 23:01:16 +0000 (00:01 +0100)
com.woltlab.wcf/template/textareaOptionType.tpl
wcfsetup/install/files/lib/acp/form/UserSearchForm.class.php
wcfsetup/install/files/lib/system/option/OptionHandler.class.php
wcfsetup/install/files/lib/system/option/user/UserOptionHandler.class.php

index 657ee51ebae849c49beb7a74295f7fa6e6e9ca67..310cd47267b2652a529a79b087cc1b3db22974f8 100644 (file)
@@ -1 +1 @@
-<textarea id="{$option->optionName}" name="values[{$option->optionName}]" cols="40" rows="10">{$value}</textarea>
\ No newline at end of file
+<textarea id="{$option->optionName}" name="values[{$option->optionName}]" cols="40" rows="10">{$value}</textarea>
index cb64f5ecc74c2da1e845a45ed6207141dbeac7a6..fa099dfcf2b171df8c62a82ed88c8b70d15183d1 100755 (executable)
@@ -119,12 +119,6 @@ class UserSearchForm extends UserOptionListForm {
         */
        public $maxResults = 0;
        
-       /**
-        * list of option values
-        * @var array
-        */
-       public $values = array();
-       
        /**
         * @see wcf\form\IForm::readFormParameters()
         */
@@ -142,17 +136,23 @@ class UserSearchForm extends UserOptionListForm {
                if (isset($_POST['sortField'])) $this->sortField = $_POST['sortField'];
                if (isset($_POST['sortOrder'])) $this->sortOrder = $_POST['sortOrder'];
                if (isset($_POST['columns']) && is_array($_POST['columns'])) $this->columns = $_POST['columns'];
-               
-               if (isset($_POST['values']) && is_array($_POST['values'])) $this->values = $_POST['values'];
+       }
+       
+       /**
+        * @see wcf\acp\form\AbstractOptionListForm::initOptionHandler()
+        */
+       protected function initOptionHandler() {
+               $this->optionHandler->enableSearchMode();
+               $this->optionHandler->init();
        }
        
        /**
         * @see wcf\page\IPage::readData()
         */
        public function readData() {
-               $this->readOptionTree();
-               
                parent::readData();
+               
+               $this->readOptionTree();
        }
        
        /**
@@ -298,8 +298,8 @@ class UserSearchForm extends UserOptionListForm {
                foreach ($this->optionHandler->getCategoryOptions('profile') as $option) {
                        $option = $option['object'];
                        
-                       $value = isset($this->values[$option->optionName]) ? $this->values[$option->optionName] : null;
-                       $this->optionHandler->getTypeObject($option->optionType)->getCondition($this->conditions, $option->getDecoratedObject(), $value);
+                       $value = isset($this->optionHandler->optionValues[$option->optionName]) ? $this->optionHandler->optionValues[$option->optionName] : null;
+                       $this->optionHandler->getTypeObject($option->optionType)->getCondition($this->conditions, $option, $value);
                }
        }
 }
index 005adbaad5b04ca4d35178cb9b83bfd7fc66e141..72229eaecd5e5105e738c2054b81718af56b2c3a 100644 (file)
@@ -212,7 +212,7 @@ class OptionHandler implements IOptionHandler {
                                // add option to list
                                $option = $this->getOption($optionName);
                                if ($option !== null) {
-                                       $children[] = $this->getOption($optionName);
+                                       $children[] = $option;
                                }
                        }
                }
index 1ee37c7d975fc7e11e701a7f3cdd50646aa22f79..5ef52f0d4c4323fc4d6b1c93bf63740091e650cc 100644 (file)
@@ -30,6 +30,12 @@ class UserOptionHandler extends OptionHandler {
         */
        public $editMode = true;
        
+       /**
+        * true, if within search mode
+        * @var boolean
+        */
+       public $searchMode = false;
+       
        /**
         * true, if empty options should be removed
         * @var boolean
@@ -68,6 +74,16 @@ class UserOptionHandler extends OptionHandler {
                $this->editMode = $enable;
        }
        
+       /**
+        * Enables search mode.
+        *
+        * @param       boolean         $enable
+        */
+       public function enableSearchMode($enable = true) {
+               $this->searchMode = $enable;
+               if ($enable) $this->enableEditMode(false);
+       }
+       
        /**
         * Sets option values for a certain user.
         * 
@@ -97,18 +113,29 @@ class UserOptionHandler extends OptionHandler {
        public function getOption($optionName) {
                $optionData = parent::getOption($optionName);
                
-               $optionData['object'] = new ViewableUserOption($optionData['object']);
-               if ($this->user !== null) {
-                       $optionData['object']->setOptionValue($this->user);
-               }
-               
-               if ($this->removeEmptyOptions && empty($optionData['object']->optionValue)) {
-                       return null;
+               if (!$this->editMode && !$this->searchMode) {
+                       $optionData['object'] = new ViewableUserOption($optionData['object']);
+                       if ($this->user !== null) {
+                               $optionData['object']->setOptionValue($this->user);
+                       }
+                       
+                       if ($this->removeEmptyOptions && empty($optionData['object']->optionValue)) {
+                               return null;
+                       }
                }
                
                return $optionData;
        }
        
+       /**
+        * @see wcf\system\option\IOptionType::getFormElement()
+        */
+       protected function getFormElement($type, Option $option) {
+               if ($this->searchMode) return $this->getTypeObject($type)->getSearchFormElement($option, (isset($this->optionValues[$option->optionName]) ? $this->optionValues[$option->optionName] : null));
+               
+               return parent::getFormElement($type, $option);
+       }
+       
        /**
         * @see wcf\system\option\OptionHandler::validateOption()
         */
@@ -135,11 +162,17 @@ class UserOptionHandler extends OptionHandler {
         * @see wcf\system\option\OptionHandler::checkVisibility()
         */
        protected function checkVisibility(Option $option) {
+               if ($option->disabled) {
+                       return false;
+               }
+               
+               // in registration
                if ($this->inRegistration && !$option->askDuringRegistration && !$option->required) {
                        return false;
                }
                
-               if ($option->disabled) {
+               // search mode
+               if ($this->searchMode && !$option->searchable) {
                        return false;
                }
                
@@ -181,4 +214,15 @@ class UserOptionHandler extends OptionHandler {
                        if (!isset($this->optionValues[$option->optionName])) $this->optionValues[$option->optionName] = $option->defaultValue;
                }
        }
+       
+       /**
+        * @see wcf\system\option\IOptionHandler::readUserInput()
+        */
+       public function readUserInput(array &$source) {
+               parent::readUserInput($source);
+               
+               if ($this->searchMode) {
+                       $this->optionValues = $this->rawValues;
+               }
+       }
 }