|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
|
6
|
|
|
* @package symfony |
|
7
|
|
|
* @subpackage Controller |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\ShopBundle\Controller; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
15
|
|
|
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; |
|
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Aimeos controller for the JQAdm admin interface |
|
21
|
|
|
* |
|
22
|
|
|
* @package symfony |
|
23
|
|
|
* @subpackage Controller |
|
24
|
|
|
*/ |
|
25
|
|
|
class JqadmController extends AbstractController |
|
26
|
|
|
{ |
|
27
|
|
|
private $twig; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
public function __construct( \Twig\Environment $twig ) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->twig = $twig; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Returns the JS file content |
|
38
|
|
|
* |
|
39
|
|
|
* @param $name File type, i.e. "index-css" or "index-js" |
|
|
|
|
|
|
40
|
|
|
* @return Response Response object |
|
41
|
|
|
*/ |
|
42
|
|
|
public function fileAction( $name ) : Response |
|
43
|
|
|
{ |
|
44
|
|
|
$files = []; |
|
45
|
|
|
$aimeos = $this->container->get( 'aimeos' )->get(); |
|
46
|
|
|
|
|
47
|
|
|
foreach( $aimeos->getCustomPaths( 'admin/jqadm' ) as $base => $paths ) |
|
48
|
|
|
{ |
|
49
|
|
|
foreach( $paths as $path ) { |
|
50
|
|
|
$files[] = $base . '/' . $path; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$response = new Response( \Aimeos\Admin\JQAdm\Bundle::get( $files, $name ) ); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
if( str_ends_with( $name, 'js' ) ) { |
|
57
|
|
|
$response->headers->set( 'Content-Type', 'application/javascript' ); |
|
58
|
|
|
} elseif( str_ends_with( $name, 'css' ) ) { |
|
59
|
|
|
$response->headers->set( 'Content-Type', 'text/css' ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $response; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Returns the HTML code for a batch of a resource object |
|
68
|
|
|
* |
|
69
|
|
|
* @param Request $request Symfony request object |
|
70
|
|
|
* @param string $resource Resource location, e.g. "product" |
|
71
|
|
|
* @param string $site Unique site code |
|
72
|
|
|
* @return Response Generated output |
|
73
|
|
|
*/ |
|
74
|
|
|
public function batchAction( Request $request, $resource, $site = 'default' ) : Response |
|
75
|
|
|
{ |
|
76
|
|
|
$cntl = $this->createAdmin( $request, $site, $resource ); |
|
77
|
|
|
|
|
78
|
|
|
if( ( $html = $cntl->batch() ) == '' ) { |
|
79
|
|
|
return ( new HttpFoundationFactory() )->createResponse( $cntl->view()->response() ); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $this->getHtml( (string) $html, $request->get( 'locale', 'en' ) ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Returns the HTML code for a copy of a resource object |
|
88
|
|
|
* |
|
89
|
|
|
* @param Request $request Symfony request object |
|
90
|
|
|
* @param string $resource Resource location, e.g. "product" |
|
91
|
|
|
* @param string $site Unique site code |
|
92
|
|
|
* @return Response Generated output |
|
93
|
|
|
*/ |
|
94
|
|
|
public function copyAction( Request $request, $resource, $site = 'default' ) : Response |
|
95
|
|
|
{ |
|
96
|
|
|
$cntl = $this->createAdmin( $request, $site, $resource ); |
|
97
|
|
|
|
|
98
|
|
|
if( ( $html = $cntl->copy() ) == '' ) { |
|
99
|
|
|
return ( new HttpFoundationFactory() )->createResponse( $cntl->view()->response() ); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $this->getHtml( (string) $html, $request->get( 'locale', 'en' ) ); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Returns the HTML code for a new resource object |
|
108
|
|
|
* |
|
109
|
|
|
* @param Request $request Symfony request object |
|
110
|
|
|
* @param string $resource Resource location, e.g. "product" |
|
111
|
|
|
* @param string $site Unique site code |
|
112
|
|
|
* @return Response Generated output |
|
113
|
|
|
*/ |
|
114
|
|
|
public function createAction( Request $request, $resource, $site = 'default' ) : Response |
|
115
|
|
|
{ |
|
116
|
|
|
$cntl = $this->createAdmin( $request, $site, $resource ); |
|
117
|
|
|
|
|
118
|
|
|
if( ( $html = $cntl->create() ) == '' ) { |
|
119
|
|
|
return ( new HttpFoundationFactory() )->createResponse( $cntl->view()->response() ); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return $this->getHtml( (string) $html, $request->get( 'locale', 'en' ) ); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Deletes the resource object or a list of resource objects |
|
128
|
|
|
* |
|
129
|
|
|
* @param Request $request Symfony request object |
|
130
|
|
|
* @param string $resource Resource location, e.g. "product" |
|
131
|
|
|
* @param string $site Unique site code |
|
132
|
|
|
* @return Response Generated output |
|
133
|
|
|
*/ |
|
134
|
|
|
public function deleteAction( Request $request, $resource, $site = 'default' ) : Response |
|
135
|
|
|
{ |
|
136
|
|
|
$cntl = $this->createAdmin( $request, $site, $resource ); |
|
137
|
|
|
|
|
138
|
|
|
if( ( $html = $cntl->delete() ) == '' ) { |
|
139
|
|
|
return ( new HttpFoundationFactory() )->createResponse( $cntl->view()->response() ); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
return $this->getHtml( (string) $html, $request->get( 'locale', 'en' ) ); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Exports the requested resource object |
|
148
|
|
|
* |
|
149
|
|
|
* @param Request $request Symfony request object |
|
150
|
|
|
* @param string $resource Resource location, e.g. "product" |
|
151
|
|
|
* @param string $site Unique site code |
|
152
|
|
|
* @return Response Generated output |
|
153
|
|
|
*/ |
|
154
|
|
|
public function exportAction( Request $request, $resource, $site = 'default' ) : Response |
|
155
|
|
|
{ |
|
156
|
|
|
$cntl = $this->createAdmin( $request, $site, $resource ); |
|
157
|
|
|
|
|
158
|
|
|
if( ( $html = $cntl->export() ) == '' ) { |
|
159
|
|
|
return ( new HttpFoundationFactory() )->createResponse( $cntl->view()->response() ); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
return $this->getHtml( (string) $html, $request->get( 'locale', 'en' ) ); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Returns the HTML code for the requested resource object |
|
168
|
|
|
* |
|
169
|
|
|
* @param Request $request Symfony request object |
|
170
|
|
|
* @param string $resource Resource location, e.g. "product" |
|
171
|
|
|
* @param string $site Unique site code |
|
172
|
|
|
* @return Response Generated output |
|
173
|
|
|
*/ |
|
174
|
|
|
public function getAction( Request $request, $resource, $site = 'default' ) : Response |
|
175
|
|
|
{ |
|
176
|
|
|
$cntl = $this->createAdmin( $request, $site, $resource ); |
|
177
|
|
|
|
|
178
|
|
|
if( ( $html = $cntl->get() ) == '' ) { |
|
179
|
|
|
return ( new HttpFoundationFactory() )->createResponse( $cntl->view()->response() ); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
return $this->getHtml( (string) $html, $request->get( 'locale', 'en' ) ); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Imports the requested resource object |
|
188
|
|
|
* |
|
189
|
|
|
* @param Request $request Symfony request object |
|
190
|
|
|
* @param string $resource Resource location, e.g. "product" |
|
191
|
|
|
* @param string $site Unique site code |
|
192
|
|
|
* @return Response Generated output |
|
193
|
|
|
*/ |
|
194
|
|
|
public function importAction( Request $request, $resource, $site = 'default' ) : Response |
|
195
|
|
|
{ |
|
196
|
|
|
$cntl = $this->createAdmin( $request, $site, $resource ); |
|
197
|
|
|
|
|
198
|
|
|
if( ( $html = $cntl->import() ) == '' ) { |
|
199
|
|
|
return ( new HttpFoundationFactory() )->createResponse( $cntl->view()->response() ); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
return $this->getHtml( (string) $html, $request->get( 'locale', 'en' ) ); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Saves a new resource object |
|
208
|
|
|
* |
|
209
|
|
|
* @param Request $request Symfony request object |
|
210
|
|
|
* @param string $resource Resource location, e.g. "product" |
|
211
|
|
|
* @param string $site Unique site code |
|
212
|
|
|
* @return Response Generated output |
|
213
|
|
|
*/ |
|
214
|
|
|
public function saveAction( Request $request, $resource, $site = 'default' ) : Response |
|
215
|
|
|
{ |
|
216
|
|
|
$cntl = $this->createAdmin( $request, $site, $resource ); |
|
217
|
|
|
|
|
218
|
|
|
if( ( $html = $cntl->save() ) == '' ) { |
|
219
|
|
|
return ( new HttpFoundationFactory() )->createResponse( $cntl->view()->response() ); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
return $this->getHtml( (string) $html, $request->get( 'locale', 'en' ) ); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* Returns the HTML code for a list of resource objects |
|
228
|
|
|
* |
|
229
|
|
|
* @param Request $request Symfony request object |
|
230
|
|
|
* @param string $resource Resource location, e.g. "product" |
|
231
|
|
|
* @param string $site Unique site code |
|
232
|
|
|
* @return Response Generated output |
|
233
|
|
|
*/ |
|
234
|
|
|
public function searchAction( Request $request, $resource, $site = 'default' ) : Response |
|
235
|
|
|
{ |
|
236
|
|
|
$cntl = $this->createAdmin( $request, $site, $resource ); |
|
237
|
|
|
|
|
238
|
|
|
if( ( $html = $cntl->search() ) == '' ) { |
|
239
|
|
|
return ( new HttpFoundationFactory() )->createResponse( $cntl->view()->response() ); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
return $this->getHtml( (string) $html, $request->get( 'locale', 'en' ) ); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* Returns the resource controller |
|
248
|
|
|
* |
|
249
|
|
|
* @param Request $request Symfony request object |
|
250
|
|
|
* @param string $site Unique site code |
|
251
|
|
|
* @param string $resource Resource location, e.g. "product" |
|
252
|
|
|
* @return \Aimeos\Admin\JQAdm\Iface Context item |
|
253
|
|
|
*/ |
|
254
|
|
|
protected function createAdmin( Request $request, $site, $resource ) : \Aimeos\Admin\JQAdm\Iface |
|
255
|
|
|
{ |
|
256
|
|
|
$lang = $request->get( 'locale', 'en' ); |
|
257
|
|
|
|
|
258
|
|
|
$aimeos = $this->container->get( 'aimeos' )->get(); |
|
259
|
|
|
$templatePaths = $aimeos->getTemplatePaths( 'admin/jqadm/templates' ); |
|
260
|
|
|
|
|
261
|
|
|
$context = $this->container->get( 'aimeos.context' )->get( false, 'backend' ); |
|
262
|
|
|
$context->setI18n( $this->container->get( 'aimeos.i18n' )->get( array( $lang, 'en' ) ) ); |
|
263
|
|
|
$context->setLocale( $this->container->get( 'aimeos.locale' )->getBackend( $context, $site ) ); |
|
264
|
|
|
|
|
265
|
|
|
$view = $this->container->get( 'aimeos.view' )->create( $context, $templatePaths, $lang ); |
|
266
|
|
|
|
|
267
|
|
|
$view->aimeosType = 'Symfony'; |
|
268
|
|
|
$view->aimeosVersion = $this->container->get( 'aimeos' )->getVersion(); |
|
269
|
|
|
$view->aimeosExtensions = implode( ',', $aimeos->getExtensions() ); |
|
270
|
|
|
|
|
271
|
|
|
$context->setView( $view ); |
|
272
|
|
|
|
|
273
|
|
|
return \Aimeos\Admin\JQAdm::create( $context, $aimeos, $resource ); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* Returns the generated HTML code |
|
279
|
|
|
* |
|
280
|
|
|
* @param string $content Content from admin client |
|
281
|
|
|
* @param string $lang ISO language code |
|
282
|
|
|
* @return Response View for rendering the output |
|
283
|
|
|
*/ |
|
284
|
|
|
protected function getHtml( string $content, string $lang ) : Response |
|
285
|
|
|
{ |
|
286
|
|
|
return new Response( $this->twig->render( '@AimeosShop/Jqadm/index.html.twig', [ |
|
287
|
|
|
'content' => $content, |
|
288
|
|
|
'locale' => $lang, |
|
289
|
|
|
'localeDir' => in_array( $lang, ['ar', 'az', 'dv', 'fa', 'he', 'ku', 'ur'] ) ? 'rtl' : 'ltr', |
|
290
|
|
|
'theme' => ( $_COOKIE['aimeos_backend_theme'] ?? '' ) == 'dark' ? 'dark' : 'light' |
|
291
|
|
|
] ) ); |
|
292
|
|
|
} |
|
293
|
|
|
} |
|
294
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths