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\Bundle\FrameworkBundle\Controller\Controller; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Aimeos controller for the JQAdm admin interface |
20
|
|
|
* |
21
|
|
|
* @package symfony |
22
|
|
|
* @subpackage Controller |
23
|
|
|
*/ |
24
|
|
|
class JqadmController extends Controller |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Returns the JS file content |
28
|
|
|
* |
29
|
|
|
* @param $type File type, i.e. "css" or "js" |
30
|
|
|
* @return Response Response object |
31
|
|
|
*/ |
32
|
|
|
public function fileAction( $type ) |
33
|
|
|
{ |
34
|
|
|
$contents = ''; |
35
|
|
|
$files = array(); |
36
|
|
|
$aimeos = $this->get( 'aimeos' )->get(); |
37
|
|
|
|
38
|
|
|
foreach( $aimeos->getCustomPaths( 'admin/jqadm' ) as $base => $paths ) |
39
|
|
|
{ |
40
|
|
|
foreach( $paths as $path ) |
41
|
|
|
{ |
42
|
|
|
$jsbAbsPath = $base . '/' . $path; |
43
|
|
|
$jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $jsbAbsPath ) ); |
44
|
|
|
$files = array_merge( $files, $jsb2->getFiles( $type ) ); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
foreach( $files as $file ) |
49
|
|
|
{ |
50
|
|
|
if( ( $content = file_get_contents( $file ) ) !== false ) { |
51
|
|
|
$contents .= $content; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$response = new Response( $contents ); |
56
|
|
|
|
57
|
|
|
if( $type === 'js' ) { |
58
|
|
|
$response->headers->set( 'Content-Type', 'application/javascript' ); |
59
|
|
|
} elseif( $type === 'css' ) { |
60
|
|
|
$response->headers->set( 'Content-Type', 'text/css' ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $response; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Returns the HTML code for a copy of a resource object |
69
|
|
|
* |
70
|
|
|
* @param Request $request Symfony request object |
71
|
|
|
* @param string $resource Resource location, e.g. "product" |
72
|
|
|
* @param string $site Unique site code |
73
|
|
|
* @return Response Generated output |
74
|
|
|
*/ |
75
|
|
|
public function copyAction( Request $request, $resource, $site = 'default' ) |
76
|
|
|
{ |
77
|
|
|
$cntl = $this->createClient( $request, $site, $resource ); |
78
|
|
|
|
79
|
|
|
if( ( $html = $cntl->copy() ) == '' ) { |
80
|
|
|
return $cntl->getView()->response(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $this->getHtml( $html ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns the HTML code for a new resource object |
89
|
|
|
* |
90
|
|
|
* @param Request $request Symfony request object |
91
|
|
|
* @param string $resource Resource location, e.g. "product" |
92
|
|
|
* @param string $site Unique site code |
93
|
|
|
* @return Response Generated output |
94
|
|
|
*/ |
95
|
|
|
public function createAction( Request $request, $resource, $site = 'default' ) |
96
|
|
|
{ |
97
|
|
|
$cntl = $this->createClient( $request, $site, $resource ); |
98
|
|
|
|
99
|
|
|
if( ( $html = $cntl->create() ) == '' ) { |
100
|
|
|
return $cntl->getView()->response(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $this->getHtml( $html ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Deletes the resource object or a list of resource objects |
109
|
|
|
* |
110
|
|
|
* @param Request $request Symfony request object |
111
|
|
|
* @param string $resource Resource location, e.g. "product" |
112
|
|
|
* @param string $site Unique site code |
113
|
|
|
* @return Response Generated output |
114
|
|
|
*/ |
115
|
|
|
public function deleteAction( Request $request, $resource, $site = 'default' ) |
116
|
|
|
{ |
117
|
|
|
$cntl = $this->createClient( $request, $site, $resource ); |
118
|
|
|
|
119
|
|
|
if( ( $html = $cntl->delete() ) == '' ) { |
120
|
|
|
return $cntl->getView()->response(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $this->getHtml( $html ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Exports the requested resource object |
129
|
|
|
* |
130
|
|
|
* @param Request $request Symfony request object |
131
|
|
|
* @param string $resource Resource location, e.g. "product" |
132
|
|
|
* @param string $site Unique site code |
133
|
|
|
* @return Response Generated output |
134
|
|
|
*/ |
135
|
|
|
public function exportAction( Request $request, $resource, $site = 'default' ) |
136
|
|
|
{ |
137
|
|
|
$cntl = $this->createClient( $request, $site, $resource ); |
138
|
|
|
|
139
|
|
|
if( ( $html = $cntl->export() ) == '' ) { |
140
|
|
|
return $cntl->getView()->response(); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $this->getHtml( $html ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Returns the HTML code for the requested resource object |
149
|
|
|
* |
150
|
|
|
* @param Request $request Symfony request object |
151
|
|
|
* @param string $resource Resource location, e.g. "product" |
152
|
|
|
* @param string $site Unique site code |
153
|
|
|
* @return Response Generated output |
154
|
|
|
*/ |
155
|
|
|
public function getAction( Request $request, $resource, $site = 'default' ) |
156
|
|
|
{ |
157
|
|
|
$cntl = $this->createClient( $request, $site, $resource ); |
158
|
|
|
|
159
|
|
|
if( ( $html = $cntl->get() ) == '' ) { |
160
|
|
|
return $cntl->getView()->response(); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
return $this->getHtml( $html ); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Saves a new resource object |
169
|
|
|
* |
170
|
|
|
* @param Request $request Symfony request object |
171
|
|
|
* @param string $resource Resource location, e.g. "product" |
172
|
|
|
* @param string $site Unique site code |
173
|
|
|
* @return Response Generated output |
174
|
|
|
*/ |
175
|
|
|
public function saveAction( Request $request, $resource, $site = 'default' ) |
176
|
|
|
{ |
177
|
|
|
$cntl = $this->createClient( $request, $site, $resource ); |
178
|
|
|
|
179
|
|
|
if( ( $html = $cntl->save() ) == '' ) { |
180
|
|
|
return $cntl->getView()->response(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
return $this->getHtml( $html ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Returns the HTML code for a list of resource objects |
189
|
|
|
* |
190
|
|
|
* @param Request $request Symfony request object |
191
|
|
|
* @param string $resource Resource location, e.g. "product" |
192
|
|
|
* @param string $site Unique site code |
193
|
|
|
* @return Response Generated output |
194
|
|
|
*/ |
195
|
|
|
public function searchAction( Request $request, $resource, $site = 'default' ) |
196
|
|
|
{ |
197
|
|
|
$cntl = $this->createClient( $request, $site, $resource ); |
198
|
|
|
|
199
|
|
|
if( ( $html = $cntl->search() ) == '' ) { |
200
|
|
|
return $cntl->getView()->response(); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
return $this->getHtml( $html ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Returns the resource controller |
209
|
|
|
* |
210
|
|
|
* @param Request $request Symfony request object |
211
|
|
|
* @param string $site Unique site code |
212
|
|
|
* @param string $resource Resource location, e.g. "product" |
213
|
|
|
* @return \Aimeos\Admin\JQAdm\Iface Context item |
214
|
|
|
*/ |
215
|
|
|
protected function createClient( Request $request, $site, $resource ) |
216
|
|
|
{ |
217
|
|
|
$lang = $request->get( 'lang', 'en' ); |
218
|
|
|
|
219
|
|
|
$aimeos = $this->get( 'aimeos' )->get(); |
220
|
|
|
$templatePaths = $aimeos->getCustomPaths( 'admin/jqadm/templates' ); |
221
|
|
|
|
222
|
|
|
$context = $this->get( 'aimeos_context' )->get( false, 'backend' ); |
223
|
|
|
$context->setI18n( $this->get( 'aimeos_i18n' )->get( array( $lang, 'en' ) ) ); |
224
|
|
|
$context->setLocale( $this->get( 'aimeos_locale' )->getBackend( $context, $site ) ); |
225
|
|
|
|
226
|
|
|
$view = $this->get( 'aimeos_view' )->create( $context, $templatePaths, $lang ); |
227
|
|
|
$context->setView( $view ); |
228
|
|
|
|
229
|
|
|
return \Aimeos\Admin\JQAdm\Factory::createClient( $context, $templatePaths, $resource )->setAimeos( $aimeos ); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Returns the generated HTML code |
235
|
|
|
* |
236
|
|
|
* @param string $content Content from admin client |
237
|
|
|
* @return Response View for rendering the output |
238
|
|
|
*/ |
239
|
|
|
protected function getHtml( $content ) |
240
|
|
|
{ |
241
|
|
|
$version = $this->get( 'aimeos' )->getVersion(); |
242
|
|
|
$extnames = implode( ',', $this->get( 'aimeos' )->get()->getExtensions() ); |
243
|
|
|
$content = str_replace( ['{type}', '{version}', '{extensions}'], ['Symfony', $version, $extnames], $content ); |
244
|
|
|
|
245
|
|
|
return $this->render( 'AimeosShopBundle:Jqadm:index.html.twig', array( 'content' => $content ) ); |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
|