TYPO3 CMS  TYPO3_6-2
BackendUserSettingsDataProvider.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
34  public function get($key = '') {
35  if (strpos($key, '.') !== FALSE) {
36  $return = $this->getFromDottedNotation($key);
37  } else {
38  $return = $key === '' ? $GLOBALS['BE_USER']->uc : $GLOBALS['BE_USER']->uc[$key];
39  }
40  return $return;
41  }
42 
50  public function set($key, $value) {
51  if (strpos($key, '.') !== FALSE) {
52  $this->setFromDottedNotation($key, $value);
53  } else {
54  $GLOBALS['BE_USER']->uc[$key] = $value;
55  }
56  $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
57  }
58 
65  public function setFromArray(array $array) {
66  $GLOBALS['BE_USER']->uc = array_merge($GLOBALS['BE_USER']->uc, $array);
67  $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
68  }
69 
75  public function reset() {
76  $GLOBALS['BE_USER']->resetUC();
77  }
78 
85  public function unsetKey($key) {
86  if (isset($GLOBALS['BE_USER']->uc[$key])) {
87  unset($GLOBALS['BE_USER']->uc[$key]);
88  $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
89  }
90  }
91 
100  public function addToList($key, $value) {
101  $list = $this->get($key);
102  if (!isset($list)) {
103  $list = $value;
104  } else {
105  if (!GeneralUtility::inList($list, $value)) {
106  $list .= ',' . $value;
107  }
108  }
109  $this->set($key, $list);
110  }
111 
120  public function removeFromList($key, $value) {
121  $list = $this->get($key);
122  if (GeneralUtility::inList($list, $value)) {
123  $list = GeneralUtility::trimExplode(',', $list, TRUE);
124  $list = GeneralUtility::removeArrayEntryByValue($list, $value);
125  $this->set($key, implode(',', $list));
126  }
127  }
128 
135  protected function getFromDottedNotation($key) {
136  $subkeys = GeneralUtility::trimExplode('.', $key);
137  $array = &$GLOBALS['BE_USER']->uc;
138  foreach ($subkeys as $subkey) {
139  $array = &$array[$subkey];
140  }
141  return $array;
142  }
143 
151  protected function setFromDottedNotation($key, $value) {
152  $subkeys = GeneralUtility::trimExplode('.', $key, TRUE);
153  $lastKey = $subkeys[count($subkeys) - 1];
154  $array = &$GLOBALS['BE_USER']->uc;
155  foreach ($subkeys as $subkey) {
156  if ($subkey === $lastKey) {
157  $array[$subkey] = $value;
158  } else {
159  $array = &$array[$subkey];
160  }
161  }
162  }
163 
170  protected function getLastKeyFromDottedNotation($key) {
171  $subkeys = GeneralUtility::trimExplode('.', $key, TRUE);
172  return $subkeys[count($subkeys) - 1];
173  }
174 
175 }
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static removeArrayEntryByValue(array $array, $cmpValue)