Standard   A
last analyzed

Complexity

Total Complexity 31

Size/Duplication

Total Lines 441
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 112
dl 0
loc 441
rs 9.92
c 0
b 0
f 0
wmc 31

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubClientNames() 0 36 1
A deleteMediaItems() 0 22 4
A getSubClient() 0 76 1
A copy() 0 8 1
A render() 0 25 1
A data() 0 19 1
A save() 0 8 1
A delete() 0 8 1
C fromArray() 0 55 12
A get() 0 8 1
A toArray() 0 37 5
A create() 0 20 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021-2023
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Cms\Media;
12
13
sprintf( 'media' ); // for translation
14
15
16
/**
17
 * Default implementation of cms media 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
	/** admin/jqadm/cms/media/name
27
	 * Name of the media subpart used by the JQAdm cms implementation
28
	 *
29
	 * Use "Myname" if your class is named "\Aimeos\Admin\Jqadm\Cms\Media\Myname".
30
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
31
	 *
32
	 * @param string Last part of the JQAdm class name
33
	 * @since 2021.04
34
	 * @category Developer
35
	 */
36
37
38
	/**
39
	 * Adds the required data used in the cms template
40
	 *
41
	 * @param \Aimeos\Base\View\Iface $view View object
42
	 * @return \Aimeos\Base\View\Iface View object with assigned parameters
43
	 */
44
	public function data( \Aimeos\Base\View\Iface $view ) : \Aimeos\Base\View\Iface
45
	{
46
		$context = $this->context();
47
48
		$typeManager = \Aimeos\MShop::create( $context, 'media/type' );
49
		$listTypeManager = \Aimeos\MShop::create( $context, 'cms/lists/type' );
50
51
		$search = $typeManager->filter( true )->slice( 0, 10000 );
52
		$search->setConditions( $search->compare( '==', 'media.type.domain', 'cms' ) );
53
		$search->setSortations( [$search->sort( '+', 'media.type.position' )] );
54
55
		$listSearch = $listTypeManager->filter( true )->slice( 0, 10000 );
56
		$listSearch->setConditions( $listSearch->compare( '==', 'cms.lists.type.domain', 'media' ) );
57
		$listSearch->setSortations( [$listSearch->sort( '+', 'cms.lists.type.position' )] );
58
59
		$view->mediaListTypes = $listTypeManager->search( $listSearch );
60
		$view->mediaTypes = $typeManager->search( $search );
61
62
		return $view;
63
	}
64
65
66
	/**
67
	 * Copies a resource
68
	 *
69
	 * @return string|null HTML output
70
	 */
71
	public function copy() : ?string
72
	{
73
		$view = $this->object()->data( $this->view() );
74
75
		$view->mediaData = $this->toArray( $view->item, true );
76
		$view->mediaBody = parent::copy();
77
78
		return $this->render( $view );
79
	}
80
81
82
	/**
83
	 * Creates a new resource
84
	 *
85
	 * @return string|null HTML output
86
	 */
87
	public function create() : ?string
88
	{
89
		$view = $this->object()->data( $this->view() );
90
		$siteid = $this->context()->locale()->getSiteId();
91
92
		$itemData = $this->toArray( $view->item );
93
		$data = array_replace_recursive( $itemData, $view->param( 'media', [] ) );
94
95
		foreach( $data as $idx => $entry )
96
		{
97
			$data[$idx]['media.siteid'] = $siteid;
98
			$data[$idx]['media.url'] = $entry['media.url'] ?? null;
99
			$data[$idx]['media.preview'] = $entry['media.preview'] ?? null;
100
			$data[$idx]['cms.lists.siteid'] = $siteid;
101
		}
102
103
		$view->mediaData = $data;
104
		$view->mediaBody = parent::create();
105
106
		return $this->render( $view );
107
	}
108
109
110
	/**
111
	 * Deletes a resource
112
	 *
113
	 * @return string|null HTML output
114
	 */
115
	public function delete() : ?string
116
	{
117
		parent::delete();
118
119
		$item = $this->view()->item;
120
		$this->deleteMediaItems( $item, $item->getListItems( 'media', null, null, false )->toArray() );
121
122
		return null;
123
	}
124
125
126
	/**
127
	 * Returns a single resource
128
	 *
129
	 * @return string|null HTML output
130
	 */
