1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://www.gnu.org/copyleft/lgpl.html |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
6
|
|
|
* @package flow |
7
|
|
|
* @subpackage Controller |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Shop\Controller; |
12
|
|
|
|
13
|
|
|
use Neos\Flow\Annotations as Flow; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Controller for JQuery based adminisration interface. |
18
|
|
|
* @package flow |
19
|
|
|
* @subpackage Controller |
20
|
|
|
*/ |
21
|
|
|
class JqadmController extends \Neos\Flow\Mvc\Controller\ActionController |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var \Aimeos\Shop\Base\Aimeos |
25
|
|
|
* @Flow\Inject |
26
|
|
|
*/ |
27
|
|
|
protected $aimeos; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \Aimeos\Shop\Base\Context |
31
|
|
|
* @Flow\Inject |
32
|
|
|
*/ |
33
|
|
|
protected $context; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \Aimeos\Shop\Base\I18n |
37
|
|
|
* @Flow\Inject |
38
|
|
|
*/ |
39
|
|
|
protected $i18n; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var \Aimeos\Shop\Base\Locale |
43
|
|
|
* @Flow\Inject |
44
|
|
|
*/ |
45
|
|
|
protected $locale; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var \Aimeos\Shop\Base\View |
49
|
|
|
* @Flow\Inject |
50
|
|
|
*/ |
51
|
|
|
protected $viewbase; |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns the JS file content |
56
|
|
|
* |
57
|
|
|
* @return \Neos\Flow\Http\Response Response object |
58
|
|
|
*/ |
59
|
|
|
public function fileAction() |
60
|
|
|
{ |
61
|
|
|
$files = array(); |
62
|
|
|
$aimeos = $this->aimeos->get(); |
63
|
|
|
$type = $this->request->getArgument( 'type' ); |
64
|
|
|
|
65
|
|
|
foreach( $aimeos->getCustomPaths( 'admin/jqadm' ) as $base => $paths ) |
66
|
|
|
{ |
67
|
|
|
foreach( $paths as $path ) |
68
|
|
|
{ |
69
|
|
|
$jsbAbsPath = $base . '/' . $path; |
70
|
|
|
$jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $jsbAbsPath ) ); |
71
|
|
|
$files = array_merge( $files, $jsb2->getFiles( $type ) ); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
foreach( $files as $file ) |
76
|
|
|
{ |
77
|
|
|
if( ( $content = file_get_contents( $file ) ) !== false ) { |
78
|
|
|
$this->response->appendContent( $content ); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if( $type === 'js' ) { |
83
|
|
|
$this->response->setHeader( 'Content-Type', 'application/javascript' ); |
84
|
|
|
} elseif( $type === 'css' ) { |
85
|
|
|
$this->response->setHeader( 'Content-Type', 'text/css' ); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Returns the HTML code for a copy of a resource object |
92
|
|
|
* |
93
|
|
|
* @param string Resource location, e.g. "product" |
94
|
|
|
* @param string $site Unique site code |
95
|
|
|
* @return string Generated output |
96
|
|
|
* @Flow\Session(autoStart = TRUE) |
97
|
|
|
*/ |
98
|
|
|
public function copyAction( $resource, $site = 'default' ) |
99
|
|
|
{ |
100
|
|
|
$cntl = $this->createAdmin( $site, $resource ); |
101
|
|
|
|
102
|
|
|
if( ( $html = $cntl->copy() ) == '' ) { |
103
|
|
|
return $this->setPsrResponse( $cntl->getView()->response() ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $this->getHtml( $html ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Returns the HTML code for a new resource object |
112
|
|
|
* |
113
|
|
|
* @param string Resource location, e.g. "product" |
114
|
|
|
* @param string $site Unique site code |
115
|
|
|
* @return string Generated output |
116
|
|
|
* @Flow\Session(autoStart = TRUE) |
117
|
|
|
*/ |
118
|
|
|
public function createAction( $resource, $site = 'default' ) |
119
|
|
|
{ |
120
|
|
|
$cntl = $this->createAdmin( $site, $resource ); |
121
|
|
|
|
122
|
|
|
if( ( $html = $cntl->create() ) == '' ) { |
123
|
|
|
return $this->setPsrResponse( $cntl->getView()->response() ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $this->getHtml( $html ); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Deletes the resource object or a list of resource objects |
132
|
|
|
* |
133
|
|
|
* @param string Resource location, e.g. "product" |
134
|
|
|
* @param string $site Unique site code |
135
|
|
|
* @return string Generated output |
136
|
|
|
* @Flow\Session(autoStart = TRUE) |
137
|
|
|
*/ |
138
|
|
|
public function deleteAction( $resource, $site = 'default' ) |
139
|
|
|
{ |
140
|
|
|
$cntl = $this->createAdmin( $site, $resource ); |
141
|
|
|
|
142
|
|
|
if( ( $html = $cntl->delete() ) == '' ) { |
143
|
|
|
return $this->setPsrResponse( $cntl->getView()->response() ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return $this->getHtml( $html ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Exports the resource object |
152
|
|
|
* |
153
|
|
|
* @param string Resource location, e.g. "order" |
154
|
|
|
* @param string $site Unique site code |
155
|
|
|
* @return string Generated output |
156
|
|
|
* @Flow\Session(autoStart = TRUE) |
157
|
|
|
*/ |
158
|
|
|
public function exportAction( $resource, $site = 'default' ) |
159
|
|
|
{ |
160
|
|
|
$cntl = $this->createAdmin( $site, $resource ); |
161
|
|
|
|
162
|
|
|
if( ( $html = $cntl->export() ) == '' ) { |
|
|
|
|
163
|
|
|
return $this->setPsrResponse( $cntl->getView()->response() ); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
return $this->getHtml( $html ); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Returns the HTML code for the requested resource object |
172
|
|
|
* |
173
|
|
|
* @param string Resource location, e.g. "product" |
174
|
|
|
* @param string $site Unique site code |
175
|
|
|
* @return string Generated output |
176
|
|
|
* @Flow\Session(autoStart = TRUE) |
177
|
|
|
*/ |
178
|
|
|
public function getAction( $resource, $site = 'default' ) |
179
|
|
|
{ |
180
|
|
|
$cntl = $this->createAdmin( $site, $resource ); |
181
|
|
|
|
182
|
|
|
if( ( $html = $cntl->get() ) == '' ) { |
183
|
|
|
return $this->setPsrResponse( $cntl->getView()->response() ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
return $this->getHtml( $html ); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Saves a new resource object |
192
|
|
|
* |
193
|
|
|
* @param string Resource location, e.g. "product" |
194
|
|
|
* @param string $site Unique site code |
195
|
|
|
* @return string Generated output |
196
|
|
|
* @Flow\Session(autoStart = TRUE) |
197
|
|
|
*/ |
198
|
|
|
public function saveAction( $resource, $site = 'default' ) |
199
|
|
|
{ |
200
|
|
|
$cntl = $this->createAdmin( $site, $resource ); |
201
|
|
|
|
202
|
|
|
if( ( $html = $cntl->save() ) == '' ) { |
203
|
|
|
return $this->setPsrResponse( $cntl->getView()->response() ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
return $this->getHtml( $html ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Returns the HTML code for a list of resource objects |
212
|
|
|
* |
213
|
|
|
* @param string Resource location, e.g. "product" |
214
|
|
|
* @param string $site Unique site code |
215
|
|
|
* @return string Generated output |
216
|
|
|
* @Flow\Session(autoStart = TRUE) |
217
|
|
|
*/ |
218
|
|
|
public function searchAction( $resource, $site = 'default' ) |
219
|
|
|
{ |
220
|
|
|
$cntl = $this->createAdmin( $site, $resource ); |
221
|
|
|
|
222
|
|
|
if( ( $html = $cntl->search() ) == '' ) { |
223
|
|
|
return $this->setPsrResponse( $cntl->getView()->response() ); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
return $this->getHtml( $html ); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Returns the resource controller |
232
|
|
|
* |
233
|
|
|
* @param string $sitecode Unique site code |
234
|
|
|
* @return \Aimeos\Admin\JQAdm\Iface JQAdm client object |
235
|
|
|
*/ |
236
|
|
|
protected function createAdmin( $sitecode, $resource ) |
237
|
|
|
{ |
238
|
|
|
$aimeos = $this->aimeos->get(); |
239
|
|
|
$paths = $aimeos->getCustomPaths( 'admin/jqadm/templates' ); |
240
|
|
|
$lang = ( $this->request->hasArgument( 'lang' ) ? $this->request->getArgument( 'lang' ) : 'en' ); |
241
|
|
|
|
242
|
|
|
$context = $this->context->get( null, 'backend' ); |
243
|
|
|
$context->setI18n( $this->i18n->get( array( $lang, 'en' ) ) ); |
244
|
|
|
$context->setLocale( $this->locale->getBackend( $context, $sitecode ) ); |
245
|
|
|
|
246
|
|
|
$view = $this->viewbase->create( $context, $this->uriBuilder, $paths, $this->request, $lang ); |
247
|
|
|
|
248
|
|
|
$view->aimeosType = 'Flow'; |
249
|
|
|
$view->aimeosVersion = $this->aimeos->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 the generated view including the HTML code |
260
|
|
|
* |
261
|
|
|
* @param string $content Content from admin client |
262
|
|
|
*/ |
263
|
|
|
protected function getHtml( $content ) |
264
|
|
|
{ |
265
|
|
|
$this->view->assign( 'content', $content ); |
266
|
|
|
return $this->view->render( 'index' ); |
|
|
|
|
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Set the response data from a PSR-7 response object |
272
|
|
|
* |
273
|
|
|
* @param \Psr\Http\Message\ResponseInterface $response PSR-7 response object |
274
|
|
|
* @return string Response message content |
275
|
|
|
*/ |
276
|
|
|
protected function setPsrResponse( \Psr\Http\Message\ResponseInterface $response ) |
277
|
|
|
{ |
278
|
|
|
$this->response->setStatus( $response->getStatusCode() ); |
279
|
|
|
|
280
|
|
|
foreach( $response->getHeaders() as $key => $value ) { |
281
|
|
|
$this->response->setHeader( $key, $value ); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
return (string) $response->getBody(); |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
|