|
1
|
|
|
<?php |
|
2
|
|
|
namespace Fab\Vidi\Controller; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* This file is part of the TYPO3 CMS project. |
|
6
|
|
|
* |
|
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
9
|
|
|
* of the License, or any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please read the |
|
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
13
|
|
|
* |
|
14
|
|
|
* The TYPO3 project - inspiring people to share! |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
18
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Controller which handles actions related to Vidi in the Backend. |
|
22
|
|
|
*/ |
|
23
|
|
|
class UserPreferencesController extends ActionController |
|
24
|
|
|
{ |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param string $key |
|
28
|
|
|
* @param string $value |
|
29
|
|
|
* @param string $preferenceSignature |
|
30
|
|
|
* @return string |
|
31
|
|
|
*/ |
|
32
|
|
|
public function saveAction($key, $value, $preferenceSignature) |
|
33
|
|
|
{ |
|
34
|
|
|
|
|
35
|
|
|
$dataType = $this->getModuleLoader()->getDataType(); |
|
36
|
|
|
|
|
37
|
|
|
$key = $dataType . '_' . $this->getBackendUserIdentifier() . '_' . $key; |
|
38
|
|
|
$this->getCacheInstance()->set($key, $value, array(), 0); |
|
39
|
|
|
|
|
40
|
|
|
$key = $dataType . '_' . $this->getBackendUserIdentifier() . '_signature'; |
|
41
|
|
|
$this->getCacheInstance()->set($key, $preferenceSignature, array(), 0); |
|
42
|
|
|
|
|
43
|
|
|
return 'OK'; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return int |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function getBackendUserIdentifier() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->getBackendUser()->user['uid']; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Returns an instance of the current Backend User. |
|
56
|
|
|
* |
|
57
|
|
|
* @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function getBackendUser() |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
return $GLOBALS['BE_USER']; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the Vidi Module Loader. |
|
66
|
|
|
* |
|
67
|
|
|
* @return \Fab\Vidi\Module\ModuleLoader |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function getModuleLoader() |
|
70
|
|
|
{ |
|
71
|
|
|
return GeneralUtility::makeInstance('Fab\Vidi\Module\ModuleLoader'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function getCacheInstance() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->getCacheManager()->getCache('vidi'); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Return the Cache Manager |
|
84
|
|
|
* |
|
85
|
|
|
* @return \TYPO3\CMS\Core\Cache\CacheManager |
|
86
|
|
|
*/ |
|
87
|
|
|
protected function getCacheManager() |
|
88
|
|
|
{ |
|
89
|
|
|
return GeneralUtility::makeInstance('TYPO3\CMS\Core\Cache\CacheManager'); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: