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