Standard::toArray()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 36
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

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

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

337
			$listItem = $item->getListItem( 'media', $type, $id, false ) ?: $manager->/** @scrutinizer ignore-call */ createListItem();

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...
338
			$refItem = $listItem->getRefItem() ?: $mediaManager->create();
339
340
			$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\Group\Item\Iface or Aimeos\MShop\Rule\Item\Iface or Aimeos\MShop\Basket\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\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\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

340
			$refItem->fromArray( $entry, true )->/** @scrutinizer ignore-call */ setDomain( 'cms' );
Loading history...
341
342
			$preview = $this->val( $files, 'media/' . $idx . '/preview' );
343
			$file = $this->val( $files, 'media/' . $idx . '/file' );
344
345
			if( $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\Group\Item\Iface or Aimeos\MShop\Rule\Item\Iface or Aimeos\MShop\Basket\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\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\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\Type\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

345
			if( $refItem->getId() === null && $refItem->/** @scrutinizer ignore-call */ getUrl() !== '' ) {
Loading history...
346
				$refItem = $mediaManager->copy( $refItem );
0 ignored issues
show
Bug introduced by
The method copy() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Common\Manager\Decorator\Iface or Aimeos\MShop\Order\Manag...rvice\Transaction\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Type\Manager\Iface or Aimeos\MShop\Order\Manager\Service\Iface or Aimeos\MShop\Review\Manager\Iface or Aimeos\MShop\Coupon\Manager\Code\Iface or Aimeos\MShop\Product\Manager\Iface or Aimeos\MShop\Supplier\Manager\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Attribute\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Address\Iface or Aimeos\MShop\Order\Manager\Product\Attribute\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Customer\Manager\Iface or Aimeos\MShop\Order\Manager\Coupon\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Group\Manager\Iface or Aimeos\MShop\Catalog\Manager\Iface or Aimeos\MShop\Locale\Manager\Site\Iface or Aimeos\MShop\Order\Manager\Service\Attribute\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Cms\Manager\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Rule\Manager\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Basket\Manager\Iface or Aimeos\MShop\Stock\Manager\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MShop\Service\Manager\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MShop\Cms\Manager\Lists\Iface or Aimeos\MShop\Locale\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Product\Iface or Aimeos\MShop\Price\Manager\Property\Iface or Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Property\Type\Iface or Aimeos\MShop\Cms\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Property\Type\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Property\Type\Iface or Aimeos\MShop\Rule\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Product\Manager\Property\Type\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Stock\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Media\Manager\Property\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\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
				/** @scrutinizer ignore-call */ 
347
    $refItem = $mediaManager->copy( $refItem );
Loading history...
347
			}
348
349
			$refItem = $mediaManager->upload( $refItem, $file, $preview );
0 ignored issues
show
Bug introduced by
The method upload() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Common\Manager\Decorator\Iface or Aimeos\MShop\Order\Manag...rvice\Transaction\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Type\Manager\Iface or Aimeos\MShop\Order\Manager\Service\Iface or Aimeos\MShop\Review\Manager\Iface or Aimeos\MShop\Coupon\Manager\Code\Iface or Aimeos\MShop\Product\Manager\Iface or Aimeos\MShop\Supplier\Manager\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Attribute\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Address\Iface or Aimeos\MShop\Order\Manager\Product\Attribute\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Customer\Manager\Iface or Aimeos\MShop\Order\Manager\Coupon\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Group\Manager\Iface or Aimeos\MShop\Catalog\Manager\Iface or Aimeos\MShop\Locale\Manager\Site\Iface or Aimeos\MShop\Order\Manager\Service\Attribute\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Cms\Manager\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Rule\Manager\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Basket\Manager\Iface or Aimeos\MShop\Stock\Manager\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MShop\Service\Manager\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MShop\Cms\Manager\Lists\Iface or Aimeos\MShop\Locale\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Product\Iface or Aimeos\MShop\Price\Manager\Property\Iface or Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Property\Type\Iface or Aimeos\MShop\Cms\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Property\Type\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Property\Type\Iface or Aimeos\MShop\Rule\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Product\Manager\Property\Type\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Stock\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Media\Manager\Property\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\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

349
			/** @scrutinizer ignore-call */ 
350
   $refItem = $mediaManager->upload( $refItem, $file, $preview );
Loading history...
350
			$listItem->fromArray( $entry, true )->setPosition( $idx )->setConfig( [] );
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\Group\Item\Iface or Aimeos\MShop\Basket\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\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\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

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