Completed
Push — master ( 4b53c0...8e3539 )
by Aimeos
02:32
created
admin/jsonadm/src/Admin/JsonAdm/Base.php 1 patch
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 * @param \Aimeos\MShop\Context\Item\Iface $context MShop context object
32 32
 	 * @param string $path Name of the client separated by slashes, e.g "product/property"
33 33
 	 */
34
-	public function __construct( \Aimeos\MShop\Context\Item\Iface $context, $path )
34
+	public function __construct(\Aimeos\MShop\Context\Item\Iface $context, $path)
35 35
 	{
36 36
 		$this->context = $context;
37 37
 		$this->path = $path;
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 	 * @param array $param List of method parameter
46 46
 	 * @throws \Aimeos\Admin\JsonAdm\Exception If method call failed
47 47
 	 */
48
-	public function __call( $name, array $param )
48
+	public function __call($name, array $param)
49 49
 	{
50
-		throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Unable to call method "%1$s"', $name ) );
50
+		throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Unable to call method "%1$s"', $name));
51 51
 	}
52 52
 
53 53
 
@@ -58,8 +58,8 @@  discard block
 block discarded – undo
58 58
 	 */
59 59
 	public function getAimeos()
60 60
 	{
61
-		if( !isset( $this->aimeos ) ) {
62
-			throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Aimeos object not available' ) );
61
+		if (!isset($this->aimeos)) {
62
+			throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Aimeos object not available'));
63 63
 		}
64 64
 
65 65
 		return $this->aimeos;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 * @param \Aimeos\Bootstrap $aimeos The Aimeos bootstrap object
73 73
 	 * @return \Aimeos\Admin\JQAdm\Iface Reference to this object for fluent calls
74 74
 	 */
75
-	public function setAimeos( \Aimeos\Bootstrap $aimeos )
75
+	public function setAimeos(\Aimeos\Bootstrap $aimeos)
76 76
 	{
77 77
 		$this->aimeos = $aimeos;
78 78
 		return $this;
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 */
87 87
 	public function getView()
88 88
 	{
89
-		if( !isset( $this->view ) ) {
90
-			throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'No view available' ) );
89
+		if (!isset($this->view)) {
90
+			throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('No view available'));
91 91
 		}
92 92
 
93 93
 		return $this->view;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 * @param \Aimeos\MW\View\Iface $view The view object which generates the admin output
101 101
 	 * @return \Aimeos\Admin\JQAdm\Iface Reference to this object for fluent calls
102 102
 	 */
103
-	public function setView( \Aimeos\MW\View\Iface $view )
103
+	public function setView(\Aimeos\MW\View\Iface $view)
104 104
 	{
105 105
 		$this->view = $view;
106 106
 		return $this;
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @param array $include List of resource types that should be fetched
115 115
 	 * @return array List of items implementing \Aimeos\MShop\Common\Item\Iface
116 116
 	 */
117
-	protected function getChildItems( array $items, array $include )
117
+	protected function getChildItems(array $items, array $include)
118 118
 	{
119 119
 		return [];
120 120
 	}
@@ -137,9 +137,9 @@  discard block
 block discarded – undo
137 137
 	 * @param \Aimeos\MW\View\Iface $view View object with "resource" parameter
138 138
 	 * @return array List of domain names
139 139
 	 */
140
-	protected function getDomains( \Aimeos\MW\View\Iface $view )
140
+	protected function getDomains(\Aimeos\MW\View\Iface $view)
141 141
 	{
142
-		if( ( $domains = $view->param( 'resource' ) ) == '' )
142
+		if (($domains = $view->param('resource')) == '')
143 143
 		{
144 144
 			/** admin/jsonadm/domains
145 145
 			 * A list of domain names whose clients are available for the JSON API
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 				'attribute', 'catalog', 'coupon', 'customer', 'locale', 'media', 'order',
163 163
 				'plugin', 'price', 'product', 'service', 'supplier', 'stock', 'tag', 'text'
164 164
 			);
165
-			$domains = $this->getContext()->getConfig()->get( 'admin/jsonadm/domains', $default );
165
+			$domains = $this->getContext()->getConfig()->get('admin/jsonadm/domains', $default);
166 166
 		}
167 167
 
168 168
 		return (array) $domains;
@@ -175,15 +175,15 @@  discard block
 block discarded – undo
175 175
 	 * @param \stdClass $request Decoded request body
176 176
 	 * @return array List of item IDs
177 177
 	 */
178
-	protected function getIds( $request )
178
+	protected function getIds($request)
179 179
 	{
180 180
 		$ids = [];
181 181
 
182
-		if( isset( $request->data ) )
182
+		if (isset($request->data))
183 183
 		{
184
-			foreach( (array) $request->data as $entry )
184
+			foreach ((array) $request->data as $entry)
185 185
 			{
186
-				if( isset( $entry->id ) ) {
186
+				if (isset($entry->id)) {
187 187
 					$ids[] = $entry->id;
188 188
 				}
189 189
 			}
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 * @param array $include List of resource types that should be fetched
201 201
 	 * @return array List of items implementing \Aimeos\MShop\Common\Item\Lists\Iface
202 202
 	 */
203
-	protected function getListItems( array $items, array $include )
203
+	protected function getListItems(array $items, array $include)
204 204
 	{
205 205
 		return [];
206 206
 	}
@@ -223,23 +223,23 @@  discard block
 block discarded – undo
223 223
 	 * @param array $listItems List of items implementing \Aimeos\MShop\Common\Item\Lists\Iface
224 224
 	 * @return array List of items implementing \Aimeos\MShop\Common\Item\Iface
225 225
 	 */
226
-	protected function getRefItems( array $listItems )
226
+	protected function getRefItems(array $listItems)
227 227
 	{
228 228
 		$list = $map = [];
229 229
 		$context = $this->getContext();
230 230
 
231
-		foreach( $listItems as $listItem ) {
231
+		foreach ($listItems as $listItem) {
232 232
 			$map[$listItem->getDomain()][] = $listItem->getRefId();
233 233
 		}
234 234
 
235
-		foreach( $map as $domain => $ids )
235
+		foreach ($map as $domain => $ids)
236 236
 		{
237
-			$manager = \Aimeos\MShop\Factory::createManager( $context, $domain );
237
+			$manager = \Aimeos\MShop\Factory::createManager($context, $domain);
238 238
 
239 239
 			$search = $manager->createSearch();
240
-			$search->setConditions( $search->compare( '==', str_replace( '/', '.', $domain ) . '.id', $ids ) );
240
+			$search->setConditions($search->compare('==', str_replace('/', '.', $domain) . '.id', $ids));
241 241
 
242
-			$list = array_merge( $list, $manager->searchItems( $search ) );
242
+			$list = array_merge($list, $manager->searchItems($search));
243 243
 		}
244 244
 
245 245
 		return $list;
@@ -253,14 +253,14 @@  discard block
 block discarded – undo
253 253
 	 * @param array List of all available resources
254 254
 	 * @return array List of allowed resources
255 255
 	 */
256
-	protected function getAllowedResources( \Aimeos\MW\View\Iface $view, array $resources )
256
+	protected function getAllowedResources(\Aimeos\MW\View\Iface $view, array $resources)
257 257
 	{
258 258
 		$config = $this->getContext()->getConfig();
259 259
 		$allowed = [];
260 260
 
261
-		foreach( $resources as $resource )
261
+		foreach ($resources as $resource)
262 262
 		{
263
-			if( $view->access( $config->get( 'admin/jsonadm/resource/' . $resource . '/groups', [] ) ) === true ) {
263
+			if ($view->access($config->get('admin/jsonadm/resource/' . $resource . '/groups', [])) === true) {
264 264
 				$allowed[] = $resource;
265 265
 			}
266 266
 		}
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	 * @param \Aimeos\MW\View\Iface $view View object with "resource" parameter
276 276
 	 * @return array List of domain names
277 277
 	 */
278
-	protected function getResources( \Aimeos\MW\View\Iface $view )
278
+	protected function getResources(\Aimeos\MW\View\Iface $view)
279 279
 	{
280 280
 		/** admin/jsonadm/resources
281 281
 		 * A list of additional resources name whose clients are available for the JSON API
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 		 * @category Developer
294 294
 		 * @see admin/jsonadm/domains
295 295
 		 */
296
-		return (array) $view->config( 'admin/jsonadm/resources', ['coupon/config', 'plugin/config', 'service/config'] );
296
+		return (array) $view->config('admin/jsonadm/resources', ['coupon/config', 'plugin/config', 'service/config']);
297 297
 	}
298 298
 
299 299
 
@@ -304,11 +304,11 @@  discard block
 block discarded – undo
304 304
 	 * @param array $params List of criteria data with condition, sorting and paging
305 305
 	 * @return \Aimeos\MW\Criteria\Iface Initialized criteria object
306 306
 	 */
307
-	protected function initCriteria( \Aimeos\MW\Criteria\Iface $criteria, array $params )
307
+	protected function initCriteria(\Aimeos\MW\Criteria\Iface $criteria, array $params)
308 308
 	{
309
-		$this->initCriteriaConditions( $criteria, $params );
310
-		$this->initCriteriaSortations( $criteria, $params );
311
-		$this->initCriteriaSlice( $criteria, $params );
309
+		$this->initCriteriaConditions($criteria, $params);
310
+		$this->initCriteriaSortations($criteria, $params);
311
+		$this->initCriteriaSlice($criteria, $params);
312 312
 
313 313
 		return $criteria;
314 314
 	}
@@ -320,17 +320,17 @@  discard block
 block discarded – undo
320 320
 	 * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object
321 321
 	 * @param array $params List of criteria data with condition, sorting and paging
322 322
 	 */
323
-	protected function initCriteriaConditions( \Aimeos\MW\Criteria\Iface $criteria, array $params )
323
+	protected function initCriteriaConditions(\Aimeos\MW\Criteria\Iface $criteria, array $params)
324 324
 	{
325
-		if( !isset( $params['filter'] ) ) {
325
+		if (!isset($params['filter'])) {
326 326
 			return;
327 327
 		}
328 328
 
329 329
 		$existing = $criteria->getConditions();
330
-		$criteria->setConditions( $criteria->toConditions( (array) $params['filter'] ) );
330
+		$criteria->setConditions($criteria->toConditions((array) $params['filter']));
331 331
 
332
-		$expr = array( $criteria->getConditions(), $existing );
333
-		$criteria->setConditions( $criteria->combine( '&&', $expr ) );
332
+		$expr = array($criteria->getConditions(), $existing);
333
+		$criteria->setConditions($criteria->combine('&&', $expr));
334 334
 	}
335 335
 
336 336
 
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
 	 * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object
341 341
 	 * @param array $params List of criteria data with condition, sorting and paging
342 342
 	 */
343
-	protected function initCriteriaSlice( \Aimeos\MW\Criteria\Iface $criteria, array $params )
343
+	protected function initCriteriaSlice(\Aimeos\MW\Criteria\Iface $criteria, array $params)
344 344
 	{
345
-		$start = ( isset( $params['page']['offset'] ) ? (int) $params['page']['offset'] : 0 );
346
-		$size = ( isset( $params['page']['limit'] ) ? (int) $params['page']['limit'] : 25 );
345
+		$start = (isset($params['page']['offset']) ? (int) $params['page']['offset'] : 0);
346
+		$size = (isset($params['page']['limit']) ? (int) $params['page']['limit'] : 25);
347 347
 
348
-		$criteria->setSlice( $start, $size );
348
+		$criteria->setSlice($start, $size);
349 349
 	}
350 350
 
351 351
 
@@ -355,24 +355,24 @@  discard block
 block discarded – undo
355 355
 	 * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object
356 356
 	 * @param array $params List of criteria data with condition, sorting and paging
357 357
 	 */
358
-	protected function initCriteriaSortations( \Aimeos\MW\Criteria\Iface $criteria, array $params )
358
+	protected function initCriteriaSortations(\Aimeos\MW\Criteria\Iface $criteria, array $params)
359 359
 	{
360
-		if( !isset( $params['sort'] ) ) {
360
+		if (!isset($params['sort'])) {
361 361
 			return;
362 362
 		}
363 363
 
364 364
 		$sortation = [];
365 365
 
366
-		foreach( explode( ',', $params['sort'] ) as $sort )
366
+		foreach (explode(',', $params['sort']) as $sort)
367 367
 		{
368
-			if( $sort[0] === '-' ) {
369
-				$sortation[] = $criteria->sort( '-', substr( $sort, 1 ) );
368
+			if ($sort[0] === '-') {
369
+				$sortation[] = $criteria->sort('-', substr($sort, 1));
370 370
 			} else {
371
-				$sortation[] = $criteria->sort( '+', $sort );
371
+				$sortation[] = $criteria->sort('+', $sort);
372 372
 			}
373 373
 		}
374 374
 
375
-		$criteria->setSortations( $sortation );
375
+		$criteria->setSortations($sortation);
376 376
 	}
377 377
 
378 378
 
@@ -383,14 +383,14 @@  discard block
 block discarded – undo
383 383
 	 * @param \stdClass $request Object with request body data
384 384
 	 * @return array List of items
385 385
 	 */
386
-	protected function saveData( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $request )
386
+	protected function saveData(\Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $request)
387 387
 	{
388 388
 		$data = [];
389 389
 
390
-		if( isset( $request->data ) )
390
+		if (isset($request->data))
391 391
 		{
392
-			foreach( (array) $request->data as $entry ) {
393
-				$data[] = $this->saveEntry( $manager, $entry );
392
+			foreach ((array) $request->data as $entry) {
393
+				$data[] = $this->saveEntry($manager, $entry);
394 394
 			}
395 395
 		}
396 396
 
@@ -405,22 +405,22 @@  discard block
 block discarded – undo
405 405
 	 * @param \stdClass $entry Object including "id" and "attributes" elements
406 406
 	 * @return \Aimeos\MShop\Common\Item\Iface New or updated item
407 407
 	 */
408
-	protected function saveEntry( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry )
408
+	protected function saveEntry(\Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry)
409 409
 	{
410
-		if( isset( $entry->id ) ) {
411
-			$item = $manager->getItem( $entry->id );
410
+		if (isset($entry->id)) {
411
+			$item = $manager->getItem($entry->id);
412 412
 		} else {
413 413
 			$item = $manager->createItem();
414 414
 		}
415 415
 
416
-		$item = $this->addItemData( $manager, $item, $entry, $item->getResourceType() );
417
-		$item = $manager->saveItem( $item );
416
+		$item = $this->addItemData($manager, $item, $entry, $item->getResourceType());
417
+		$item = $manager->saveItem($item);
418 418
 
419
-		if( isset( $entry->relationships ) ) {
420
-			$this->saveRelationships( $manager, $item, $entry->relationships );
419
+		if (isset($entry->relationships)) {
420
+			$this->saveRelationships($manager, $item, $entry->relationships);
421 421
 		}
422 422
 
423
-		return $manager->getItem( $item->getId() );
423
+		return $manager->getItem($item->getId());
424 424
 	}
425 425
 
426 426
 
@@ -431,28 +431,28 @@  discard block
 block discarded – undo
431 431
 	 * @param \Aimeos\MShop\Common\Item\Iface $item Domain item with an unique ID set
432 432
 	 * @param \stdClass $relationships Object including the <domain>/data/attributes structure
433 433
 	 */
434
-	protected function saveRelationships( \Aimeos\MShop\Common\Manager\Iface $manager,
435
-		\Aimeos\MShop\Common\Item\Iface $item, \stdClass $relationships )
434
+	protected function saveRelationships(\Aimeos\MShop\Common\Manager\Iface $manager,
435
+		\Aimeos\MShop\Common\Item\Iface $item, \stdClass $relationships)
436 436
 	{
437 437
 		$id = $item->getId();
438
-		$listManager = $manager->getSubManager( 'lists' );
438
+		$listManager = $manager->getSubManager('lists');
439 439
 
440
-		foreach( (array) $relationships as $domain => $list )
440
+		foreach ((array) $relationships as $domain => $list)
441 441
 		{
442
-			if( isset( $list->data ) )
442
+			if (isset($list->data))
443 443
 			{
444
-				foreach( (array) $list->data as $data )
444
+				foreach ((array) $list->data as $data)
445 445
 				{
446
-					$listItem = $this->addItemData( $listManager, $listManager->createItem(), $data, $domain );
446
+					$listItem = $this->addItemData($listManager, $listManager->createItem(), $data, $domain);
447 447
 
448
-					if( isset( $data->id ) ) {
449
-						$listItem->setRefId( $data->id );
448
+					if (isset($data->id)) {
449
+						$listItem->setRefId($data->id);
450 450
 					}
451 451
 
452
-					$listItem->setParentId( $id );
453
-					$listItem->setDomain( $domain );
452
+					$listItem->setParentId($id);
453
+					$listItem->setDomain($domain);
454 454
 
455
-					$listManager->saveItem( $listItem, false );
455
+					$listManager->saveItem($listItem, false);
456 456
 				}
457 457
 			}
458 458
 		}
@@ -469,20 +469,20 @@  discard block
 block discarded – undo
469 469
 	 * @return \Aimeos\MShop\Common\Item\Iface Item including the data
470 470
 	 */
471 471
 	protected function addItemData(\Aimeos\MShop\Common\Manager\Iface $manager,
472
-		\Aimeos\MShop\Common\Item\Iface $item, \stdClass $data, $domain )
472
+		\Aimeos\MShop\Common\Item\Iface $item, \stdClass $data, $domain)
473 473
 	{
474
-		if( isset( $data->attributes ) )
474
+		if (isset($data->attributes))
475 475
 		{
476 476
 			$attr = (array) $data->attributes;
477
-			$key = str_replace( '/', '.', $item->getResourceType() );
477
+			$key = str_replace('/', '.', $item->getResourceType());
478 478
 
479
-			if( isset( $attr[$key.'.type'] ) )
479
+			if (isset($attr[$key . '.type']))
480 480
 			{
481
-				$typeItem = $manager->getSubManager( 'type' )->findItem( $attr[$key.'.type'], [], $domain );
482
-				$attr[$key.'.typeid'] = $typeItem->getId();
481
+				$typeItem = $manager->getSubManager('type')->findItem($attr[$key . '.type'], [], $domain);
482
+				$attr[$key . '.typeid'] = $typeItem->getId();
483 483
 			}
484 484
 
485
-			$item->fromArray( $attr );
485
+			$item->fromArray($attr);
486 486
 		}
487 487
 
488 488
 		return $item;
Please login to merge, or discard this patch.