131
	public function get() : ?string
132
	{
133
		$view = $this->object()->data( $this->view() );
134
135
		$view->mediaData = $this->toArray( $view->item );
136
		$view->mediaBody = parent::get();
137
138
		return $this->render( $view );
139
	}
140
141
142
	/**
143
	 * Saves the data
144
	 *
145
	 * @return string|null HTML output
146
	 */
147
	public function save() : ?string
148
	{
149
		$view = $this->view();
150
151
		$view->item = $this->fromArray( $view->item, $view->param( 'media', [] ) );
152
		$view->mediaBody = parent::save();
153
154
		return null;
155
	}
156
157
158
	/**
159
	 * Returns the sub-client given by its name.
160
	 *
161
	 * @param string $type Name of the client type
162
	 * @param string|null $name Name of the sub-client (Default if null)
163
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
164
	 */
165
	public function getSubClient( string $type, ?string $name = null ) : \Aimeos\Admin\JQAdm\Iface
166
	{
167
		/** admin/jqadm/cms/media/decorators/excludes
168
		 * Excludes decorators added by the "common" option from the cms JQAdm client
169
		 *
170
		 * Decorators extend the functionality of a class by adding new aspects
171
		 * (e.g. log what is currently done), executing the methods of the underlying
172
		 * class only in certain conditions (e.g. only for logged in users) or
173
		 * modify what is returned to the caller.
174
		 *
175
		 * This option allows you to remove a decorator added via
176
		 * "admin/jqadm/common/decorators/default" before they are wrapped
177
		 * around the JQAdm client.
178
		 *
179
		 *  admin/jqadm/cms/media/decorators/excludes = array( 'decorator1' )
180
		 *
181
		 * This would remove the decorator named "decorator1" from the list of
182
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
183
		 * "admin/jqadm/common/decorators/default" to the JQAdm client.
184
		 *
185
		 * @param array List of decorator names
186
		 * @since 2021.04
187
		 * @category Developer
188
		 * @see admin/jqadm/common/decorators/default
189
		 * @see admin/jqadm/cms/media/decorators/global
190
		 * @see admin/jqadm/cms/media/decorators/local
191
		 */
192
193
		/** admin/jqadm/cms/media/decorators/global
194
		 * Adds a list of globally available decorators only to the cms JQAdm client
195
		 *
196
		 * Decorators extend the functionality of a class by adding new aspects
197
		 * (e.g. log what is currently done), executing the methods of the underlying
198
		 * class only in certain conditions (e.g. only for logged in users) or
199
		 * modify what is returned to the caller.
200
		 *
201
		 * This option allows you to wrap global decorators
202
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
203
		 *
204
		 *  admin/jqadm/cms/media/decorators/global = array( 'decorator1' )
205
		 *
206
		 * This would add the decorator named "decorator1" defined by
207
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
208
		 *
209
		 * @param array List of decorator names
210
		 * @since 2021.04
211
		 * @category Developer
212
		 * @see admin/jqadm/common/decorators/default
213
		 * @see admin/jqadm/cms/media/decorators/excludes
214
		 * @see admin/jqadm/cms/media/decorators/local
215
		 */
216
217
		/** admin/jqadm/cms/media/decorators/local
218
		 * Adds a list of local decorators only to the cms JQAdm client
219
		 *
220
		 * Decorators extend the functionality of a class by adding new aspects
221
		 * (e.g. log what is currently done), executing the methods of the underlying
222
		 * class only in certain conditions (e.g. only for logged in users) or
223
		 * modify what is returned to the caller.
224
		 *
225
		 * This option allows you to wrap local decorators
226
		 * ("\Aimeos\Admin\JQAdm\Cms\Decorator\*") around the JQAdm client.
227
		 *
228
		 *  admin/jqadm/cms/media/decorators/local = array( 'decorator2' )
229
		 *
230
		 * This would add the decorator named "decorator2" defined by
231
		 * "\Aimeos\Admin\JQAdm\Cms\Decorator\Decorator2" only to the JQAdm client.
232
		 *
233
		 * @param array List of decorator names
234
		 * @since 2021.04
235
		 * @category Developer
236
		 * @see admin/jqadm/common/decorators/default
237
		 * @see admin/jqadm/cms/media/decorators/excludes
238
		 * @see admin/jqadm/cms/media/decorators/global
239
		 */
240
		return $this->createSubClient( 'cms/media/' . $type, $name );
241
	}
