Standard   A
last analyzed

Complexity

Total Complexity 28

Size/Duplication

Total Lines 428
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 104
dl 0
loc 428
rs 10
c 0
b 0
f 0
wmc 28

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 data() 0 19 1
A save() 0 8 1
A delete() 0 8 1
A get() 0 8 1
A create() 0 20 2
A render() 0 25 1
B fromArray() 0 43 9
A toArray() 0 36 5
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 )->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
		$mediaManager = \Aimeos\MShop::create( $context, 'media' );
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
				$mediaManager->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
		$manager = \Aimeos\MShop::create( $context, 'cms' );
332
		$mediaManager = \Aimeos\MShop::create( $context, 'media' );
333
334
		$listItems = $item->getListItems( 'media', null, null, false );
335
		$files = (array) $this->view()->request()->getUploadedFiles();
336
337
		foreach( $data as $idx => $entry )
338
		{
339
			$id = $this->val( $entry, 'media.id', '' );
340
			$type = $this->val( $entry, 'cms.lists.type', 'default' );
341
342
			$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

342
			$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...
343
			$refItem = $listItem->getRefItem() ?: $mediaManager->create();
344
345
			$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

345
			$refItem->fromArray( $entry, true )->/** @scrutinizer ignore-call */ setDomain( 'cms' );
Loading history...
346
347
			$preview = $this->val( $files, 'media/' . $idx . '/preview' );
348
			$file = $this->val( $files, 'media/' . $idx . '/file' );
349
350
			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

350
			if( $refItem->getId() === null && $refItem->/** @scrutinizer ignore-call */ getUrl() !== '' ) {
Loading history...
351
				$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

351
				/** @scrutinizer ignore-call */ 
352
    $refItem = $mediaManager->copy( $refItem );
Loading history...
352
			}
353
354
			$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

354
			/** @scrutinizer ignore-call */ 
355
   $refItem = $mediaManager->upload( $refItem, $file, $preview );
Loading history...
355
			$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

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