1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2018 |
6
|
|
|
* @package Admin |
7
|
|
|
* @subpackage JQAdm |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Admin\JQAdm\Service; |
12
|
|
|
|
13
|
|
|
sprintf( 'service' ); // for translation |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Default implementation of service JQAdm client. |
18
|
|
|
* |
19
|
|
|
* @package Admin |
20
|
|
|
* @subpackage JQAdm |
21
|
|
|
*/ |
22
|
|
|
class Standard |
23
|
|
|
extends \Aimeos\Admin\JQAdm\Common\Admin\Factory\Base |
24
|
|
|
implements \Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Copies a resource |
28
|
|
|
* |
29
|
|
|
* @return string HTML output |
30
|
|
|
*/ |
31
|
|
|
public function copy() |
32
|
|
|
{ |
33
|
|
|
$view = $this->getView(); |
34
|
|
|
$context = $this->getContext(); |
35
|
|
|
|
36
|
|
|
try |
37
|
|
|
{ |
38
|
|
|
if( ( $id = $view->param( 'id' ) ) === null ) { |
39
|
|
|
throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$manager = \Aimeos\MShop::create( $context, 'service' ); |
43
|
|
|
|
44
|
|
|
$view->item = $manager->getItem( $id, $this->getDomains() ); |
45
|
|
|
$view->itemData = $this->toArray( $view->item, true ); |
46
|
|
|
$view->itemSubparts = $this->getSubClientNames(); |
47
|
|
|
$view->itemProviders = $this->getProviderNames(); |
48
|
|
|
$view->itemDecorators = $this->getDecoratorNames(); |
49
|
|
|
$view->itemAttributes = $this->getConfigAttributes( $view->item ); |
50
|
|
|
$view->itemTypes = $this->getTypeItems(); |
51
|
|
|
$view->itemBody = ''; |
52
|
|
|
|
53
|
|
|
foreach( $this->getSubClients() as $idx => $client ) |
54
|
|
|
{ |
55
|
|
|
$view->tabindex = ++$idx + 1; |
56
|
|
|
$view->itemBody .= $client->copy(); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
60
|
|
|
{ |
61
|
|
|
$error = array( 'service-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
62
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
63
|
|
|
$this->logException( $e ); |
64
|
|
|
} |
65
|
|
|
catch( \Exception $e ) |
66
|
|
|
{ |
67
|
|
|
$error = array( 'service-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() ); |
68
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
69
|
|
|
$this->logException( $e ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $this->render( $view ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Creates a new resource |
78
|
|
|
* |
79
|
|
|
* @return string HTML output |
80
|
|
|
*/ |
81
|
|
|
public function create() |
82
|
|
|
{ |
83
|
|
|
$view = $this->getView(); |
84
|
|
|
$context = $this->getContext(); |
85
|
|
|
|
86
|
|
|
try |
87
|
|
|
{ |
88
|
|
|
$data = $view->param( 'item', [] ); |
89
|
|
|
|
90
|
|
|
if( !isset( $view->item ) ) { |
91
|
|
|
$view->item = \Aimeos\MShop::create( $context, 'service' )->createItem(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$data['service.siteid'] = $view->item->getSiteId(); |
95
|
|
|
|
96
|
|
|
$view->itemSubparts = $this->getSubClientNames(); |
97
|
|
|
$view->itemDecorators = $this->getDecoratorNames(); |
98
|
|
|
$view->itemProviders = $this->getProviderNames(); |
99
|
|
|
$view->itemTypes = $this->getTypeItems(); |
100
|
|
|
$view->itemData = $data; |
101
|
|
|
$view->itemBody = ''; |
102
|
|
|
|
103
|
|
|
foreach( $this->getSubClients() as $idx => $client ) |
104
|
|
|
{ |
105
|
|
|
$view->tabindex = ++$idx + 1; |
106
|
|
|
$view->itemBody .= $client->create(); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
110
|
|
|
{ |
111
|
|
|
$error = array( 'service-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
112
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
113
|
|
|
$this->logException( $e ); |
114
|
|
|
} |
115
|
|
|
catch( \Exception $e ) |
116
|
|
|
{ |
117
|
|
|
$error = array( 'service-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() ); |
118
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
119
|
|
|
$this->logException( $e ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return $this->render( $view ); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Deletes a resource |
128
|
|
|
* |
129
|
|
|
* @return string|null HTML output |
130
|
|
|
*/ |
131
|
|
|
public function delete() |
132
|
|
|
{ |
133
|
|
|
$view = $this->getView(); |
134
|
|
|
$context = $this->getContext(); |
135
|
|
|
|
136
|
|
|
$manager = \Aimeos\MShop::create( $context, 'service' ); |
137
|
|
|
$manager->begin(); |
138
|
|
|
|
139
|
|
|
try |
140
|
|
|
{ |
141
|
|
|
if( ( $ids = $view->param( 'id' ) ) === null ) { |
142
|
|
|
throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$search = $manager->createSearch()->setSlice( 0, count( (array) $ids ) ); |
146
|
|
|
$search->setConditions( $search->compare( '==', 'service.id', $ids ) ); |
147
|
|
|
$items = $manager->searchItems( $search, $this->getDomains() ); |
148
|
|
|
|
149
|
|
|
foreach( $items as $item ) |
150
|
|
|
{ |
151
|
|
|
$view->item = $item; |
152
|
|
|
|
153
|
|
|
foreach( $this->getSubClients() as $client ) { |
154
|
|
|
$client->delete(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$manager->saveItem( $view->item ); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
$manager->deleteItems( array_keys( $items ) ); |
161
|
|
|
$manager->commit(); |
162
|
|
|
|
163
|
|
|
$this->nextAction( $view, 'search', 'service', null, 'delete' ); |
164
|
|
|
return; |
165
|
|
|
} |
166
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
167
|
|
|
{ |
168
|
|
|
$error = array( 'service-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
169
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
170
|
|
|
$this->logException( $e ); |
171
|
|
|
} |
172
|
|
|
catch( \Exception $e ) |
173
|
|
|
{ |
174
|
|
|
$error = array( 'service-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() ); |
175
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
176
|
|
|
$this->logException( $e ); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$manager->rollback(); |
180
|
|
|
|
181
|
|
|
return $this->search(); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Returns a single resource |
187
|
|
|
* |
188
|
|
|
* @return string HTML output |
189
|
|
|
*/ |
190
|
|
|
public function get() |
191
|
|
|
{ |
192
|
|
|
$view = $this->getView(); |
193
|
|
|
$context = $this->getContext(); |
194
|
|
|
|
195
|
|
|
try |
196
|
|
|
{ |
197
|
|
|
if( ( $id = $view->param( 'id' ) ) === null ) { |
198
|
|
|
throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) ); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
$manager = \Aimeos\MShop::create( $context, 'service' ); |
202
|
|
|
|
203
|
|
|
$view->item = $manager->getItem( $id, $this->getDomains() ); |
204
|
|
|
$view->itemData = $this->toArray( $view->item ); |
205
|
|
|
$view->itemSubparts = $this->getSubClientNames(); |
206
|
|
|
$view->itemDecorators = $this->getDecoratorNames(); |
207
|
|
|
$view->itemProviders = $this->getProviderNames(); |
208
|
|
|
$view->itemAttributes = $this->getConfigAttributes( $view->item ); |
209
|
|
|
$view->itemTypes = $this->getTypeItems(); |
210
|
|
|
$view->itemBody = ''; |
211
|
|
|
|
212
|
|
|
foreach( $this->getSubClients() as $idx => $client ) |
213
|
|
|
{ |
214
|
|
|
$view->tabindex = ++$idx + 1; |
215
|
|
|
$view->itemBody .= $client->get(); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
219
|
|
|
{ |
220
|
|
|
$error = array( 'service-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
221
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
222
|
|
|
$this->logException( $e ); |
223
|
|
|
} |
224
|
|
|
catch( \Exception $e ) |
225
|
|
|
{ |
226
|
|
|
$error = array( 'service-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() ); |
227
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
228
|
|
|
$this->logException( $e ); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
return $this->render( $view ); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Saves the data |
237
|
|
|
* |
238
|
|
|
* @return string HTML output |
239
|
|
|
*/ |
240
|
|
|
public function save() |
241
|
|
|
{ |
242
|
|
|
$view = $this->getView(); |
243
|
|
|
$context = $this->getContext(); |
244
|
|
|
|
245
|
|
|
$manager = \Aimeos\MShop::create( $context, 'service' ); |
246
|
|
|
$manager->begin(); |
247
|
|
|
|
248
|
|
|
try |
249
|
|
|
{ |
250
|
|
|
$item = $this->fromArray( $view->param( 'item', [] ) ); |
251
|
|
|
$view->item = $item->getId() ? $item : $manager->saveItem( $item ); |
252
|
|
|
$view->itemBody = ''; |
253
|
|
|
|
254
|
|
|
foreach( $this->getSubClients() as $client ) { |
255
|
|
|
$view->itemBody .= $client->save(); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
$manager->saveItem( clone $view->item ); |
259
|
|
|
$manager->commit(); |
260
|
|
|
|
261
|
|
|
$this->nextAction( $view, $view->param( 'next' ), 'service', $view->item->getId(), 'save' ); |
262
|
|
|
return; |
263
|
|
|
} |
264
|
|
|
catch( \Aimeos\Admin\JQAdm\Exception $e ) |
265
|
|
|
{ |
266
|
|
|
// fall through to create |
267
|
|
|
} |
268
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
269
|
|
|
{ |
270
|
|
|
$error = array( 'service-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
271
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
272
|
|
|
$this->logException( $e ); |
273
|
|
|
} |
274
|
|
|
catch( \Exception $e ) |
275
|
|
|
{ |
276
|
|
|
$error = array( 'service-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() ); |
277
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
278
|
|
|
$this->logException( $e ); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
$manager->rollback(); |
282
|
|
|
|
283
|
|
|
return $this->create(); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Returns a list of resource according to the conditions |
289
|
|
|
* |
290
|
|
|
* @return string HTML output |
291
|
|
|
*/ |
292
|
|
|
public function search() |
293
|
|
|
{ |
294
|
|
|
$view = $this->getView(); |
295
|
|
|
$context = $this->getContext(); |
296
|
|
|
|
297
|
|
|
try |
298
|
|
|
{ |
299
|
|
|
$total = 0; |
300
|
|
|
$params = $this->storeSearchParams( $view->param(), 'service' ); |
301
|
|
|
$manager = \Aimeos\MShop::create( $context, 'service' ); |
302
|
|
|
|
303
|
|
|
$search = $manager->createSearch(); |
304
|
|
|
$search->setSortations( [$search->sort( '+', 'service.type' ), $search->sort( '+', 'service.position' )] ); |
305
|
|
|
$search = $this->initCriteria( $search, $params ); |
306
|
|
|
|
307
|
|
|
$view->items = $manager->searchItems( $search, $this->getDomains(), $total ); |
308
|
|
|
$view->filterAttributes = $manager->getSearchAttributes( true ); |
309
|
|
|
$view->filterOperators = $search->getOperators(); |
310
|
|
|
$view->itemTypes = $this->getTypeItems(); |
311
|
|
|
$view->total = $total; |
312
|
|
|
$view->itemBody = ''; |
313
|
|
|
|
314
|
|
|
foreach( $this->getSubClients() as $client ) { |
315
|
|
|
$view->itemBody .= $client->search(); |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
catch( \Aimeos\MShop\Exception $e ) |
319
|
|
|
{ |
320
|
|
|
$error = array( 'service-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) ); |
321
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
322
|
|
|
$this->logException( $e ); |
323
|
|
|
} |
324
|
|
|
catch( \Exception $e ) |
325
|
|
|
{ |
326
|
|
|
$error = array( 'service-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() ); |
327
|
|
|
$view->errors = $view->get( 'errors', [] ) + $error; |
328
|
|
|
$this->logException( $e ); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** admin/jqadm/service/template-list |
332
|
|
|
* Relative path to the HTML body template for the service list. |
333
|
|
|
* |
334
|
|
|
* The template file contains the HTML code and processing instructions |
335
|
|
|
* to generate the result shown in the body of the frontend. The |
336
|
|
|
* configuration string is the path to the template file relative |
337
|
|
|
* to the templates directory (usually in admin/jqadm/templates). |
338
|
|
|
* |
339
|
|
|
* You can overwrite the template file configuration in extensions and |
340
|
|
|
* provide alternative templates. These alternative templates should be |
341
|
|
|
* named like the default one but with the string "default" replaced by |
342
|
|
|
* an unique name. You may use the name of your project for this. If |
343
|
|
|
* you've implemented an alternative client class as well, "default" |
344
|
|
|
* should be replaced by the name of the new class. |
345
|
|
|
* |
346
|
|
|
* @param string Relative path to the template creating the HTML code |
347
|
|
|
* @since 2016.04 |
348
|
|
|
* @category Developer |
349
|
|
|
*/ |
350
|
|
|
$tplconf = 'admin/jqadm/service/template-list'; |
351
|
|
|
$default = 'service/list-standard'; |
352
|
|
|
|
353
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Returns the sub-client given by its name. |
359
|
|
|
* |
360
|
|
|
* @param string $type Name of the client type |
361
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
362
|
|
|
* @return \Aimeos\Admin\JQAdm\Iface Sub-client object |
363
|
|
|
*/ |
364
|
|
|
public function getSubClient( $type, $name = null ) |
365
|
|
|
{ |
366
|
|
|
/** admin/jqadm/service/decorators/excludes |
367
|
|
|
* Excludes decorators added by the "common" option from the service JQAdm client |
368
|
|
|
* |
369
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
370
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
371
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
372
|
|
|
* modify what is returned to the caller. |
373
|
|
|
* |
374
|
|
|
* This option allows you to remove a decorator added via |
375
|
|
|
* "client/jqadm/common/decorators/default" before they are wrapped |
376
|
|
|
* around the JQAdm client. |
377
|
|
|
* |
378
|
|
|
* admin/jqadm/service/decorators/excludes = array( 'decorator1' ) |
379
|
|
|
* |
380
|
|
|
* This would remove the decorator named "decorator1" from the list of |
381
|
|
|
* common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via |
382
|
|
|
* "client/jqadm/common/decorators/default" to the JQAdm client. |
383
|
|
|
* |
384
|
|
|
* @param array List of decorator names |
385
|
|
|
* @since 2017.10 |
386
|
|
|
* @category Developer |
387
|
|
|
* @see admin/jqadm/common/decorators/default |
388
|
|
|
* @see admin/jqadm/service/decorators/global |
389
|
|
|
* @see admin/jqadm/service/decorators/local |
390
|
|
|
*/ |
391
|
|
|
|
392
|
|
|
/** admin/jqadm/service/decorators/global |
393
|
|
|
* Adds a list of globally available decorators only to the service JQAdm client |
394
|
|
|
* |
395
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
396
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
397
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
398
|
|
|
* modify what is returned to the caller. |
399
|
|
|
* |
400
|
|
|
* This option allows you to wrap global decorators |
401
|
|
|
* ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client. |
402
|
|
|
* |
403
|
|
|
* admin/jqadm/service/decorators/global = array( 'decorator1' ) |
404
|
|
|
* |
405
|
|
|
* This would add the decorator named "decorator1" defined by |
406
|
|
|
* "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client. |
407
|
|
|
* |
408
|
|
|
* @param array List of decorator names |
409
|
|
|
* @since 2017.10 |
410
|
|
|
* @category Developer |
411
|
|
|
* @see admin/jqadm/common/decorators/default |
412
|
|
|
* @see admin/jqadm/service/decorators/excludes |
413
|
|
|
* @see admin/jqadm/service/decorators/local |
414
|
|
|
*/ |
415
|
|
|
|
416
|
|
|
/** admin/jqadm/service/decorators/local |
417
|
|
|
* Adds a list of local decorators only to the service JQAdm client |
418
|
|
|
* |
419
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
420
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
421
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
422
|
|
|
* modify what is returned to the caller. |
423
|
|
|
* |
424
|
|
|
* This option allows you to wrap local decorators |
425
|
|
|
* ("\Aimeos\Admin\JQAdm\Service\Decorator\*") around the JQAdm client. |
426
|
|
|
* |
427
|
|
|
* admin/jqadm/service/decorators/local = array( 'decorator2' ) |
428
|
|
|
* |
429
|
|
|
* This would add the decorator named "decorator2" defined by |
430
|
|
|
* "\Aimeos\Admin\JQAdm\Service\Decorator\Decorator2" only to the JQAdm client. |
431
|
|
|
* |
432
|
|
|
* @param array List of decorator names |
433
|
|
|
* @since 2017.10 |
434
|
|
|
* @category Developer |
435
|
|
|
* @see admin/jqadm/common/decorators/default |
436
|
|
|
* @see admin/jqadm/service/decorators/excludes |
437
|
|
|
* @see admin/jqadm/service/decorators/global |
438
|
|
|
*/ |
439
|
|
|
return $this->createSubClient( 'service/' . $type, $name ); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* Returns the backend configuration attributes of the provider and decorators |
445
|
|
|
* |
446
|
|
|
* @param \Aimeos\MShop\Service\Item\Iface $item Service item incl. provider/decorator property |
447
|
|
|
* @return \Aimeos\MW\Common\Critera\Attribute\Iface[] List of configuration attributes |
448
|
|
|
*/ |
449
|
|
|
public function getConfigAttributes( \Aimeos\MShop\Service\Item\Iface $item ) |
450
|
|
|
{ |
451
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'service' ); |
452
|
|
|
|
453
|
|
|
try { |
454
|
|
|
return $manager->getProvider( $item, $item->getType() )->getConfigBE(); |
455
|
|
|
} catch( \Aimeos\MShop\Exception $e ) { |
456
|
|
|
return []; |
457
|
|
|
} |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
|
461
|
|
|
/** |
462
|
|
|
* Returns the domain names whose items should be fetched too |
463
|
|
|
* |
464
|
|
|
* @return string[] List of domain names |
465
|
|
|
*/ |
466
|
|
|
protected function getDomains() |
467
|
|
|
{ |
468
|
|
|
/** admin/jqadm/service/domains |
469
|
|
|
* List of domain items that should be fetched along with the service |
470
|
|
|
* |
471
|
|
|
* If you need to display additional content, you can configure your own |
472
|
|
|
* list of domains (attribute, media, price, service, text, etc. are |
473
|
|
|
* domains) whose items are fetched from the storage. |
474
|
|
|
* |
475
|
|
|
* @param array List of domain names |
476
|
|
|
* @since 2017.10 |
477
|
|
|
* @category Developer |
478
|
|
|
*/ |
479
|
|
|
$domains = array( 'media', 'price', 'text' ); |
480
|
|
|
|
481
|
|
|
return $this->getContext()->getConfig()->get( 'admin/jqadm/service/domains', $domains ); |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
|
485
|
|
|
/** |
486
|
|
|
* Returns the names of the available service decorators |
487
|
|
|
* |
488
|
|
|
* @return string[] List of decorator class names |
489
|
|
|
*/ |
490
|
|
|
protected function getDecoratorNames() |
491
|
|
|
{ |
492
|
|
|
$ds = DIRECTORY_SEPARATOR; |
493
|
|
|
return $this->getClassNames( 'MShop' . $ds . 'Service' . $ds . 'Provider' . $ds . 'Decorator' ); |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Returns the names of the available service providers |
499
|
|
|
* |
500
|
|
|
* @return string[] List of provider class names |
501
|
|
|
*/ |
502
|
|
|
protected function getProviderNames() |
503
|
|
|
{ |
504
|
|
|
$ds = DIRECTORY_SEPARATOR; |
505
|
|
|
return [ |
506
|
|
|
'delivery' => $this->getClassNames( 'MShop' . $ds . 'Service' . $ds . 'Provider' . $ds . 'Delivery' ), |
507
|
|
|
'payment' => $this->getClassNames( 'MShop' . $ds . 'Service' . $ds . 'Provider' . $ds . 'Payment' ), |
508
|
|
|
]; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Returns the list of sub-client names configured for the client. |
514
|
|
|
* |
515
|
|
|
* @return array List of JQAdm client names |
516
|
|
|
*/ |
517
|
|
|
protected function getSubClientNames() |
518
|
|
|
{ |
519
|
|
|
/** admin/jqadm/service/standard/subparts |
520
|
|
|
* List of JQAdm sub-clients rendered within the service section |
521
|
|
|
* |
522
|
|
|
* The output of the frontend is composed of the code generated by the JQAdm |
523
|
|
|
* clients. Each JQAdm client can consist of serveral (or none) sub-clients |
524
|
|
|
* that are responsible for rendering certain sub-parts of the output. The |
525
|
|
|
* sub-clients can contain JQAdm clients themselves and therefore a |
526
|
|
|
* hierarchical tree of JQAdm clients is composed. Each JQAdm client creates |
527
|
|
|
* the output that is placed inside the container of its parent. |
528
|
|
|
* |
529
|
|
|
* At first, always the JQAdm code generated by the parent is printed, then |
530
|
|
|
* the JQAdm code of its sub-clients. The order of the JQAdm sub-clients |
531
|
|
|
* determines the order of the output of these sub-clients inside the parent |
532
|
|
|
* container. If the configured list of clients is |
533
|
|
|
* |
534
|
|
|
* array( "subclient1", "subclient2" ) |
535
|
|
|
* |
536
|
|
|
* you can easily change the order of the output by reordering the subparts: |
537
|
|
|
* |
538
|
|
|
* admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" ) |
539
|
|
|
* |
540
|
|
|
* You can also remove one or more parts if they shouldn't be rendered: |
541
|
|
|
* |
542
|
|
|
* admin/jqadm/<clients>/subparts = array( "subclient1" ) |
543
|
|
|
* |
544
|
|
|
* As the clients only generates structural JQAdm, the layout defined via CSS |
545
|
|
|
* should support adding, removing or reordering content by a fluid like |
546
|
|
|
* design. |
547
|
|
|
* |
548
|
|
|
* @param array List of sub-client names |
549
|
|
|
* @since 2017.10 |
550
|
|
|
* @category Developer |
551
|
|
|
*/ |
552
|
|
|
return $this->getContext()->getConfig()->get( 'admin/jqadm/service/standard/subparts', [] ); |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
|
556
|
|
|
/** |
557
|
|
|
* Returns the available service type items |
558
|
|
|
* |
559
|
|
|
* @return array List of item implementing \Aimeos\MShop\Common\Type\Iface |
560
|
|
|
*/ |
561
|
|
|
protected function getTypeItems() |
562
|
|
|
{ |
563
|
|
|
$typeManager = \Aimeos\MShop::create( $this->getContext(), 'service/type' ); |
564
|
|
|
|
565
|
|
|
$search = $typeManager->createSearch( true )->setSlice( 0, 10000 ); |
566
|
|
|
$search->setSortations( [$search->sort( '+', 'service.type.position' )] ); |
567
|
|
|
|
568
|
|
|
return $this->map( $typeManager->searchItems( $search ) ); |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
|
572
|
|
|
/** |
573
|
|
|
* Creates new and updates existing items using the data array |
574
|
|
|
* |
575
|
|
|
* @param array $data Data array |
576
|
|
|
* @return \Aimeos\MShop\Service\Item\Iface New service item object |
577
|
|
|
*/ |
578
|
|
|
protected function fromArray( array $data ) |
579
|
|
|
{ |
580
|
|
|
$conf = []; |
581
|
|
|
|
582
|
|
|
if( isset( $data['config']['key'] ) ) |
583
|
|
|
{ |
584
|
|
|
foreach( (array) $data['config']['key'] as $idx => $key ) |
585
|
|
|
{ |
586
|
|
|
if( trim( $key ) !== '' && isset( $data['config']['val'][$idx] ) ) |
587
|
|
|
{ |
588
|
|
|
if( ( $val = json_decode( $data['config']['val'][$idx] ) ) === null ) { |
589
|
|
|
$conf[$key] = $data['config']['val'][$idx]; |
590
|
|
|
} else { |
591
|
|
|
$conf[$key] = $val; |
592
|
|
|
} |
593
|
|
|
} |
594
|
|
|
} |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'service' ); |
598
|
|
|
|
599
|
|
|
if( isset( $data['service.id'] ) && $data['service.id'] != '' ) { |
600
|
|
|
$item = $manager->getItem( $data['service.id'], $this->getDomains() ); |
601
|
|
|
} else { |
602
|
|
|
$item = $manager->createItem(); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
$item->fromArray( $data, true ); |
606
|
|
|
$item->setConfig( $conf ); |
|
|
|
|
607
|
|
|
|
608
|
|
|
return $item; |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
|
612
|
|
|
/** |
613
|
|
|
* Constructs the data array for the view from the given item |
614
|
|
|
* |
615
|
|
|
* @param \Aimeos\MShop\Service\Item\Iface $item Service item object |
616
|
|
|
* @return string[] Multi-dimensional associative list of item data |
617
|
|
|
*/ |
618
|
|
|
protected function toArray( \Aimeos\MShop\Service\Item\Iface $item, $copy = false ) |
619
|
|
|
{ |
620
|
|
|
$config = $item->getConfig(); |
621
|
|
|
$data = $item->toArray( true ); |
622
|
|
|
$data['config'] = []; |
623
|
|
|
|
624
|
|
|
if( $copy === true ) |
625
|
|
|
{ |
626
|
|
|
$data['service.siteid'] = $this->getContext()->getLocale()->getSiteId(); |
627
|
|
|
$data['service.code'] = $data['service.code'] . '_copy'; |
628
|
|
|
$data['service.id'] = ''; |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
ksort( $config ); |
632
|
|
|
|
633
|
|
|
foreach( $config as $key => $value ) |
634
|
|
|
{ |
635
|
|
|
$data['config']['key'][] = $key; |
636
|
|
|
$data['config']['val'][] = $value; |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
return $data; |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
|
643
|
|
|
/** |
644
|
|
|
* Returns the rendered template including the view data |
645
|
|
|
* |
646
|
|
|
* @param \Aimeos\MW\View\Iface $view View object with data assigned |
647
|
|
|
* @return string HTML output |
648
|
|
|
*/ |
649
|
|
|
protected function render( \Aimeos\MW\View\Iface $view ) |
650
|
|
|
{ |
651
|
|
|
/** admin/jqadm/service/template-item |
652
|
|
|
* Relative path to the HTML body template for the service item. |
653
|
|
|
* |
654
|
|
|
* The template file contains the HTML code and processing instructions |
655
|
|
|
* to generate the result shown in the body of the frontend. The |
656
|
|
|
* configuration string is the path to the template file relative |
657
|
|
|
* to the templates directory (usually in admin/jqadm/templates). |
658
|
|
|
* |
659
|
|
|
* You can overwrite the template file configuration in extensions and |
660
|
|
|
* provide alternative templates. These alternative templates should be |
661
|
|
|
* named like the default one but with the string "default" replaced by |
662
|
|
|
* an unique name. You may use the name of your project for this. If |
663
|
|
|
* you've implemented an alternative client class as well, "default" |
664
|
|
|
* should be replaced by the name of the new class. |
665
|
|
|
* |
666
|
|
|
* @param string Relative path to the template creating the HTML code |
667
|
|
|
* @since 2016.04 |
668
|
|
|
* @category Developer |
669
|
|
|
*/ |
670
|
|
|
$tplconf = 'admin/jqadm/service/template-item'; |
671
|
|
|
$default = 'service/item-standard'; |
672
|
|
|
|
673
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
674
|
|
|
} |
675
|
|
|
} |
676
|
|
|
|