242
243
244
	/**
245
	 * Removes the media reference and the media item if not shared
246
	 *
247
	 * @param \Aimeos\MShop\Cms\Item\Iface $item Cms item including media reference
248
	 * @param array $listItems Media list items to be removed
249
	 * @return \Aimeos\MShop\Cms\Item\Iface Modified cms item
250
	 */
251
	protected function deleteMediaItems( \Aimeos\MShop\Cms\Item\Iface $item, array $listItems ) : \Aimeos\MShop\Cms\Item\Iface
252
	{
253
		$context = $this->context();
254
		$cntl = \Aimeos\Controller\Common\Media\Factory::create( $context );
255
		$manager = \Aimeos\MShop::create( $context, 'cms' );
256
		$search = $manager->filter();
257
258
		foreach( $listItems as $listItem )
259
		{
260
			$func = $search->make( 'cms:has', ['media', $listItem->getType(), $listItem->getRefId()] );
261
			$search->setConditions( $search->compare( '!=', $func, null ) );
262
			$items = $manager->search( $search );
263
			$refItem = null;
264
265
			if( count( $items ) === 1 && ( $refItem = $listItem->getRefItem() ) !== null ) {
266
				$cntl->delete( $refItem );
267
			}
268
269
			$item->deleteListItem( 'media', $listItem, $refItem );
270
		}
271
272
		return $item;
273
	}
274
275
276
	/**
277
	 * Returns the list of sub-client names configured for the client.
278
	 *
279
	 * @return array List of JQAdm client names
280
	 */
281
	protected function getSubClientNames() : array
282
	{
283
		/** admin/jqadm/cms/media/subparts
284
		 * List of JQAdm sub-clients rendered within the cms media section
285
		 *
286
		 * The output of the frontend is composed of the code generated by the JQAdm
287
		 * clients. Each JQAdm client can consist of serveral (or none) sub-clients
288
		 * that are responsible for rendering certain sub-parts of the output. The
289
		 * sub-clients can contain JQAdm clients themselves and therefore a
290
		 * hierarchical tree of JQAdm clients is composed. Each JQAdm client creates
291
		 * the output that is placed inside the container of its parent.
292
		 *
293
		 * At first, always the JQAdm code generated by the parent is printed, then
294
		 * the JQAdm code of its sub-clients. The order of the JQAdm sub-clients
295
		 * determines the order of the output of these sub-clients inside the parent
296
		 * container. If the configured list of clients is
297
		 *
298
		 *  array( "subclient1", "subclient2" )
299
		 *
300
		 * you can easily change the order of the output by reordering the subparts:
301
		 *
302
		 *  admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" )
303
		 *
304
		 * You can also remove one or more parts if they shouldn't be rendered:
305
		 *
306
		 *  admin/jqadm/<clients>/subparts = array( "subclient1" )
307
		 *
308
		 * As the clients only generates structural JQAdm, the layout defined via CSS
309
		 * should support adding, removing or reordering content by a fluid like
310
		 * design.
311
		 *
312
		 * @param array List of sub-client names
313
		 * @since 2021.04
314
		 * @category Developer
315
		 */
316
		return $this->context()->config()->get( 'admin/jqadm/cms/media/subparts', [] );
317
	}
318
319
320
	/**
321
	 * Creates new and updates existing items using the data array
322
	 *
323
	 * @param \Aimeos\MShop\Cms\Item\Iface $item Cms item object without referenced domain items
324
	 * @param array $data Data array
325
	 * @return \Aimeos\MShop\Cms\Item\Iface Modified cms item
326
	 */
327
	protected function fromArray( \Aimeos\MShop\Cms\Item\Iface $item, array $data ) : \Aimeos\MShop\Cms\Item\Iface
