Added support for user options
authorAlexander Ebert <ebert@woltlab.com>
Tue, 8 Nov 2011 14:15:10 +0000 (15:15 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 8 Nov 2011 14:15:10 +0000 (15:15 +0100)
wcfsetup/install/files/lib/data/user/option/UserOption.class.php
wcfsetup/install/files/lib/util/OptionUtil.class.php [new file with mode: 0644]

index 06f97db1c73045863863291ebf1f22931dc29219..4802f4a36ac2563974696ef08c0f4f1d39605eff 100644 (file)
@@ -22,4 +22,16 @@ class UserOption extends Option {
         * @see wcf\data\DatabaseObject::$databaseTableIndexName
         */
        protected static $databaseTableIndexName = 'optionID';
+       
+       /**
+        * option value
+        * @var string
+        */
+       public $optionValue = '';
+       
+       /**
+        * output data
+        * @var array
+        */
+       public $outputData = array();
 }
diff --git a/wcfsetup/install/files/lib/util/OptionUtil.class.php b/wcfsetup/install/files/lib/util/OptionUtil.class.php
new file mode 100644 (file)
index 0000000..0c31255
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+namespace wcf\util;
+
+/**
+ * Contains option-related functions.
+ *
+ * @author     Marcel Werk
+ * @copyright  2001-2011 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage util
+ * @category   Community Framework
+ */
+class OptionUtil {
+       /**
+        * Returns a list of the available options.
+        * 
+        * @param       string          $selectOptions
+        * @return      array
+        */
+       public static function parseSelectOptions($selectOptions) {
+               $result = array();
+               $options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($selectOptions)));
+               foreach ($options as $option) {
+                       $key = $value = $option;
+                       if (StringUtil::indexOf($option, ':') !== false) {
+                               $optionData = explode(':', $option);
+                               $key = array_shift($optionData);
+                               $value = implode(':', $optionData);
+                       }
+                       
+                       $result[$key] = $value;
+               }
+               
+               return $result;
+       }
+       
+       /**
+        * Returns a list of the enable options.
+        * 
+        * @param       string          $enableOptions
+        * @return      array
+        */
+       public static function parseMultipleEnableOptions($enableOptions) {
+               $result = array();
+               if (!empty($enableOptions)) {
+                       $options = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($enableOptions)));
+                       $key = -1;
+                       foreach ($options as $option) {
+                               if (StringUtil::indexOf($option, ':') !== false) {
+                                       $optionData = explode(':', $option);
+                                       $key = array_shift($optionData);
+                                       $value = implode(':', $optionData);
+                               }
+                               else {
+                                       $key++;
+                                       $value = $option;
+                               }
+                               
+                               $result[$key] = $value;
+                       }
+               }
+               
+               return $result;
+       }
+}