FocuspointController::main()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 9.344
c 0
b 0
f 0
cc 4
nc 6
nop 0
1
<?php
2
3
/**
4
 * Wizard controller.
5
 */
6
7
namespace HDNET\Focuspoint\Controller\Wizard;
8
9
use HDNET\Focuspoint\Service\WizardHandler\AbstractWizardHandler;
10
use HDNET\Focuspoint\Service\WizardHandler\File;
11
use HDNET\Focuspoint\Service\WizardHandler\FileReference;
12
use HDNET\Focuspoint\Service\WizardHandler\Group;
13
use Psr\Http\Message\ResponseInterface;
14
use Psr\Http\Message\ServerRequestInterface;
15
use TYPO3\CMS\Backend\Utility\BackendUtility;
16
use TYPO3\CMS\Core\Http\HtmlResponse;
17
use TYPO3\CMS\Core\Utility\ArrayUtility;
18
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
19
use TYPO3\CMS\Core\Utility\GeneralUtility;
20
use TYPO3\CMS\Core\Utility\HttpUtility;
21
use TYPO3\CMS\Fluid\View\StandaloneView;
22
23
/**
24
 * Wizard controller.
25
 */
26
class FocuspointController
27
{
28
    /**
29
     * Main action.
30
     *
31
     * @throws \Exception
32
     *
33
     * @return string
34
     */
35
    public function main()
36
    {
37
        $handler = $this->getCurrentHandler();
38
        $parameter = GeneralUtility::_GET();
39
        if (isset($parameter['save'])) {
40
            if (\is_object($handler)) {
41
                $handler->setCurrentPoint($parameter['xValue'] * 100, $parameter['yValue'] * 100);
42
            }
43
            HttpUtility::redirect($parameter['P']['returnUrl']);
44
        }
45
        $saveArguments = [
46
            'save' => 1,
47
            'P' => [
48
                'returnUrl' => $parameter['P']['returnUrl'],
49
            ],
50
        ];
51
52
        /** @var StandaloneView $template */
53
        $template = GeneralUtility::makeInstance(StandaloneView::class);
54
        $template->setTemplatePathAndFilename(ExtensionManagementUtility::extPath(
55
            'focuspoint',
56
            'Resources/Private/Templates/Wizard/Focuspoint.html'
57
        ));
58
59
        if (\is_object($handler)) {
60
            ArrayUtility::mergeRecursiveWithOverrule($saveArguments, $handler->getArguments());
61
            list($x, $y) = $handler->getCurrentPoint();
62
            $template->assign('filePath', $handler->getPublicUrl());
63
            $template->assign('currentLeft', (($x + 100) / 2) . '%');
64
            $template->assign('currentTop', (($y - 100) / -2) . '%');
65
        }
66
67
        $template->assign('saveUri', BackendUtility::getModuleUrl('focuspoint', $saveArguments));
0 ignored issues
show
Deprecated Code introduced by
The method TYPO3\CMS\Backend\Utilit...Utility::getModuleUrl() has been deprecated with message: since TYPO3 v9, will be removed in TYPO3 v10.0. Use UriBuilder instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
68
69
        return $template->render();
70
    }
71
72
    /**
73
     * Returns the Module menu for the AJAX request.
74
     *
75
     * @param ServerRequestInterface $request
76
     * @param ResponseInterface      $response
77
     *
78
     * @return ResponseInterface
79
     */
80
    public function mainAction(ServerRequestInterface $request, ResponseInterface $response = null)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
    {
82
        if($response === null) {
83
            $response = new HtmlResponse('');
84
        }
85
        $content = $this->main();
86
        $response->getBody()->write($content);
87
88
        return $response;
89
    }
90
91
    /**
92
     * Get the current handler.
93
     *
94
     * @return AbstractWizardHandler|null
95
     */
96
    protected function getCurrentHandler()
97
    {
98
        foreach ($this->getWizardHandler() as $handler) {
99
            /** @var $handler AbstractWizardHandler */
100
            if ($handler->canHandle()) {
101
                return $handler;
102
            }
103
        }
104
    }
105
106
    /**
107
     * Get the wizard handler.
108
     *
109
     * @return array
110
     */
111
    protected function getWizardHandler()
112
    {
113
        return [
114
            GeneralUtility::makeInstance(File::class),
115
            GeneralUtility::makeInstance(FileReference::class),
116
            GeneralUtility::makeInstance(Group::class),
117
        ];
118
    }
119
}
120