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

SelectionController::editAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
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 Fab\Vidi\Domain\Model\Selection;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
20
21
/**
22
 * Controller which handles actions related to Selection in Vidi Backend.
23
 */
24
class SelectionController extends ActionController
25
{
26
27
    /**
28
     * @var \Fab\Vidi\Domain\Repository\SelectionRepository
29
     * @inject
30
     */
31
    protected $selectionRepository;
32
33
    /**
34
     * @param Selection $selection
35
     */
36
    public function createAction(Selection $selection = NULL)
37
    {
38
        $selection->setDataType($this->getModuleLoader()->getDataType());
0 ignored issues
show
Bug introduced by
It seems like $selection is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
39
40
        $selection->setOwner($this->getBackendUser()->user['uid']);
41
        $this->selectionRepository->add($selection);
42
        $this->redirect('edit', 'Selection', 'vidi', array('dataType' => $selection->getDataType()));
43
    }
44
45
    /**
46
     * @param Selection $selection
47
     * @return string
48
     */
49
    public function deleteAction(Selection $selection)
50
    {
51
        $this->selectionRepository->remove($selection);
52
        return 'ok';
53
    }
54
55
    /**
56
     * @param Selection $selection
57
     */
58
    public function updateAction(Selection $selection)
59
    {
60
        $this->selectionRepository->update($selection);
61
        $this->redirect('show', 'Selection', 'vidi', array('selection' => $selection->getUid()));
62
    }
63
64
    /**
65
     * @param Selection $selection
66
     */
67
    public function showAction(Selection $selection)
68
    {
69
        $this->view->assign('selection', $selection);
70
    }
71
72
    /**
73
     * Returns an editing form for a given data type.
74
     *
75
     * @param string $dataType
76
     */
77
    public function editAction($dataType)
78
    {
79
        $selections = $this->selectionRepository->findByDataTypeForCurrentBackendUser($dataType);
80
        $this->view->assign('selections', $selections);
81
    }
82
83
    /**
84
     * @param string $dataType
85
     */
86
    public function listAction($dataType)
87
    {
88
        $selections = $this->selectionRepository->findByDataTypeForCurrentBackendUser($dataType);
89
        $this->view->assign('selections', $selections);
90
    }
91
92
    /**
93
     * Get the Vidi Module Loader.
94
     *
95
     * @return \Fab\Vidi\Module\ModuleLoader
96
     */
97
    protected function getModuleLoader()
98
    {
99
        return GeneralUtility::makeInstance('Fab\Vidi\Module\ModuleLoader');
100
    }
101
102
    /**
103
     * Returns an instance of the current Backend User.
104
     *
105
     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
106
     */
107
    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...
108
    {
109
        return $GLOBALS['BE_USER'];
110
    }
111
112
}