1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license GPLv3, http://www.gnu.org/copyleft/gpl.html |
||
5 | * @copyright Aimeos (aimeos.org), 2015-2016 |
||
6 | * @package TYPO3 |
||
7 | */ |
||
8 | |||
9 | |||
10 | namespace Aimeos\Aimeos\Controller; |
||
11 | |||
12 | |||
13 | use Aimeos\Aimeos\Base; |
||
14 | |||
15 | |||
16 | /** |
||
17 | * Controller for the JSON API |
||
18 | * |
||
19 | * @package TYPO3 |
||
20 | */ |
||
21 | class JqadmController extends AbstractController |
||
22 | { |
||
23 | /** |
||
24 | * Initializes the object before the real action is called. |
||
25 | */ |
||
26 | protected function initializeAction() |
||
27 | { |
||
28 | $this->uriBuilder->setArgumentPrefix('tx_aimeos_web_aimeos'); |
||
29 | } |
||
30 | |||
31 | |||
32 | /** |
||
33 | * Returns the CSS/JS file content |
||
34 | * |
||
35 | * @return string CSS/JS files content |
||
36 | */ |
||
37 | public function fileAction() |
||
38 | { |
||
39 | $contents = ''; |
||
40 | $files = []; |
||
41 | $type = $this->request->getArgument('type'); |
||
42 | |||
43 | foreach (Base::aimeos()->getCustomPaths('admin/jqadm') as $base => $paths) { |
||
44 | foreach($paths as $path) { |
||
45 | $jsbAbsPath = $base . '/' . $path; |
||
46 | $jsb2 = new \Aimeos\MW\Jsb2\Standard($jsbAbsPath, dirname($jsbAbsPath)); |
||
47 | $files = array_merge($files, $jsb2->getFiles($type)); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | foreach ($files as $file) { |
||
52 | if (($content = file_get_contents($file)) === false) { |
||
53 | throw new \RuntimeException(sprintf('File "%1$s" not found', $jsbAbsPath)); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
54 | } |
||
55 | |||
56 | $contents .= $content; |
||
57 | } |
||
58 | |||
59 | $response = $this->responseFactory->createResponse() |
||
60 | ->withBody($this->streamFactory->createStream($contents)); |
||
61 | |||
62 | if ($type === 'js') { |
||
63 | $response = $response->withAddedHeader('Content-Type', 'application/javascript'); |
||
64 | } elseif ($type === 'css') { |
||
65 | $response = $response->withAddedHeader('Content-Type', 'text/css'); |
||
66 | } |
||
67 | |||
68 | return $response; |
||
69 | } |
||
70 | |||
71 | |||
72 | /** |
||
73 | * Returns the HTML code for batch operations on resource objects |
||
74 | * |
||
75 | * @return string Generated output |
||
76 | */ |
||
77 | public function batchAction() |
||
78 | { |
||
79 | $cntl = $this->createAdmin(); |
||
80 | |||
81 | if (($html = $cntl->batch()) == '') { |
||
82 | return $cntl->response(); |
||
83 | } |
||
84 | |||
85 | $this->view->assign('content', $html); |
||
86 | return $this->render(); |
||
87 | } |
||
88 | |||
89 | |||
90 | /** |
||
91 | * Returns the HTML code for a copy of a resource object |
||
92 | * |
||
93 | * @return string Generated output |
||
94 | */ |
||
95 | public function copyAction() |
||
96 | { |
||
97 | $cntl = $this->createAdmin(); |
||
98 | |||
99 | if (($html = $cntl->copy()) == '') { |
||
100 | return $cntl->response(); |
||
101 | } |
||
102 | |||
103 | $this->view->assign('content', $html); |
||
104 | return $this->render(); |
||
105 | } |
||
106 | |||
107 | |||
108 | /** |
||
109 | * Returns the HTML code for a new resource object |
||
110 | * |
||
111 | * @return string Generated output |
||
112 | */ |
||
113 | public function createAction() |
||
114 | { |
||
115 | $cntl = $this->createAdmin(); |
||
116 | |||
117 | if (($html = $cntl->create()) == '') { |
||
118 | return $cntl->response(); |
||
119 | } |
||
120 | |||
121 | $this->view->assign('content', $html); |
||
122 | return $this->render(); |
||
123 | } |
||
124 | |||
125 | |||
126 | /** |
||
127 | * Deletes the resource object or a list of resource objects |
||
128 | * |
||
129 | * @return string Generated output |
||
130 | */ |
||
131 | public function deleteAction() |
||
132 | { |
||
133 | $cntl = $this->createAdmin(); |
||
134 | |||
135 | if (($html = $cntl->delete()) == '') { |
||
136 | return $cntl->response(); |
||
137 | } |
||
138 | |||
139 | $this->view->assign('content', $html); |
||
140 | return $this->render(); |
||
141 | } |
||
142 | |||
143 | |||
144 | /** |
||
145 | * Exports the resource object |
||
146 | * |
||
147 | * @return string Generated output |
||
148 | */ |
||
149 | public function exportAction() |
||
150 | { |
||
151 | $cntl = $this->createAdmin(); |
||
152 | |||
153 | if (($html = $cntl->export()) == '') { |
||
154 | return $cntl->response(); |
||
155 | } |
||
156 | |||
157 | $this->view->assign('content', $html); |
||
158 | return $this->render(); |
||
159 | } |
||
160 | |||
161 | |||
162 | /** |
||
163 | * Returns the HTML code for the requested resource object |
||
164 | * |
||
165 | * @return string Generated output |
||
166 | */ |
||
167 | public function getAction() |
||
168 | { |
||
169 | $cntl = $this->createAdmin(); |
||
170 | |||
171 | if (($html = $cntl->get()) == '') { |
||
172 | return $cntl->response(); |
||
173 | } |
||
174 | |||
175 | $this->view->assign('content', $html); |
||
176 | return $this->render(); |
||
177 | } |
||
178 | |||
179 | |||
180 | /** |
||
181 | * Imports the resource object |
||
182 | * |
||
183 | * @return string Generated output |
||
184 | */ |
||
185 | public function importAction() |
||
186 | { |
||
187 | $cntl = $this->createAdmin(); |
||
188 | |||
189 | if (($html = $cntl->import()) == '') { |
||
190 | return $cntl->response(); |
||
191 | } |
||
192 | |||
193 | $this->view->assign('content', $html); |
||
194 | return $this->render(); |
||
195 | } |
||
196 | |||
197 | |||
198 | /** |
||
199 | * Saves a new resource object |
||
200 | * |
||
201 | * @return string Generated output |
||
202 | */ |
||
203 | public function saveAction() |
||
204 | { |
||
205 | $cntl = $this->createAdmin(); |
||
206 | |||
207 | if (($html = $cntl->save()) == '') { |
||
208 | return $cntl->response(); |
||
209 | } |
||
210 | |||
211 | $this->view->assign('content', $html); |
||
212 | return $this->render(); |
||
213 | } |
||
214 | |||
215 | |||
216 | /** |
||
217 | * Returns the HTML code for a list of resource objects |
||
218 | * |
||
219 | * @return string Generated output |
||
220 | */ |
||
221 | public function searchAction() |
||
222 | { |
||
223 | $cntl = $this->createAdmin(); |
||
224 | |||
225 | if (($html = $cntl->search()) == '') { |
||
226 | return $cntl->response(); |
||
227 | } |
||
228 | |||
229 | $this->view->assign('content', $html); |
||
230 | return $this->render(); |
||
231 | } |
||
232 | |||
233 | |||
234 | /** |
||
235 | * Returns the resource controller |
||
236 | * |
||
237 | * @return \Aimeos\Admin\JQAdm\Iface JQAdm client |
||
238 | */ |
||
239 | protected function createAdmin() : \Aimeos\Admin\JQAdm\Iface |
||
240 | { |
||
241 | $resource = $this->request->hasArgument('resource') ? $this->request->getArgument('resource') : 'dashboard'; |
||
242 | |||
243 | $aimeos = Base::aimeos(); |
||
244 | $context = $this->contextBackend('admin/jqadm/templates'); |
||
245 | |||
246 | $view = $context->view(); |
||
247 | |||
248 | $view->aimeosType = 'TYPO3'; |
||
249 | $view->aimeosVersion = Base::getVersion(); |
||
250 | $view->aimeosExtensions = implode(',', $aimeos->getExtensions()); |
||
251 | |||
252 | $context->setView($view); |
||
253 | |||
254 | return \Aimeos\Admin\JQAdm::create($context, $aimeos, $resource); |
||
255 | } |
||
256 | |||
257 | |||
258 | /** |
||
259 | * Returns a PSR-7 response for TYPO3 11+ |
||
260 | */ |
||
261 | protected function render() |
||
262 | { |
||
263 | if (isset($this->responseFactory)) { // TYPO3 11 |
||
264 | return $this->responseFactory->createResponse() |
||
265 | ->withAddedHeader('Content-Type', 'text/html; charset=utf-8') |
||
266 | ->withBody($this->streamFactory->createStream($this->view->render())); |
||
267 | } |
||
268 | } |
||
269 | |||
270 | |||
271 | /** |
||
272 | * Uses default view. |
||
273 | * |
||
274 | * return \TYPO3\CMS\Extbase\Mvc\View\ViewInterface View object |
||
275 | */ |
||
276 | protected function resolveView() : \TYPO3Fluid\Fluid\View\ViewInterface |
||
277 | { |
||
278 | if ($this->request->hasArgument('locale') && ($value = $this->request->getArgument('locale')) != '') { |
||
279 | $lang = $value; |
||
280 | } elseif (isset($GLOBALS['BE_USER']->uc['lang']) && $GLOBALS['BE_USER']->uc['lang'] != '') { |
||
281 | $lang = $GLOBALS['BE_USER']->uc['lang']; |
||
282 | } else { |
||
283 | $lang = 'en'; |
||
284 | } |
||
285 | |||
286 | $view = \TYPO3\CMS\Extbase\Mvc\Controller\ActionController::resolveView(); |
||
287 | |||
288 | $view->assign('theme', ($_COOKIE['aimeos_backend_theme'] ?? null) == 'dark' ? 'dark' : 'light'); |
||
289 | $view->assign('localeDir', in_array($lang, ['ar', 'az', 'dv', 'fa', 'he', 'ku', 'ur']) ? 'rtl' : 'ltr'); |
||
290 | $view->assign('locale', $lang); |
||
291 | |||
292 | return $view; |
||
293 | } |
||
294 | } |
||
295 |