|
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
|
|
|
* @param integer $id Unique resource ID |
|
96
|
|
|
* @return string Generated output |
|
97
|
|
|
*/ |
|
98
|
|
|
public function copyAction( $site = 'default', $resource, $id ) |
|
99
|
|
|
{ |
|
100
|
|
|
$cntl = $this->createClient( $site, $resource ); |
|
101
|
|
|
return $this->getHtml( $cntl->copy( $id ) ); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Returns the HTML code for a new resource object |
|
107
|
|
|
* |
|
108
|
|
|
* @param string Resource location, e.g. "product" |
|
109
|
|
|
* @param string $site Unique site code |
|
110
|
|
|
* @return string Generated output |
|
111
|
|
|
*/ |
|
112
|
|
|
public function createAction( $site = 'default', $resource ) |
|
113
|
|
|
{ |
|
114
|
|
|
$cntl = $this->createClient( $site, $resource ); |
|
115
|
|
|
return $this->getHtml( $cntl->create() ); |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Deletes the resource object or a list of resource objects |
|
121
|
|
|
* |
|
122
|
|
|
* @param string Resource location, e.g. "product" |
|
123
|
|
|
* @param string $site Unique site code |
|
124
|
|
|
* @param integer $id Unique resource ID |
|
125
|
|
|
* @return string Generated output |
|
126
|
|
|
*/ |
|
127
|
|
|
public function deleteAction( $site = 'default', $resource, $id ) |
|
|
|
|
|
|
128
|
|
|
{ |
|
129
|
|
|
$cntl = $this->createClient( $site, $resource ); |
|
130
|
|
|
|
|
131
|
|
|
if( ( $html = $cntl->delete() ) == '' ) { |
|
|
|
|
|
|
132
|
|
|
return $this->setPsrResponse( $cntl->getView()->response() ); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return $this->getHtml( $html ); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Returns the HTML code for the requested resource object |
|
141
|
|
|
* |
|
142
|
|
|
* @param string Resource location, e.g. "product" |
|
143
|
|
|
* @param string $site Unique site code |
|
144
|
|
|
* @param integer $id Unique resource ID |
|
145
|
|
|
* @return string Generated output |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getAction( $site = 'default', $resource, $id ) |
|
148
|
|
|
{ |
|
149
|
|
|
$cntl = $this->createClient( $site, $resource ); |
|
150
|
|
|
return $this->getHtml( $cntl->get( $id ) ); |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Saves a new resource object |
|
156
|
|
|
* |
|
157
|
|
|
* @param string Resource location, e.g. "product" |
|
158
|
|
|
* @param string $site Unique site code |
|
159
|
|
|
* @return string Generated output |
|
160
|
|
|
*/ |
|
161
|
|
|
public function saveAction( $site = 'default', $resource ) |
|
162
|
|
|
{ |
|
163
|
|
|
$cntl = $this->createClient( $site, $resource ); |
|
164
|
|
|
|
|
165
|
|
|
if( ( $html = $cntl->save() ) == '' ) { |
|
|
|
|
|
|
166
|
|
|
return $this->setPsrResponse( $cntl->getView()->response() ); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
return $this->getHtml( $html ); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Returns the HTML code for a list of resource objects |
|
175
|
|
|
* |
|
176
|
|
|
* @param string Resource location, e.g. "product" |
|
177
|
|
|
* @param string $site Unique site code |
|
178
|
|
|
* @return string Generated output |
|
179
|
|
|
*/ |
|
180
|
|
|
public function searchAction( $site = 'default', $resource ) |
|
181
|
|
|
{ |
|
182
|
|
|
$cntl = $this->createClient( $site, $resource ); |
|
183
|
|
|
return $this->getHtml( $cntl->search() ); |
|
|
|
|
|
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Returns the resource controller |
|
189
|
|
|
* |
|
190
|
|
|
* @param string $sitecode Unique site code |
|
191
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context item |
|
192
|
|
|
*/ |
|
193
|
|
|
protected function createClient( $sitecode, $resource ) |
|
194
|
|
|
{ |
|
195
|
|
|
$aimeos = $this->aimeos->get(); |
|
196
|
|
|
$lang = ( $this->request->hasArgument( 'lang' ) ? $this->request->getArgument( 'lang' ) : 'en' ); |
|
197
|
|
|
$templatePaths = $aimeos->getCustomPaths( 'admin/jqadm/templates' ); |
|
198
|
|
|
|
|
199
|
|
|
$context = $this->context->get( null, 'backend' ); |
|
200
|
|
|
$context->setI18n( $this->i18n->get( array( $lang, 'en' ) ) ); |
|
201
|
|
|
$context->setLocale( $this->locale->getBackend( $context, $sitecode ) ); |
|
202
|
|
|
$context->setView( $this->viewbase->create( $context, $this->uriBuilder, $templatePaths, $this->request, $lang ) ); |
|
203
|
|
|
|
|
204
|
|
|
return \Aimeos\Admin\JQAdm\Factory::createClient( $context, $templatePaths, $resource )->setAimeos( $aimeos ); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* Returns the generated view including the HTML code |
|
210
|
|
|
* |
|
211
|
|
|
* @param string $content Content from admin client |
|
212
|
|
|
*/ |
|
213
|
|
|
protected function getHtml( $content ) |
|
214
|
|
|
{ |
|
215
|
|
|
$version = $this->aimeos->getVersion(); |
|
216
|
|
|
$extnames = implode( ',', $this->aimeos->get()->getExtensions() ); |
|
217
|
|
|
$content = str_replace( ['{type}', '{version}', '{extensions}'], ['Flow', $version, $extnames], $content ); |
|
218
|
|
|
|
|
219
|
|
|
$this->view->assign( 'content', $content ); |
|
220
|
|
|
return $this->view->render( 'index' ); |
|
|
|
|
|
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* Set the response data from a PSR-7 response object |
|
226
|
|
|
* |
|
227
|
|
|
* @param \Psr\Http\Message\ResponseInterface $response PSR-7 response object |
|
228
|
|
|
* @return string Response message content |
|
229
|
|
|
*/ |
|
230
|
|
|
protected function setPsrResponse( \Psr\Http\Message\ResponseInterface $response ) |
|
231
|
|
|
{ |
|
232
|
|
|
$this->response->setStatus( $response->getStatusCode() ); |
|
233
|
|
|
|
|
234
|
|
|
foreach( $response->getHeaders() as $key => $value ) { |
|
235
|
|
|
$this->response->setHeader( $key, $value ); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
return (string) $response->getBody(); |
|
239
|
|
|
} |
|
240
|
|
|
} |
|
241
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.