AbstractController.php 6.19 KB
Newer Older
speedprogs_de's avatar
speedprogs_de committed
1
<?php
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*******************************************************************
 *  Copyright notice
 *
 *  (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
 *
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ******************************************************************/

/**
 * Abstract controller
 */
29
abstract class Tx_TerFe2_Controller_AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{

    /**
     * @var Tx_TerFe2_Security_Role
     */
    protected $securityRole;

    /**
     * @param Tx_TerFe2_Security_Role $securityRole
     */
    public function injectSecurityRole(Tx_TerFe2_Security_Role $securityRole)
    {
        $this->securityRole = $securityRole;
    }

    /**
     * Pre-parse TypoScript setup
     *
     * @return void
     */
    public function initializeAction()
    {
        // Pre-parse settings
        $this->settings = Tx_TerFe2_Utility_TypoScript::parse($this->settings);

        // Initialize the controller
        $this->initializeController();
    }


    /**
     * Override in concrete controller to initialize it
     *
     * @return void
     */
    protected function initializeController()
    {

    }


    /**
     * Translate a label
     *
     * @param string $label Label to translate
     * @param array $arguments Optional arguments array
     * @return string Translated label
     */
    protected function translate($label, array $arguments = array())
    {
        $extensionKey = $this->request->getControllerExtensionKey();
81
        return \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($label, $extensionKey, $arguments);
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
    }


    /**
     * Send flash message and redirect to given action
     *
     * @param string $message Identifier of the message to send
     * @param string $action Name of the action
     * @param string $title Title for the flash message
     * @param int $severity Severity for the flash message
     * @param string $controller Unqualified object name of the controller
     * @param string $extension Name of the extension containing the controller
     * @param array $arguments Arguments to pass to the target action
     * @return void
     */
97
    protected function redirectWithMessage($message, $action, $title = '', $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
98
99
                                           $controller = NULL, $extension = NULL, array $arguments = NULL)
    {
100
        $this->addFlashMessage($message, $title, $severity);
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
        $this->clearPageCache($GLOBALS['TSFE']->id);
        $this->redirect($action, $controller, $extension, $arguments);
    }


    /**
     * Send flash message and forward to given action
     *
     * @param string $message Identifier of the message to send
     * @param string $action Name of the action
     * @param string $controller Unqualified object name of the controller
     * @param string $extension Name of the extension containing the controller
     * @param array $arguments Arguments to pass to the target action
     * @return void
     */
    protected function forwardWithMessage($message, $action, $controller = NULL, $extension = NULL, array $arguments = NULL)
    {
118
        $this->addFlashMessage($message);
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
        $this->clearPageCache($GLOBALS['TSFE']->id);
        $this->forward($action, $controller, $extension, $arguments);
    }


    /**
     * Send flash message and redirect to given action
     *
     * @param string $message Identifier of the message to send
     * @param string $action Name of the action
     * @param string $controller Unqualified object name of the controller
     * @param string $extension Name of the extension containing the controller
     * @param array $arguments Arguments to pass to the target action
     * @return void
     */
    protected function redirectWithError($message, $action, $controller = NULL, $extension = NULL, array $arguments = NULL)
    {
136
        $this->addFlashMessage($message, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
        $this->clearPageCache($GLOBALS['TSFE']->id);
        $this->redirect($action, $controller, $extension, $arguments);
    }


    /**
     * Send flash message and forward to given action
     *
     * @param string $message Identifier of the message to send
     * @param string $action Name of the action
     * @param string $controller Unqualified object name of the controller
     * @param string $extension Name of the extension containing the controller
     * @param array $arguments Arguments to pass to the target action
     * @return void
     */
    protected function forwardWithError($message, $action, $controller = NULL, $extension = NULL, array $arguments = NULL)
    {
154
        $this->addFlashMessage($message, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
155
156
157
158
159
160
161
162
163
164
165
166
167
168
        $this->clearPageCache($GLOBALS['TSFE']->id);
        $this->forward($action, $controller, $extension, $arguments);
    }


    /**
     * Clear cache of given pages
     *
     * @param string $pages List of page ids
     * @return void
     */
    protected function clearPageCache($pages)
    {
        if (!empty($pages)) {
169
170
            $pages = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $pages, TRUE);
            $this->cacheService->clearPageCache([$pages]);
171
172
173
174
175
176
177
178
179
180
181
182
183
184
        }
    }


    /**
     * Adds the base uri if not already in place.
     *
     * WORKAROUND for #33788
     *
     * @param string $uri The URI
     * @return void
     */
    protected function addBaseUriIfNecessary($uri)
    {
185
        return \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl($uri);
186
187
188
    }

}