328
	{
329
		$context = $this->context();
330
331
		$mediaManager = \Aimeos\MShop::create( $context, 'media' );
332
		$listManager = \Aimeos\MShop::create( $context, 'cms/lists' );
333
		$cntl = \Aimeos\Controller\Common\Media\Factory::create( $context );
334
335
		$listItems = $item->getListItems( 'media', null, null, false );
336
		$files = (array) $this->view()->request()->getUploadedFiles();
337
338
		foreach( $data as $idx => $entry )
339
		{
340
			$id = $this->val( $entry, 'media.id', '' );
341
			$type = $this->val( $entry, 'cms.lists.type', 'default' );
342
343
			$listItem = $item->getListItem( 'media', $type, $id, false ) ?: $listManager->create();
344
			$refItem = $listItem->getRefItem() ?: $mediaManager->create();
0 ignored issues
show
Bug introduced by
The method getRefItem() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Product\Item\Iface or Aimeos\MAdmin\Log\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Rule\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Order\Item\Product\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MAdmin\Cache\Item\Iface or Aimeos\MShop\Common\Item\ListsRef\Iface or Aimeos\MShop\Customer\Item\Group\Iface or Aimeos\MShop\Stock\Item\Iface or Aimeos\MShop\Order\Item\Product\Attribute\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Order\Item\Service\Iface or Aimeos\MShop\Order\Item\Iface or Aimeos\MShop\Subscription\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Order\Item\Service\Attribute\Iface or Aimeos\MShop\Review\Item\Iface or Aimeos\MAdmin\Job\Item\Iface or Aimeos\MShop\Order\Item\Status\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Locale\Item\Iface or Aimeos\MShop\Common\Item\PropertyRef\Iface or Aimeos\MShop\Tag\Item\Iface or Aimeos\MShop\Order\Item\Basket\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Order\Item\Service\Transaction\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Cms\Item\Iface or Aimeos\MShop\Common\Item\Address\Iface or Aimeos\MShop\Common\Item\Property\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Common\Item\AddressRef\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Order\Item\Coupon\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Cms\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Customer\Item\Address\Iface or Aimeos\MShop\Order\Item\Address\Iface or Aimeos\MShop\Supplier\Item\Address\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Supplier\Item\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 ignore-call  annotation

344
			$refItem = $listItem->/** @scrutinizer ignore-call */ getRefItem() ?: $mediaManager->create();
Loading history...
345
346
			$refItem->fromArray( $entry, true )->setDomain( 'cms' );
0 ignored issues
show
Bug introduced by
The method setDomain() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Product\Item\Iface or Aimeos\MAdmin\Log\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Rule\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Order\Item\Product\Iface or Aimeos\MAdmin\Cache\Item\Iface or Aimeos\MShop\Common\Item\ListsRef\Iface or Aimeos\MShop\Customer\Item\Group\Iface or Aimeos\MShop\Stock\Item\Iface or Aimeos\MShop\Order\Item\Product\Attribute\Iface or Aimeos\MShop\Order\Item\Service\Iface or Aimeos\MShop\Order\Item\Iface or Aimeos\MShop\Subscription\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Order\Item\Service\Attribute\Iface or Aimeos\MAdmin\Job\Item\Iface or Aimeos\MShop\Order\Item\Status\Iface or Aimeos\MShop\Locale\Item\Iface or Aimeos\MShop\Common\Item\PropertyRef\Iface or Aimeos\MShop\Order\Item\Basket\Iface or Aimeos\MShop\Order\Item\Service\Transaction\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Cms\Item\Iface or Aimeos\MShop\Common\Item\Address\Iface or Aimeos\MShop\Common\Item\Property\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Common\Item\AddressRef\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Order\Item\Coupon\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Cms\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Address\Iface or Aimeos\MShop\Order\Item\Address\Iface or Aimeos\MShop\Supplier\Item\Address\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Supplier\Item\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 ignore-call  annotation

346
			$refItem->fromArray( $entry, true )->/** @scrutinizer ignore-call */ setDomain( 'cms' );
Loading history...
347
			$file = $this->val( $files, 'media/' . $idx . '/file' );
348
			$preview = $this->val( $files, 'media/' . $idx . '/preview' );
349
350
			if( $file && $file->getError() !== UPLOAD_ERR_NO_FILE )
351
			{
352
				$refItem = $cntl->add( $refItem, $file );
353
354
				if( $preview && $preview->getError() !== UPLOAD_ERR_NO_FILE ) {
355
					$refItem = $cntl->addPreview( $refItem, $preview );
356
				}
357
			}
358
			elseif( $refItem->getId() === null && $refItem->getUrl() !== '' )
0 ignored issues
show
Bug introduced by
The method getUrl() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MAdmin\Log\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Rule\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Order\Item\Product\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MAdmin\Cache\Item\Iface or Aimeos\MShop\Common\Item\ListsRef\Iface or Aimeos\MShop\Customer\Item\Group\Iface or Aimeos\MShop\Stock\Item\Iface or Aimeos\MShop\Order\Item\Product\Attribute\Iface or Aimeos\MShop\Order\Item\Service\Iface or Aimeos\MShop\Order\Item\Iface or Aimeos\MShop\Subscription\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Order\Item\Service\Attribute\Iface or Aimeos\MShop\Review\Item\Iface or Aimeos\MAdmin\Job\Item\Iface or Aimeos\MShop\Order\Item\Status\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Locale\Item\Iface or Aimeos\MShop\Common\Item\PropertyRef\Iface or Aimeos\MShop\Tag\Item\Iface or Aimeos\MShop\Order\Item\Basket\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Order\Item\Service\Transaction\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Common\Item\Address\Iface or Aimeos\MShop\Common\Item\Property\Iface or Aimeos\MShop\Common\Item\AddressRef\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Order\Item\Coupon\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Customer\Item\Address\Iface or Aimeos\MShop\Order\Item\Address\Iface or Aimeos\MShop\Supplier\Item\Address\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Supplier\Item\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 ignore-call  annotation

358
			elseif( $refItem->getId() === null && $refItem->/** @scrutinizer ignore-call */ getUrl() !== '' )
Loading history...
359
			{
360
				$refItem = $cntl->copy( $refItem );
361
			}
362
363
			$conf = [];
364
365
			foreach( (array) $this->val( $entry, 'config', [] ) as $cfg )
366
			{
367
				if( ( $key = trim( $cfg['key'] ?? '' ) ) !== '' ) {
368
					$conf[$key] = trim( $cfg['val'] ?? '' );
369
				}
370
			}
371
372
			$listItem->fromArray( $entry, true );
373
			$listItem->setPosition( $idx );
0 ignored issues
show
Bug introduced by
The method setPosition() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Product\Item\Iface or Aimeos\MAdmin\Log\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MAdmin\Cache\Item\Iface or Aimeos\MShop\Common\Item\ListsRef\Iface or Aimeos\MShop\Customer\Item\Group\Iface or Aimeos\MShop\Stock\Item\Iface or Aimeos\MShop\Order\Item\Product\Attribute\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Order\Item\Iface or Aimeos\MShop\Subscription\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Order\Item\Service\Attribute\Iface or Aimeos\MShop\Review\Item\Iface or Aimeos\MAdmin\Job\Item\Iface or Aimeos\MShop\Order\Item\Status\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Common\Item\PropertyRef\Iface or Aimeos\MShop\Tag\Item\Iface or Aimeos\MShop\Order\Item\Basket\Iface or Aimeos\MShop\Order\Item\Service\Transaction\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Cms\Item\Iface or Aimeos\MShop\Common\Item\Property\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Common\Item\AddressRef\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Order\Item\Coupon\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Cms\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Customer\Item\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 ignore-call  annotation

373
			$listItem->/** @scrutinizer ignore-call */ 
374
              setPosition( $idx );
Loading history...
374
			$listItem->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 said class. However, the method does not exist in Aimeos\MAdmin\Log\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Order\Item\Product\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MAdmin\Cache\Item\Iface or Aimeos\MShop\Common\Item\ListsRef\Iface or Aimeos\MShop\Customer\Item\Group\Iface or Aimeos\MShop\Stock\Item\Iface or Aimeos\MShop\Order\Item\Product\Attribute\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Order\Item\Service\Iface or Aimeos\MShop\Order\Item\Iface or Aimeos\MShop\Subscription\Item\Iface or Aimeos\MShop\Order\Item\Service\Attribute\Iface or Aimeos\MShop\Review\Item\Iface or Aimeos\MAdmin\Job\Item\Iface or Aimeos\MShop\Order\Item\Status\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Locale\Item\Iface or Aimeos\MShop\Common\Item\PropertyRef\Iface or Aimeos\MShop\Tag\Item\Iface or Aimeos\MShop\Order\Item\Basket\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Cms\Item\Iface or Aimeos\MShop\Common\Item\Address\Iface or Aimeos\MShop\Common\Item\Property\Iface or Aimeos\MShop\Common\Item\AddressRef\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Order\Item\Coupon\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Cms\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Customer\Item\Address\Iface or Aimeos\MShop\Order\Item\Address\Iface or Aimeos\MShop\Supplier\Item\Address\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Supplier\Item\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 ignore-call  annotation

374
			$listItem->/** @scrutinizer ignore-call */ 
375
              setConfig( $conf );
Loading history...
375
376
			$item->addListItem( 'media', $listItem, $refItem );
377
378
			unset( $listItems[$listItem->getId()] );
379
		}
380
381
		return $this->deleteMediaItems( $item, $listItems->toArray() );
382
	}
