Completed
Push — master ( a54493...36663b )
by Fabien
05:49
created

UserPreferencesController::getBackendUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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()
0 ignored issues
show
Coding Style introduced by
getBackendUser uses the super-global variable $GLOBALS which is generally not recommended.

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:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
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