@@ -9,32 +9,32 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | |
| 11 | 11 | $options = 0; |
| 12 | -if( defined( 'JSON_PRETTY_PRINT' ) ) { |
|
| 12 | +if (defined('JSON_PRETTY_PRINT')) { |
|
| 13 | 13 | $options = JSON_PRETTY_PRINT; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | |
| 17 | -$fields = $this->param( 'fields', [] ); |
|
| 17 | +$fields = $this->param('fields', []); |
|
| 18 | 18 | |
| 19 | -foreach( (array) $fields as $resource => $list ) { |
|
| 20 | - $fields[$resource] = array_flip( explode( ',', $list ) ); |
|
| 19 | +foreach ((array) $fields as $resource => $list) { |
|
| 20 | + $fields[$resource] = array_flip(explode(',', $list)); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | -$build = function( \Aimeos\MShop\Common\Item\Iface $item, array $childItems, array $listItems ) use ( $fields ) |
|
| 24 | +$build = function(\Aimeos\MShop\Common\Item\Iface $item, array $childItems, array $listItems) use ($fields) |
|
| 25 | 25 | { |
| 26 | - $id = strtoupper( $item->getId() ); |
|
| 26 | + $id = strtoupper($item->getId()); |
|
| 27 | 27 | $type = $item->getResourceType(); |
| 28 | - $params = array( 'resource' => $type, 'id' => $id ); |
|
| 29 | - $attributes = $item->toArray( true ); |
|
| 28 | + $params = array('resource' => $type, 'id' => $id); |
|
| 29 | + $attributes = $item->toArray(true); |
|
| 30 | 30 | |
| 31 | - $target = $this->config( 'admin/jsonadm/url/target' ); |
|
| 32 | - $cntl = $this->config( 'admin/jsonadm/url/controller', 'jsonadm' ); |
|
| 33 | - $action = $this->config( 'admin/jsonadm/url/action', 'get' ); |
|
| 34 | - $config = $this->config( 'admin/jsonadm/url/config', [] ); |
|
| 31 | + $target = $this->config('admin/jsonadm/url/target'); |
|
| 32 | + $cntl = $this->config('admin/jsonadm/url/controller', 'jsonadm'); |
|
| 33 | + $action = $this->config('admin/jsonadm/url/action', 'get'); |
|
| 34 | + $config = $this->config('admin/jsonadm/url/config', []); |
|
| 35 | 35 | |
| 36 | - if( isset( $fields[$type] ) ) { |
|
| 37 | - $attributes = array_intersect_key( $attributes, $fields[$type] ); |
|
| 36 | + if (isset($fields[$type])) { |
|
| 37 | + $attributes = array_intersect_key($attributes, $fields[$type]); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $result = array( |
@@ -42,35 +42,35 @@ discard block |
||
| 42 | 42 | 'type' => $type, |
| 43 | 43 | 'attributes' => $attributes, |
| 44 | 44 | 'links' => array( |
| 45 | - 'self' => $this->url( $target, $cntl, $action, $params, [], $config ) |
|
| 45 | + 'self' => $this->url($target, $cntl, $action, $params, [], $config) |
|
| 46 | 46 | ), |
| 47 | 47 | 'relationships' => [] |
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | - foreach( $childItems as $childItem ) |
|
| 50 | + foreach ($childItems as $childItem) |
|
| 51 | 51 | { |
| 52 | - if( $childItem->getParentId() == $id ) |
|
| 52 | + if ($childItem->getParentId() == $id) |
|
| 53 | 53 | { |
| 54 | 54 | $type = $childItem->getResourceType(); |
| 55 | - $result['relationships'][$type][] = array( 'data' => array( 'id' => $childItem->getId(), 'type' => $type ) ); |
|
| 55 | + $result['relationships'][$type][] = array('data' => array('id' => $childItem->getId(), 'type' => $type)); |
|
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - foreach( $listItems as $listId => $listItem ) |
|
| 59 | + foreach ($listItems as $listId => $listItem) |
|
| 60 | 60 | { |
| 61 | - if( $listItem->getParentId() == $id ) |
|
| 61 | + if ($listItem->getParentId() == $id) |
|
| 62 | 62 | { |
| 63 | 63 | $type = $listItem->getDomain(); |
| 64 | - $params = array( 'resource' => $listItem->getResourceType(), 'id' => $listId ); |
|
| 64 | + $params = array('resource' => $listItem->getResourceType(), 'id' => $listId); |
|
| 65 | 65 | |
| 66 | - $result['relationships'][$type][] = array( 'data' => array( |
|
| 66 | + $result['relationships'][$type][] = array('data' => array( |
|
| 67 | 67 | 'id' => $listItem->getRefId(), |
| 68 | 68 | 'type' => $type, |
| 69 | - 'attributes' => $listItem->toArray( true ), |
|
| 69 | + 'attributes' => $listItem->toArray(true), |
|
| 70 | 70 | 'links' => array( |
| 71 | - 'self' => $this->url( $target, $cntl, $action, $params, [], $config ) |
|
| 71 | + 'self' => $this->url($target, $cntl, $action, $params, [], $config) |
|
| 72 | 72 | ) |
| 73 | - ) ); |
|
| 73 | + )); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
@@ -78,21 +78,21 @@ discard block |
||
| 78 | 78 | }; |
| 79 | 79 | |
| 80 | 80 | |
| 81 | -$data = $this->get( 'data', [] ); |
|
| 82 | -$childItems = $this->get( 'childItems', [] ); |
|
| 83 | -$listItems = $this->get( 'listItems', [] ); |
|
| 81 | +$data = $this->get('data', []); |
|
| 82 | +$childItems = $this->get('childItems', []); |
|
| 83 | +$listItems = $this->get('listItems', []); |
|
| 84 | 84 | |
| 85 | -if( is_array( $data ) ) |
|
| 85 | +if (is_array($data)) |
|
| 86 | 86 | { |
| 87 | 87 | $response = []; |
| 88 | 88 | |
| 89 | - foreach( $data as $item ) { |
|
| 90 | - $response[] = $build( $item, $childItems, $listItems ); |
|
| 89 | + foreach ($data as $item) { |
|
| 90 | + $response[] = $build($item, $childItems, $listItems); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | -elseif( $data !== null ) |
|
| 93 | +elseif ($data !== null) |
|
| 94 | 94 | { |
| 95 | - $response = $build( $data, $childItems, $listItems ); |
|
| 95 | + $response = $build($data, $childItems, $listItems); |
|
| 96 | 96 | } |
| 97 | 97 | else |
| 98 | 98 | { |
@@ -100,4 +100,4 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | -echo json_encode( $response, $options ); |
|
| 104 | 103 | \ No newline at end of file |
| 104 | +echo json_encode($response, $options); |
|
| 105 | 105 | \ No newline at end of file |