383
384
385
	/**
386
	 * Constructs the data array for the view from the given item
387
	 *
388
	 * @param \Aimeos\MShop\Cms\Item\Iface $item Cms item object including referenced domain items
389
	 * @param bool $copy True if items should be copied, false if not
390
	 * @return string[] Multi-dimensional associative list of item data
391
	 */
392
	protected function toArray( \Aimeos\MShop\Cms\Item\Iface $item, bool $copy = false ) : array
393
	{
394
		$data = [];
395
		$siteId = $this->context()->locale()->getSiteId();
396
397
		foreach( $item->getListItems( 'media', null, null, false ) as $listItem )
398
		{
399
			if( ( $refItem = $listItem->getRefItem() ) === null ) {
400
				continue;
401
			}
402
403
			$list = $listItem->toArray( true ) + $refItem->toArray( true );
404
405
			if( $copy === true )
406
			{
407
				$list['cms.lists.siteid'] = $siteId;
408
				$list['cms.lists.id'] = '';
409
				$list['media.siteid'] = $siteId;
410
				$list['media.id'] = null;
411
			}
412
413
			$list['media.previews'] = $this->view()->imageset( $refItem->getPreviews(), $refItem->getFileSystem() );
414
			$list['media.preview'] = $this->view()->content( $refItem->getPreview(), $refItem->getFileSystem() );
415
			$list['media.url'] = $this->view()->content( $refItem->getUrl(), $refItem->getFileSystem() );
416
417
			$list['cms.lists.datestart'] = str_replace( ' ', 'T', $list['cms.lists.datestart'] ?? '' );
418
			$list['cms.lists.dateend'] = str_replace( ' ', 'T', $list['cms.lists.dateend'] ?? '' );
419
			$list['config'] = [];
420
421
			foreach( $listItem->getConfig() as $key => $value ) {
422
				$list['config'][] = ['key' => $key, 'val' => $value];
423
			}
424
425
			$data[] = $list;
426
		}
427
428
		return $data;
429
	}
