Passed
Push — master ( b95f84...8de0c9 )
by Aimeos
04:01
created

Standard   B

Complexity

Total Complexity 52

Size/Duplication

Total Lines 617
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 209
dl 0
loc 617
rs 7.44
c 0
b 0
f 0
wmc 52

13 Methods

Rating   Name   Duplication   Size   Complexity  
B create() 0 45 6
B copy() 0 46 6
A checkSite() 0 7 3
B get() 0 46 6
A search() 0 66 5
A getUserSiteId() 0 6 1
A getSubClient() 0 76 1
A getSubClientNames() 0 36 1
B delete() 0 58 7
B save() 0 46 6
A fromArray() 0 32 6
A toArray() 0 16 3
A render() 0 25 1

How to fix   Complexity   

Complex Class

Complex classes like Standard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Standard, and based on these observations, apply Extract Interface, too.

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\Locale\Site;
12
13
sprintf( 'locale/site' ); // for translation
14
15
16
/**
17
 * Default implementation of locale site 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
			$this->checkSite( $view->access( 'super' ), $id );
43
44
			$manager = \Aimeos\MShop::create( $context, 'locale/site' );
45
			$view->item = $manager->getItem( $id );
46
47
			$view->itemData = $this->toArray( $view->item, true );
48
			$view->itemSubparts = $this->getSubClientNames();
49
			$view->itemBody = '';
50
51
			foreach( $this->getSubClients() as $idx => $client )
52
			{
53
				$view->tabindex = ++$idx + 1;
54
				$view->itemBody .= $client->copy();
55
			}
56
		}
57
		catch( \Aimeos\Admin\JQAdm\Exception $e )
58
		{
59
			$error = array( 'locale-site-item' => $context->getI18n()->dt( 'admin', $e->getMessage() ) );
60
			$view->errors = $view->get( 'errors', [] ) + $error;
61
			$this->logException( $e );
62
		}
63
		catch( \Aimeos\MShop\Exception $e )
64
		{
65
			$error = array( 'locale-site-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
66
			$view->errors = $view->get( 'errors', [] ) + $error;
67
			$this->logException( $e );
68
		}
69
		catch( \Exception $e )
70
		{
71
			$error = array( 'locale-site-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
72
			$view->errors = $view->get( 'errors', [] ) + $error;
73
			$this->logException( $e );
74
		}
75
76
		return $this->render( $view );
77
	}
78
79
80
	/**
81
	 * Creates a new resource
82
	 *
83
	 * @return string HTML output
84
	 */
85
	public function create()
