Fixed bug #16234: ExtDirect Dataprovider for user settings
authorSteffen Kamper <info@sk-typo3.de>
Wed, 1 Dec 2010 20:08:21 +0000 (20:08 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Wed, 1 Dec 2010 20:08:21 +0000 (20:08 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9736 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/config_default.php
t3lib/extjs/dataprovider/class.extdirect_dataprovider_beusersettings.php [new file with mode: 0644]
typo3/backend.php

index b22b395..650cc85 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,7 +12,8 @@
 
 2010-12-01  Steffen Kamper  <steffen@typo3.org>
 
-       * Follow-up to  bug #16624: Decrease opacity of black ExtJS mask - make mask message readable
+       * Fixed bug #16234: ExtDirect Dataprovider for user settings
+       * Follow-up to bug #16624: Decrease opacity of black ExtJS mask - make mask message readable
        * Fixed bug #16626: Improve ExtJS grid styling (Thanks to Timo Koenig and Lars Zimmermann)
        * Fixed bug #16622: PageTree - Milestone 2 Release (Thanks to Stefan Galinski and Peter Foerger)
        * Fixed bug #16621: Stabilize the Context Menu API (Thanks to Stefan Galinski)
index 2c249a0..299b38b 100644 (file)
@@ -382,7 +382,8 @@ $TYPO3_CONF_VARS = array(
                ),
                'ExtDirect' => array(   // array of key value pairs (provider -> location:className) that holds the classes for the ExtDirect functionality
                        'TYPO3.CSH.ExtDirect' => 't3lib/extjs/dataprovider/class.extdirect_dataprovider_contexthelp.php:extDirect_DataProvider_ContextHelp',
-                       'TYPO3.LiveSearchActions.ExtDirect' => 't3lib/extjs/dataprovider/class.extdirect_dataprovider_backendlivesearch.php:extDirect_DataProvider_BackendLiveSearch'
+                       'TYPO3.LiveSearchActions.ExtDirect' => 't3lib/extjs/dataprovider/class.extdirect_dataprovider_backendlivesearch.php:extDirect_DataProvider_BackendLiveSearch',
+                       'TYPO3.BackendUserSettings.ExtDirect' => 't3lib/extjs/dataprovider/class.extdirect_dataprovider_beusersettings.php:extDirect_DataProvider_BackendUserSettings'
                ),
        ),
        'EXTCONF' => array(             // Here you may add manually set configuration options for your extensions. Eg. $TYPO3_CONF_VARS['EXTCONF']['my_extension_key']['my_option'] = 'my_value';
diff --git a/t3lib/extjs/dataprovider/class.extdirect_dataprovider_beusersettings.php b/t3lib/extjs/dataprovider/class.extdirect_dataprovider_beusersettings.php
new file mode 100644 (file)
index 0000000..02f4bfe
--- /dev/null
@@ -0,0 +1,183 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010 Steffen Kamper <steffen@typo3.org>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * ExtDirect DataProvider for BE User Settings
+ */
+class extDirect_DataProvider_BackendUserSettings {
+
+       /**
+        * Get user settings
+        *
+        * Returns all user settings, if $key is not specified, otherwise it retuns the value for $key
+        *
+        * @param  string $key  identifier, allows also dotted notation for subarrays
+        * @return mixed value associated
+        */
+       public function get($key = '') {
+               if (strpos($key, '.') !== FALSE) {
+                       $return = $this->getFromDottedNotation($key);
+               } else {
+                       $return = ($key === '' ? $GLOBALS['BE_USER']->uc : $GLOBALS['BE_USER']->uc[$key]);
+               }
+               return $return;
+       }
+
+       /**
+        * Sets user settings by key/value pair
+        *
+        * @param  string $key
+        * @param  mixed $value
+        * @return void
+        */
+       public function set($key, $value) {
+               if (strpos($key, '.') !== FALSE) {
+                       $this->setFromDottedNotation($key, $value);
+               } else {
+                       $GLOBALS['BE_USER']->uc[$key] = $value;
+               }
+               $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
+       }
+
+       /**
+        * Sets user settings by array and merges them with current settings
+        *
+        * @param  array $array
+        * @return void
+        */
+       public function setFromArray(array $array) {
+               $GLOBALS['BE_USER']->uc = array_merge($GLOBALS['BE_USER']->uc, $array);
+               $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
+       }
+
+       /**
+        * Resets the user settings to the default
+        *
+        * @return void
+        */
+       public function reset() {
+               $GLOBALS['BE_USER']->resetUC();
+       }
+
+       /**
+        * Unsets a key in user settings
+        *
+        * @param  string $key
+        * @return void
+        */
+       public function unsetKey($key) {
+               if (isset($GLOBALS['BE_USER']->uc[$key])) {
+                       unset($GLOBALS['BE_USER']->uc[$key]);
+                       $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
+               }
+       }
+
+       /**
+        * Adds an value to an Comma-separated list
+        * stored $key  of user settings
+        *
+        * @param string $key
+        * @param mixed $value
+        * @return void
+        */
+       public function addToList($key, $value) {
+               $list = $this->get($key);
+               if (!isset($list)) {
+                       $list = $value;
+               } else {
+                       if (!t3lib_div::inList($list, $value)) {
+                               $list .= ',' . $value;
+                       }
+               }
+               $this->set($key, $list);
+       }
+
+       /**
+        * Removes an value from an Comma-separated list
+        * stored $key of user settings
+        *
+        * @param string $key
+        * @param mixed $value
+        * @return void
+        */
+       public function removeFromList($key, $value) {
+               $list = $this->get($key);
+               if (t3lib_div::inList($list, $value)) {
+                       $list = t3lib_div::trimExplode(',', $list, TRUE);
+                       $list = t3lib_div::removeArrayEntryByValue($list, $value);
+                       $this->set($key, $list);
+               }
+       }
+
+       /**
+        * Computes the subarray from dotted notation
+        *
+        * @param  $key dotted notation of subkeys like moduleData.module1.general.checked
+        * @return mixed $array value of the settings
+        */
+       protected function getFromDottedNotation($key) {
+               $subkeys = t3lib_div::trimExplode('.', $key);
+               $array =& $GLOBALS['BE_USER']->uc;
+               foreach ($subkeys as $subkey) {
+                       $array =& $array[$subkey];
+               }
+               return $array;
+       }
+
+       /**
+        * Sets the value of a key written in dotted notation
+        *
+        * @param  string $key
+        * @param  mixed $value
+        * @return void
+        */
+       protected function setFromDottedNotation($key, $value) {
+               $subkeys = t3lib_div::trimExplode('.', $key, TRUE);
+               $lastKey = $subkeys[count($subkeys) - 1];
+               $array =& $GLOBALS['BE_USER']->uc;
+               foreach ($subkeys as $subkey) {
+                       if ($subkey === $lastKey) {
+                               $array[$subkey] = $value;
+                       } else {
+                               $array =& $array[$subkey];
+                       }
+               }
+       }
+
+       /**
+        * Gets the last part of of an Dotted Notation
+        *
+        * @param string $key
+        * @return void
+        */
+       protected function getLastKeyFromDottedNotation($key) {
+               $subkeys = t3lib_div::trimExplode('.', $key, TRUE);
+               return $subkeys[count($subkeys) - 1];
+       }
+}
+
+?>
\ No newline at end of file
index 0c73ff1..aa70b97 100644 (file)
@@ -141,6 +141,7 @@ class TYPO3backend {
                        'viewport'              => 'js/extjs/viewport.js',
                        'iframepanel'           => 'js/extjs/iframepanel.js',
                        'viewportConfiguration' => 'js/extjs/viewportConfiguration.js',
+                       'backendUserSettings'        => 'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.BackendUserSettings',
                );
 
                if ($this->debug) {