430
431
432
	/**
433
	 * Returns the rendered template including the view data
434
	 *
435
	 * @param \Aimeos\Base\View\Iface $view View object with data assigned
436
	 * @return string HTML output
437
	 */
438
	protected function render( \Aimeos\Base\View\Iface $view ) : string
439
	{
440
		/** admin/jqadm/cms/media/template-item
441
		 * Relative path to the HTML body template of the media subpart for cmss.
442
		 *
443
		 * The template file contains the HTML code and processing instructions
444
		 * to generate the result shown in the body of the frontend. The
445
		 * configuration string is the path to the template file relative
446
		 * to the templates directory (usually in admin/jqadm/templates).
447
		 *
448
		 * You can overwrite the template file configuration in extensions and
449
		 * provide alternative templates. These alternative templates should be
450
		 * named like the default one but with the string "default" replaced by
451
		 * an unique name. You may use the name of your project for this. If
452
		 * you've implemented an alternative client class as well, "default"
453
		 * should be replaced by the name of the new class.
454
		 *
455
		 * @param string Relative path to the template creating the HTML code
456
		 * @since 2021.04
457
		 * @category Developer
458
		 */
459
		$tplconf = 'admin/jqadm/cms/media/template-item';
460
		$default = 'cms/item-media';
461
462
		return $view->render( $view->config( $tplconf, $default ) );
463
	}
464
}
465