1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * @license MIT, http://opensource.org/licenses/MIT |
||||
5 | * @copyright Aimeos (aimeos.org), 2015-2016 |
||||
6 | * @package laravel |
||||
7 | * @subpackage Controller |
||||
8 | */ |
||||
9 | |||||
10 | |||||
11 | namespace Aimeos\Shop\Controller; |
||||
12 | |||||
13 | use Illuminate\Support\Facades\View; |
||||
14 | use Illuminate\Support\Facades\Route; |
||||
15 | use Illuminate\Support\Facades\Input; |
||||
16 | use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
||||
17 | |||||
18 | |||||
19 | /** |
||||
20 | * Aimeos controller for the JQuery admin interface |
||||
21 | * |
||||
22 | * @package laravel |
||||
23 | * @subpackage Controller |
||||
24 | */ |
||||
25 | class JqadmController extends AdminController |
||||
26 | { |
||||
27 | use AuthorizesRequests; |
||||
28 | |||||
29 | |||||
30 | /** |
||||
31 | * Returns the JS file content |
||||
32 | * |
||||
33 | * @return \Illuminate\Http\Response Response object containing the generated output |
||||
34 | */ |
||||
35 | public function fileAction() |
||||
36 | { |
||||
37 | if( config( 'shop.authorize', true ) ) { |
||||
38 | $this->authorize( 'admin', [JqadmController::class, ['admin', 'editor']] ); |
||||
39 | } |
||||
40 | |||||
41 | $contents = ''; |
||||
42 | $files = array(); |
||||
43 | $aimeos = app( 'aimeos' )->get(); |
||||
44 | $type = Route::input( 'type', Input::get( 'type', 'js' ) ); |
||||
45 | |||||
46 | foreach( $aimeos->getCustomPaths( 'admin/jqadm' ) as $base => $paths ) |
||||
47 | { |
||||
48 | foreach( $paths as $path ) |
||||
49 | { |
||||
50 | $jsbAbsPath = $base . '/' . $path; |
||||
51 | $jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $jsbAbsPath ) ); |
||||
52 | $files = array_merge( $files, $jsb2->getFiles( $type ) ); |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
53 | } |
||||
54 | } |
||||
55 | |||||
56 | foreach( $files as $file ) |
||||
57 | { |
||||
58 | if( ( $content = file_get_contents( $file ) ) !== false ) { |
||||
59 | $contents .= $content; |
||||
60 | } |
||||
61 | } |
||||
62 | |||||
63 | $response = response( $contents ); |
||||
64 | |||||
65 | if( $type === 'js' ) { |
||||
66 | $response->header( 'Content-Type', 'application/javascript' ); |
||||
67 | } elseif( $type === 'css' ) { |
||||
68 | $response->header( 'Content-Type', 'text/css' ); |
||||
69 | } |
||||
70 | |||||
71 | return $response; |
||||
72 | } |
||||
73 | |||||
74 | |||||
75 | /** |
||||
76 | * Returns the HTML code for a copy of a resource object |
||||
77 | * |
||||
78 | * @return string Generated output |
||||
79 | */ |
||||
80 | public function copyAction() |
||||
81 | { |
||||
82 | if( config( 'shop.authorize', true ) ) { |
||||
83 | $this->authorize( 'admin', [JqadmController::class, ['admin', 'editor']] ); |
||||
84 | } |
||||
85 | |||||
86 | $cntl = $this->createAdmin(); |
||||
87 | |||||
88 | if( ( $html = $cntl->copy() ) == '' ) { |
||||
89 | return $cntl->getView()->response(); |
||||
90 | } |
||||
91 | |||||
92 | return $this->getHtml( $html ); |
||||
93 | } |
||||
94 | |||||
95 | |||||
96 | /** |
||||
97 | * Returns the HTML code for a new resource object |
||||
98 | * |
||||
99 | * @return string Generated output |
||||
100 | */ |
||||
101 | public function createAction() |
||||
102 | { |
||||
103 | if( config( 'shop.authorize', true ) ) { |
||||
104 | $this->authorize( 'admin', [JqadmController::class, ['admin', 'editor']] ); |
||||
105 | } |
||||
106 | |||||
107 | $cntl = $this->createAdmin(); |
||||
108 | |||||
109 | if( ( $html = $cntl->create() ) == '' ) { |
||||
110 | return $cntl->getView()->response(); |
||||
111 | } |
||||
112 | |||||
113 | return $this->getHtml( $html ); |
||||
114 | } |
||||
115 | |||||
116 | |||||
117 | /** |
||||
118 | * Deletes the resource object or a list of resource objects |
||||
119 | * |
||||
120 | * @return string Generated output |
||||
121 | */ |
||||
122 | public function deleteAction() |
||||
123 | { |
||||
124 | if( config( 'shop.authorize', true ) ) { |
||||
125 | $this->authorize( 'admin', [JqadmController::class, ['admin', 'editor']] ); |
||||
126 | } |
||||
127 | |||||
128 | $cntl = $this->createAdmin(); |
||||
129 | |||||
130 | if( ( $html = $cntl->delete() ) == '' ) { |
||||
131 | return $cntl->getView()->response(); |
||||
132 | } |
||||
133 | |||||
134 | return $this->getHtml( $html ); |
||||
135 | } |
||||
136 | |||||
137 | |||||
138 | /** |
||||
139 | * Exports the data for a resource object |
||||
140 | * |
||||
141 | * @return string Generated output |
||||
142 | */ |
||||
143 | public function exportAction() |
||||
144 | { |
||||
145 | if( config( 'shop.authorize', true ) ) { |
||||
146 | $this->authorize( 'admin', [JqadmController::class, ['admin', 'editor']] ); |
||||
147 | } |
||||
148 | |||||
149 | $cntl = $this->createAdmin(); |
||||
150 | |||||
151 | if( ( $html = $cntl->export() ) == '' ) { |
||||
0 ignored issues
–
show
The method
export() does not exist on Aimeos\Admin\JQAdm\Iface . It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface or Aimeos\Admin\JQAdm\Common\Decorator\Iface . Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
152 | return $cntl->getView()->response(); |
||||
153 | } |
||||
154 | |||||
155 | return $this->getHtml( $html ); |
||||
156 | } |
||||
157 | |||||
158 | |||||
159 | /** |
||||
160 | * Returns the HTML code for the requested resource object |
||||
161 | * |
||||
162 | * @return string Generated output |
||||
163 | */ |
||||
164 | public function getAction() |
||||
165 | { |
||||
166 | if( config( 'shop.authorize', true ) ) { |
||||
167 | $this->authorize( 'admin', [JqadmController::class, ['admin', 'editor']] ); |
||||
168 | } |
||||
169 | |||||
170 | $cntl = $this->createAdmin(); |
||||
171 | |||||
172 | if( ( $html = $cntl->get() ) == '' ) { |
||||
173 | return $cntl->getView()->response(); |
||||
174 | } |
||||
175 | |||||
176 | return $this->getHtml( $html ); |
||||
177 | } |
||||
178 | |||||
179 | |||||
180 | /** |
||||
181 | * Saves a new resource object |
||||
182 | * |
||||
183 | * @return string Generated output |
||||
184 | */ |
||||
185 | public function saveAction() |
||||
186 | { |
||||
187 | if( config( 'shop.authorize', true ) ) { |
||||
188 | $this->authorize( 'admin', [JqadmController::class, ['admin', 'editor']] ); |
||||
189 | } |
||||
190 | |||||
191 | $cntl = $this->createAdmin(); |
||||
192 | |||||
193 | if( ( $html = $cntl->save() ) == '' ) { |
||||
194 | return $cntl->getView()->response(); |
||||
195 | } |
||||
196 | |||||
197 | return $this->getHtml( $html ); |
||||
198 | } |
||||
199 | |||||
200 | |||||
201 | /** |
||||
202 | * Returns the HTML code for a list of resource objects |
||||
203 | * |
||||
204 | * @return string Generated output |
||||
205 | */ |
||||
206 | public function searchAction() |
||||
207 | { |
||||
208 | if( config( 'shop.authorize', true ) ) { |
||||
209 | $this->authorize( 'admin', [JqadmController::class, ['admin', 'editor']] ); |
||||
210 | } |
||||
211 | |||||
212 | $cntl = $this->createAdmin(); |
||||
213 | |||||
214 | if( ( $html = $cntl->search() ) == '' ) { |
||||
215 | return $cntl->getView()->response(); |
||||
216 | } |
||||
217 | |||||
218 | return $this->getHtml( $html ); |
||||
219 | } |
||||
220 | |||||
221 | |||||
222 | /** |
||||
223 | * Returns the resource controller |
||||
224 | * |
||||
225 | * @return \Aimeos\Admin\JQAdm\Iface JQAdm client |
||||
226 | */ |
||||
227 | protected function createAdmin() |
||||
228 | { |
||||
229 | $site = Route::input( 'site', Input::get( 'site', 'default' ) ); |
||||
230 | $lang = Input::get( 'lang', config( 'app.locale', 'en' ) ); |
||||
231 | $resource = Route::input( 'resource' ); |
||||
232 | |||||
233 | $aimeos = app( 'aimeos' )->get(); |
||||
234 | $paths = $aimeos->getCustomPaths( 'admin/jqadm/templates' ); |
||||
235 | |||||
236 | $context = app( 'aimeos.context' )->get( false, 'backend' ); |
||||
237 | $context->setI18n( app('aimeos.i18n')->get( array( $lang, 'en' ) ) ); |
||||
238 | $context->setLocale( app('aimeos.locale')->getBackend( $context, $site ) ); |
||||
0 ignored issues
–
show
It seems like
$site can also be of type object ; however, parameter $site of Aimeos\Shop\Base\Locale::getBackend() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
239 | |||||
240 | $view = app( 'aimeos.view' )->create( $context, $paths, $lang ); |
||||
241 | |||||
242 | $view->aimeosType = 'Laravel'; |
||||
243 | $view->aimeosVersion = app( 'aimeos' )->getVersion(); |
||||
244 | $view->aimeosExtensions = implode( ',', $aimeos->getExtensions() ); |
||||
245 | |||||
246 | $context->setView( $view ); |
||||
247 | |||||
248 | return \Aimeos\Admin\JQAdm::create( $context, $aimeos, $resource ); |
||||
0 ignored issues
–
show
It seems like
$resource can also be of type object ; however, parameter $path of Aimeos\Admin\JQAdm::create() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
249 | } |
||||
250 | |||||
251 | |||||
252 | /** |
||||
253 | * Returns the generated HTML code |
||||
254 | * |
||||
255 | * @param string $content Content from admin client |
||||
256 | * @return \Illuminate\Contracts\View\View View for rendering the output |
||||
257 | */ |
||||
258 | protected function getHtml( $content ) |
||||
259 | { |
||||
260 | $site = Route::input( 'site', Input::get( 'site', 'default' ) ); |
||||
261 | return View::make( 'shop::jqadm.index', array( 'content' => $content, 'site' => $site ) ); |
||||
262 | } |
||||
263 | } |
||||
264 |