86
	{
87
		$view = $this->getView();
88
		$context = $this->getContext();
89
90
		try
91
		{
92
			$this->checkSite( $view->access( 'super' ) );
93
94
			$data = $view->param( 'item', [] );
95
96
			if( !isset( $view->item ) ) {
97
				$view->item = \Aimeos\MShop::create( $context, 'locale/site' )->createItem();
98
			}
99
100
			$view->itemSubparts = $this->getSubClientNames();
101
			$view->itemData = $data;
102
			$view->itemBody = '';
103
104
			foreach( $this->getSubClients() as $idx => $client )
105
			{
106
				$view->tabindex = ++$idx + 1;
107
				$view->itemBody .= $client->create();
108
			}
109
		}
110
		catch( \Aimeos\Admin\JQAdm\Exception $e )
111
		{
112
			$error = array( 'locale-site-item' => $context->getI18n()->dt( 'admin', $e->getMessage() ) );
113
			$view->errors = $view->get( 'errors', [] ) + $error;
114
			$this->logException( $e );
115
		}
116
		catch( \Aimeos\MShop\Exception $e )
117
		{
118
			$error = array( 'locale-site-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
119
			$view->errors = $view->get( 'errors', [] ) + $error;
120
			$this->logException( $e );
121
		}
122
		catch( \Exception $e )
123
		{
124
			$error = array( 'locale-site-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
125
			$view->errors = $view->get( 'errors', [] ) + $error;
126
			$this->logException( $e );
127
		}
128
129
		return $this->render( $view );
130
	}
131
132
133
	/**
134
	 * Deletes a resource
135
	 *
136
	 * @return string|null HTML output
137
	 */
138
	public function delete()
139
	{
140
		$view = $this->getView();
141
		$context = $this->getContext();
142
143
		$manager = \Aimeos\MShop::create( $context, 'locale/site' );
144
		$manager->begin();
145
146
		try
147
		{
148
			if( ( $ids = $view->param( 'id' ) ) === null ) {
149
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) );
150
			}
151
152
			$search = $manager->createSearch()->setSlice( 0, count( (array) $ids ) );
153
			$search->setConditions( $search->compare( '==', 'locale.site.id', $ids ) );
154
			$items = $manager->searchItems( $search );
155
156
			foreach( $items as $id => $item )
157
			{
158
				$this->checkSite( $view->access( 'super' ), $id );
159
				$view->item = $item;
160
161
				foreach( $this->getSubClients() as $client ) {
162
					$client->delete();
163
				}
164
165
				$manager->saveItem( $view->item );
0 ignored issues
show
Bug introduced by
The method saveItem() does not exist on Aimeos\MShop\Common\Manager\Iface. Did you maybe mean saveItems()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

165
				$manager->/** @scrutinizer ignore-call */ 
166
              saveItem( $view->item );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
166
			}
167
168
			$manager->deleteItems( array_keys( $items ) );
169
			$manager->commit();
170
171
			$this->nextAction( $view, 'search', 'locale/site', null, 'delete' );
172
			return;
173
		}
174
		catch( \Aimeos\Admin\JQAdm\Exception $e )
175
		{
176
			$error = array( 'locale-site-item' => $context->getI18n()->dt( 'admin', $e->getMessage() ) );
177
			$view->errors = $view->get( 'errors', [] ) + $error;
178
			$this->logException( $e );
179
		}
180
		catch( \Aimeos\MShop\Exception $e )
181
		{
182
			$error = array( 'locale-site-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
183
			$view->errors = $view->get( 'errors', [] ) + $error;
184
			$this->logException( $e );
185
		}
186
		catch( \Exception $e )
187
		{
188
			$error = array( 'locale-site-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
189
			$view->errors = $view->get( 'errors', [] ) + $error;
190
			$this->logException( $e );
191
		}
192
193
		$manager->rollback();
194
195
		return $this->search();
196
	}
197
198
199
	/**
200
	 * Returns a single resource
201
	 *
202
	 * @return string HTML output
203
	 */
204
	public function get()
205
	{
206
		$view = $this->getView();
207
		$context = $this->getContext();
208
209
		try
210
		{
211
			if( ( $id = $view->param( 'id' ) ) === null ) {
212
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) );
213
			}
214
215
			$this->checkSite( $view->access( 'super' ), $id );
216
217
			$manager = \Aimeos\MShop::create( $context, 'locale/site' );
218
219
			$view->item = $manager->getItem( $id );
220
			$view->itemSubparts = $this->getSubClientNames();
221
			$view->itemData = $this->toArray( $view->item );
222
			$view->itemBody = '';
223
224
			foreach( $this->getSubClients() as $idx => $client )
225
			{
226
				$view->tabindex = ++$idx + 1;
227
				$view->itemBody .= $client->get();
228
			}
229
		}
230
		catch( \Aimeos\Admin\JQAdm\Exception $e )
231
		{
232
			$error = array( 'locale-site-item' => $context->getI18n()->dt( 'admin', $e->getMessage() ) );
233
			$view->errors = $view->get( 'errors', [] ) + $error;
234
			$this->logException( $e );
235
		}
236
		catch( \Aimeos\MShop\Exception $e )
237
		{
238
			$error = array( 'locale-site-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
239
			$view->errors = $view->get( 'errors', [] ) + $error;
240
			$this->logException( $e );
241
		}
242
		catch( \Exception $e )
243
		{
244
			$error = array( 'locale-site-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
245
			$view->errors = $view->get( 'errors', [] ) + $error;
246
			$this->logException( $e );
247
		}
248
249
		return $this->render( $view );
250
	}
251
252
253
	/**
254
	 * Saves the data
255
	 *
256
	 * @return string HTML output
257
	 */
258
	public function save()
259
	{
260
		$view = $this->getView();
261
		$context = $this->getContext();
262
263
		$manager = \Aimeos\MShop::create( $context, 'locale/site' );
264
		$manager->begin();
265
266
		try
267
		{
268
			$item = $this->fromArray( $view->param( 'item', [] ), $view->access( 'super' ) );
269
			$view->item = $item->getId() ? $item : $manager->saveItem( $item );
270
			$view->itemBody = '';
271
272
			foreach( $this->getSubClients() as $client ) {
273
				$view->itemBody .= $client->save();
274
			}
275
276
			$manager->saveItem( clone $view->item );
277
			$manager->commit();
278
279
			$this->nextAction( $view, $view->param( 'next' ), 'locale/site', $view->item->getId(), 'save' );
280
			return;
281
		}
282
		catch( \Aimeos\Admin\JQAdm\Exception $e )
283
		{
284
			$error = array( 'locale-site-item' => $context->getI18n()->dt( 'admin', $e->getMessage() ) );
285
			$view->errors = $view->get( 'errors', [] ) + $error;
286
			$this->logException( $e );
287
		}
288
		catch( \Aimeos\MShop\Exception $e )
289
		{
290
			$error = array( 'locale-site-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
291
			$view->errors = $view->get( 'errors', [] ) + $error;
292
			$this->logException( $e );
293
		}
294
		catch( \Exception $e )
295
		{
296
			$error = array( 'locale-site-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
297
			$view->errors = $view->get( 'errors', [] ) + $error;
298
			$this->logException( $e );
299
		}
300
301
		$manager->rollback();
302
303
		return $this->create();
304
	}
305
306
307
	/**
308
	 * Returns a list of resource according to the conditions
309
	 *
310
	 * @return string HTML output
311
	 */
312
	public function search()
313
	{
314
		$view = $this->getView();
315
		$context = $this->getContext();
316
317
		try
318
		{
319
			$total = 0;
320
			$params = $this->storeSearchParams( $view->param(), 'locale/site' );
321
			$manager = \Aimeos\MShop::create( $context, 'locale/site' );
322
			$search = $this->initCriteria( $manager->createSearch(), $params );
323
324
			if( $view->access( 'super' ) === false )
325
			{
326
				$search->setConditions( $search->combine( '&&', [
327
					$search->compare( '==', 'locale.site.id', $this->getUserSiteId() ),
328
					$search->getConditions(),
329
				] ) );
330
			}
331
332
			$view->items = $manager->searchItems( $search, [], $total );
333
			$view->filterAttributes = $manager->getSearchAttributes( true );
334
			$view->filterOperators = $search->getOperators();
335
			$view->total = $total;
336
			$view->itemBody = '';
337
338
			foreach( $this->getSubClients() as $client ) {
339
				$view->itemBody .= $client->search();
340
			}
341
		}
342
		catch( \Aimeos\MShop\Exception $e )
343
		{
344
			$error = array( 'locale-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
345
			$view->errors = $view->get( 'errors', [] ) + $error;
346
			$this->logException( $e );
347
		}
348
		catch( \Exception $e )
349
		{
350
			$error = array( 'locale-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
351
			$view->errors = $view->get( 'errors', [] ) + $error;
352
			$this->logException( $e );
353
		}
354
355
		/** admin/jqadm/locale/site/template-list
356
		 * Relative path to the HTML body template for the locale list.
357
		 *
358
		 * The template file contains the HTML code and processing instructions
359
		 * to generate the result shown in the body of the frontend. The
360
		 * configuration string is the path to the template file relative
361
		 * to the templates directory (usually in admin/jqadm/templates).
362
		 *
363
		 * You can overwrite the template file configuration in extensions and
364
		 * provide alternative templates. These alternative templates should be
365
		 * named like the default one but with the string "default" replaced by
366
		 * an unique name. You may use the name of your project for this. If
367
		 * you've implemented an alternative client class as well, "default"
368
		 * should be replaced by the name of the new class.
369
		 *
370
		 * @param string Relative path to the template creating the HTML code
371
		 * @since 2016.04
372
		 * @category Developer
373
		 */
374
		$tplconf = 'admin/jqadm/locale/site/template-list';
375
		$default = 'locale/site/list-standard';
376
377
		return $view->render( $view->config( $tplconf, $default ) );
378
	}
379
380
381
	/**
382
	 * Returns the sub-client given by its name.
383
	 *
384
	 * @param string $type Name of the client type
385
	 * @param string|null $name Name of the sub-client (Default if null)
386
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
387
	 */
388
	public function getSubClient( $type, $name = null )
389
	{
390
		/** admin/jqadm/locale/site/decorators/excludes
391
		 * Excludes decorators added by the "common" option from the locale JQAdm client
392
		 *
393
		 * Decorators extend the functionality of a class by adding new aspects
394
		 * (e.g. log what is currently done), executing the methods of the underlying
395
		 * class only in certain conditions (e.g. only for logged in users) or
396
		 * modify what is returned to the caller.
397
		 *
398
		 * This option allows you to remove a decorator added via
399
		 * "client/jqadm/common/decorators/default" before they are wrapped
400
		 * around the JQAdm client.
401
		 *
402
		 *  admin/jqadm/locale/site/decorators/excludes = array( 'decorator1' )
403
		 *
404
		 * This would remove the decorator named "decorator1" from the list of
405
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
406
		 * "client/jqadm/common/decorators/default" 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/locale/site/decorators/global
413
		 * @see admin/jqadm/locale/site/decorators/local
414
		 */
415
416
		/** admin/jqadm/locale/site/decorators/global
417
		 * Adds a list of globally available decorators only to the locale 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 global decorators
425
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
426
		 *
427
		 *  admin/jqadm/locale/site/decorators/global = array( 'decorator1' )
428
		 *
429
		 * This would add the decorator named "decorator1" defined by
430
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" 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/locale/site/decorators/excludes
437
		 * @see admin/jqadm/locale/site/decorators/local
438
		 */
439
440
		/** admin/jqadm/locale/site/decorators/local
441
		 * Adds a list of local decorators only to the locale JQAdm client
442
		 *
443
		 * Decorators extend the functionality of a class by adding new aspects
444
		 * (e.g. log what is currently done), executing the methods of the underlying
445
		 * class only in certain conditions (e.g. only for logged in users) or
446
		 * modify what is returned to the caller.
447
		 *
448
		 * This option allows you to wrap local decorators
449
		 * ("\Aimeos\Admin\JQAdm\Locale\Site\Decorator\*") around the JQAdm client.
450
		 *
451
		 *  admin/jqadm/locale/site/decorators/local = array( 'decorator2' )
452
		 *
453
		 * This would add the decorator named "decorator2" defined by
454
		 * "\Aimeos\Admin\JQAdm\Locale\Site\Decorator\Decorator2" only to the JQAdm client.
455
		 *
456
		 * @param array List of decorator names
457
		 * @since 2017.10
458
		 * @category Developer
459
		 * @see admin/jqadm/common/decorators/default
460
		 * @see admin/jqadm/locale/site/decorators/excludes
461
		 * @see admin/jqadm/locale/site/decorators/global
462
		 */
463
		return $this->createSubClient( 'locale/site' . $type, $name );
464
	}
465
466
467
	/**
468
	 * Checks if the user is allowed to access the site item
469
	 *
470
	 * @param boolean $super True if user is a super user
471
	 * @param string $id ID of the site to access
472
	 * @throws \Aimeos\Admin\JQAdm\Exception If user isn't allowed to access the site
473
	 */
474
	protected function checkSite( $super, $id = null )
475
	{
476
		if( $super === true || (string) $this->getUserSiteId() === (string) $id ) {
477
			return;
478
		}
479
480
		throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Permission denied' ) );
481
	}
482
483
484
	/**
485
	 * Returns the site ID of the current user
486
	 *
487
	 * @return string|null Site ID of the current user
488
	 */
489
	protected function getUserSiteId()
490
	{
491
		$context = $this->getContext();
492
		$manager = \Aimeos\MShop::create( $context, 'customer' );
493
494
		return $manager->getItem( $context->getUserId() )->getSiteId();
495
	}
496
497
498
	/**
499
	 * Returns the list of sub-client names configured for the client.
500
	 *
501
	 * @return array List of JQAdm client names
502
	 */
503
	protected function getSubClientNames()
504
	{
505
		/** admin/jqadm/locale/site/standard/subparts
506
		 * List of JQAdm sub-clients rendered within the locale section
507
		 *
508
		 * The output of the frontend is composed of the code generated by the JQAdm
509
		 * clients. Each JQAdm client can consist of serveral (or none) sub-clients
510
		 * that are responsible for rendering certain sub-parts of the output. The
511
		 * sub-clients can contain JQAdm clients themselves and therefore a
512
		 * hierarchical tree of JQAdm clients is composed. Each JQAdm client creates
513
		 * the output that is placed inside the container of its parent.
514
		 *
515
		 * At first, always the JQAdm code generated by the parent is printed, then
516
		 * the JQAdm code of its sub-clients. The order of the JQAdm sub-clients
517
		 * determines the order of the output of these sub-clients inside the parent
518
		 * container. If the configured list of clients is
519
		 *
520
		 *  array( "subclient1", "subclient2" )
521
		 *
522
		 * you can easily change the order of the output by reordering the subparts:
523
		 *
524
		 *  admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" )
525
		 *
526
		 * You can also remove one or more parts if they shouldn't be rendered:
527
		 *
528
		 *  admin/jqadm/<clients>/subparts = array( "subclient1" )
529
		 *
530
		 * As the clients only generates structural JQAdm, the layout defined via CSS
531
		 * should support adding, removing or reordering content by a fluid like
532
		 * design.
533
		 *
534
		 * @param array List of sub-client names
535
		 * @since 2017.10
536
		 * @category Developer
537
		 */
538
		return $this->getContext()->getConfig()->get( 'admin/jqadm/locale/site/standard/subparts', [] );
539
	}
540
541
542
	/**
543
	 * Creates new and updates existing items using the data array
544
	 *
545
	 * @param array $data Data array
546
	 * @param boolean $super If current user is a super user
547
	 * @return \Aimeos\MShop\Locale\Item\Iface New locale item object
548
	 */
549
	protected function fromArray( array $data, $super )
550
	{
551
		$conf = [];
552
553
		foreach( (array) $this->getValue( $data, 'config', [] ) as $idx => $entry )
554
		{
555
			if( trim( $entry['key'] ?? '' ) !== '' ) {
556
				$conf[$entry['key']] = $entry['val'] ?? null ;
557
			}
558
		}
559
560
		$manager = \Aimeos\MShop::create( $this->getContext(), 'locale/site' );
561
562
		if( isset( $data['locale.site.id'] ) && $data['locale.site.id'] != '' )
563
		{
564
			$this->checkSite( $super, $data['locale.site.id'] );
565
			$item = $manager->getItem( $data['locale.site.id'] );
566
		}
567
		else
568
		{
569
			$this->checkSite( $super );
570
			$item = $manager->createItem();
571
		}
572
573
		$item->fromArray( $data, true );
574
		$item->setConfig( $conf );
0 ignored issues
show
Bug introduced by
The method setConfig() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Plugin\Item\Standard or Aimeos\MShop\Locale\Item\Site\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Coupon\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Product\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

574
		$item->/** @scrutinizer ignore-call */ 
575
         setConfig( $conf );
Loading history...
575
576
		if( $item->getId() == null ) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $item->getId() of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
577
			return $manager->insertItem( $item );
578
		}
579
580
		return $item;
581
	}
582
583
584
	/**
585
	 * Constructs the data array for the view from the given item
586
	 *
587
	 * @param \Aimeos\MShop\Locale\Item\Iface $item Locale item object
588
	 * @return string[] Multi-dimensional associative list of item data
589
	 */
590
	protected function toArray( \Aimeos\MShop\Locale\Item\Site\Iface $item, $copy = false )
591
	{
592
		$data = $item->toArray( true );
593
		$data['config'] = [];
594
595
		if( $copy === true )
596
		{
597
			$data['locale.site.code'] = $data['locale.site.code'] . '_copy';
598
			$data['locale.site.id'] = '';
599
		}
600
601
		foreach( $item->getConfig() as $key => $value ) {
602
			$data['config'][] = ['key' => $key, 'val' => $value];
603
		}
604
605
		return $data;
606
	}
607
608
609
	/**
610
	 * Returns the rendered template including the view data
611
	 *
612
	 * @return string HTML output
613
	 */
614
	protected function render( \Aimeos\MW\View\Iface $view )
615
	{
616
		/** admin/jqadm/locale/site/template-item
617
		 * Relative path to the HTML body template for the locale item.
618
		 *
619
		 * The template file contains the HTML code and processing instructions
620
		 * to generate the result shown in the body of the frontend. The
621
		 * configuration string is the path to the template file relative
622
		 * to the templates directory (usually in admin/jqadm/templates).
623
		 *
624
		 * You can overwrite the template file configuration in extensions and
625
		 * provide alternative templates. These alternative templates should be
626
		 * named like the default one but with the string "default" replaced by
627
		 * an unique name. You may use the name of your project for this. If
628
		 * you've implemented an alternative client class as well, "default"
629
		 * should be replaced by the name of the new class.
630
		 *
631
		 * @param string Relative path to the template creating the HTML code
632
		 * @since 2017.10
633
		 * @category Developer
634
		 */
635
		$tplconf = 'admin/jqadm/locale/site/template-item';
636
		$default = 'locale/site/item-standard';
637
638
		return $view->render( $view->config( $tplconf, $default ) );
639
	}
640
}
641