1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015 |
6
|
|
|
* @package laravel-package |
7
|
|
|
* @subpackage Controller |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Shop\Controller; |
12
|
|
|
|
13
|
|
|
use Illuminate\Routing\Controller; |
14
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Aimeos controller for the JQuery admin interface |
19
|
|
|
* |
20
|
|
|
* @package laravel-package |
21
|
|
|
* @subpackage Controller |
22
|
|
|
*/ |
23
|
|
|
class JqadmController extends Controller |
24
|
|
|
{ |
25
|
|
|
use AuthorizesRequests; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns the HTML code for a copy of a resource object |
30
|
|
|
* |
31
|
|
|
* @param string Resource location, e.g. "product" |
32
|
|
|
* @param string $sitecode Unique site code |
|
|
|
|
33
|
|
|
* @param integer $id Unique resource ID |
34
|
|
|
* @return string Generated output |
35
|
|
|
*/ |
36
|
|
|
public function copyAction( $site = 'default', $resource, $id ) |
37
|
|
|
{ |
38
|
|
|
if( config( 'shop.authorize', true ) ) { |
39
|
|
|
$this->authorize( 'admin' ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$cntl = $this->createClient( $site, $resource ); |
43
|
|
|
$content = $cntl->copy( $id ); |
|
|
|
|
44
|
|
|
|
45
|
|
|
return \View::make('shop::admin.jqadm', array( 'content' => $content ) ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Returns the HTML code for a new resource object |
51
|
|
|
* |
52
|
|
|
* @param string Resource location, e.g. "product" |
53
|
|
|
* @param string $sitecode Unique site code |
|
|
|
|
54
|
|
|
* @return string Generated output |
55
|
|
|
*/ |
56
|
|
|
public function createAction( $site = 'default', $resource ) |
57
|
|
|
{ |
58
|
|
|
if( config( 'shop.authorize', true ) ) { |
59
|
|
|
$this->authorize( 'admin' ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$cntl = $this->createClient( $site, $resource ); |
63
|
|
|
$content = $cntl->create( $id ); |
|
|
|
|
64
|
|
|
|
65
|
|
|
return \View::make('shop::admin.jqadm', array( 'content' => $content ) ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Deletes the resource object or a list of resource objects |
71
|
|
|
* |
72
|
|
|
* @param string Resource location, e.g. "product" |
73
|
|
|
* @param string $sitecode Unique site code |
|
|
|
|
74
|
|
|
* @param integer $id Unique resource ID |
75
|
|
|
* @return string Generated output |
76
|
|
|
*/ |
77
|
|
View Code Duplication |
public function deleteAction( $site = 'default', $resource, $id ) |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
if( config( 'shop.authorize', true ) ) { |
80
|
|
|
$this->authorize( 'admin' ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$cntl = $this->createClient( $site, $resource ); |
84
|
|
|
$content = ( $cntl->delete( $id ) ? : $cntl->search() ); |
|
|
|
|
85
|
|
|
|
86
|
|
|
return \View::make('shop::admin.jqadm', array( 'content' => $content ) ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Returns the HTML code for the requested resource object |
92
|
|
|
* |
93
|
|
|
* @param string Resource location, e.g. "product" |
94
|
|
|
* @param string $sitecode Unique site code |
|
|
|
|
95
|
|
|
* @param integer $id Unique resource ID |
96
|
|
|
* @return string Generated output |
97
|
|
|
*/ |
98
|
|
|
public function getAction( $site = 'default', $resource, $id ) |
99
|
|
|
{ |
100
|
|
|
if( config( 'shop.authorize', true ) ) { |
101
|
|
|
$this->authorize( 'admin' ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$cntl = $this->createClient( $site, $resource ); |
105
|
|
|
$content = $cntl->get( $id ); |
|
|
|
|
106
|
|
|
|
107
|
|
|
return \View::make('shop::admin.jqadm', array( 'content' => $content ) ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Saves a new resource object |
113
|
|
|
* |
114
|
|
|
* @param string Resource location, e.g. "product" |
115
|
|
|
* @param string $sitecode Unique site code |
|
|
|
|
116
|
|
|
* @return string Generated output |
117
|
|
|
*/ |
118
|
|
View Code Duplication |
public function saveAction( $site = 'default', $resource ) |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
if( config( 'shop.authorize', true ) ) { |
121
|
|
|
$this->authorize( 'admin' ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$cntl = $this->createClient( $site, $resource ); |
125
|
|
|
$content = ( $cntl->save() ? : $cntl->search() ); |
|
|
|
|
126
|
|
|
|
127
|
|
|
return \View::make('shop::admin.jqadm', array( 'content' => $content ) ); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Returns the HTML code for a list of resource objects |
133
|
|
|
* |
134
|
|
|
* @param string Resource location, e.g. "product" |
135
|
|
|
* @param string $sitecode Unique site code |
|
|
|
|
136
|
|
|
* @return string Generated output |
137
|
|
|
*/ |
138
|
|
|
public function searchAction( $site = 'default', $resource ) |
139
|
|
|
{ |
140
|
|
|
if( config( 'shop.authorize', true ) ) { |
141
|
|
|
$this->authorize( 'admin' ); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
$cntl = $this->createClient( $site, $resource ); |
145
|
|
|
$content = $cntl->search(); |
|
|
|
|
146
|
|
|
|
147
|
|
|
return \View::make('shop::admin.jqadm', array( 'content' => $content ) ); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Returns the resource controller |
153
|
|
|
* |
154
|
|
|
* @param string $sitecode Unique site code |
155
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context item |
156
|
|
|
*/ |
157
|
|
View Code Duplication |
protected function createClient( $sitecode, $resource ) |
|
|
|
|
158
|
|
|
{ |
159
|
|
|
$lang = \Input::get( 'lang', config( 'app.locale', 'en' ) ); |
160
|
|
|
|
161
|
|
|
$aimeos = app( '\Aimeos\Shop\Base\Aimeos' )->get(); |
162
|
|
|
$templatePaths = $aimeos->getCustomPaths( 'controller/jqadm/templates' ); |
163
|
|
|
|
164
|
|
|
$context = app( '\Aimeos\Shop\Base\Context' )->get( false ); |
165
|
|
|
$context = $this->setLocale( $context, $sitecode, $lang ); |
166
|
|
|
|
167
|
|
|
$view = app( '\Aimeos\Shop\Base\View' )->create( $context->getConfig(), $templatePaths, $lang ); |
168
|
|
|
$context->setView( $view ); |
169
|
|
|
|
170
|
|
|
return \Aimeos\Client\JQAdm\Factory::createClient( $context, $templatePaths, $resource ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Sets the locale item in the given context |
176
|
|
|
* |
177
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
178
|
|
|
* @param string $sitecode Unique site code |
179
|
|
|
* @param string $lang ISO language code, e.g. "en" or "en_GB" |
180
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
181
|
|
|
*/ |
182
|
|
View Code Duplication |
protected function setLocale( \Aimeos\MShop\Context\Item\Iface $context, $sitecode, $lang ) |
|
|
|
|
183
|
|
|
{ |
184
|
|
|
$localeManager = \Aimeos\MShop\Factory::createManager( $context, 'locale' ); |
185
|
|
|
|
186
|
|
|
try |
187
|
|
|
{ |
188
|
|
|
$localeItem = $localeManager->bootstrap( $sitecode, '', '', false ); |
189
|
|
|
$localeItem->setLanguageId( null ); |
190
|
|
|
$localeItem->setCurrencyId( null ); |
191
|
|
|
} |
192
|
|
|
catch( \Aimeos\MShop\Locale\Exception $e ) |
193
|
|
|
{ |
194
|
|
|
$localeItem = $localeManager->createItem(); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
$context->setLocale( $localeItem ); |
198
|
|
|
$context->setI18n( app('\Aimeos\Shop\Base\I18n')->get( array( $lang ) ) ); |
199
|
|
|
|
200
|
|
|
return $context; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.