@@ -1,28 +1,28 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $options = 0; |
| 4 | -if( defined( 'JSON_PRETTY_PRINT' ) ) { |
|
| 4 | +if (defined('JSON_PRETTY_PRINT')) { |
|
| 5 | 5 | $options = JSON_PRETTY_PRINT; |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
| 9 | -$build = function( \Aimeos\MW\View\Iface $view, array $items, array $fields ) |
|
| 9 | +$build = function(\Aimeos\MW\View\Iface $view, array $items, array $fields) |
|
| 10 | 10 | { |
| 11 | 11 | $list = []; |
| 12 | 12 | |
| 13 | - $target = $view->config( 'admin/jsonadm/url/target' ); |
|
| 14 | - $cntl = $view->config( 'admin/jsonadm/url/controller', 'jsonadm' ); |
|
| 15 | - $action = $view->config( 'admin/jsonadm/url/action', 'get' ); |
|
| 16 | - $config = $view->config( 'admin/jsonadm/url/config', [] ); |
|
| 13 | + $target = $view->config('admin/jsonadm/url/target'); |
|
| 14 | + $cntl = $view->config('admin/jsonadm/url/controller', 'jsonadm'); |
|
| 15 | + $action = $view->config('admin/jsonadm/url/action', 'get'); |
|
| 16 | + $config = $view->config('admin/jsonadm/url/config', []); |
|
| 17 | 17 | |
| 18 | - foreach( (array) $items as $item ) |
|
| 18 | + foreach ((array) $items as $item) |
|
| 19 | 19 | { |
| 20 | 20 | $id = $item->getId(); |
| 21 | 21 | $attributes = $item->toArray(); |
| 22 | 22 | $type = $item->getResourceType(); |
| 23 | 23 | |
| 24 | - if( isset( $fields[$type] ) ) { |
|
| 25 | - $attributes = array_intersect_key( $attributes, $fields[$type] ); |
|
| 24 | + if (isset($fields[$type])) { |
|
| 25 | + $attributes = array_intersect_key($attributes, $fields[$type]); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | $list[] = array( |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | 'type' => $type, |
| 31 | 31 | 'attributes' => $attributes, |
| 32 | 32 | 'links' => array( |
| 33 | - 'self' => $view->url( $target, $cntl, $action, array( 'resource' => $type, 'id' => $id ), [], $config ), |
|
| 33 | + 'self' => $view->url($target, $cntl, $action, array('resource' => $type, 'id' => $id), [], $config), |
|
| 34 | 34 | 'related' => array( |
| 35 | - 'href' => $view->url( $target, $cntl, $action, array( 'resource' => $type, 'id' => null ), [], $config ) |
|
| 35 | + 'href' => $view->url($target, $cntl, $action, array('resource' => $type, 'id' => null), [], $config) |
|
| 36 | 36 | ) |
| 37 | 37 | ) |
| 38 | 38 | ); |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | $response = []; |
| 46 | -$fields = $this->param( 'fields', [] ); |
|
| 46 | +$fields = $this->param('fields', []); |
|
| 47 | 47 | |
| 48 | -foreach( (array) $fields as $resource => $list ) { |
|
| 49 | - $fields[$resource] = array_flip( explode( ',', $list ) ); |
|
| 48 | +foreach ((array) $fields as $resource => $list) { |
|
| 49 | + $fields[$resource] = array_flip(explode(',', $list)); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | -$response = $build( $this, $this->get( 'childItems', [] ), $fields ); |
|
| 53 | -$response = array_merge( $response, $build( $this, $this->get( 'refItems', [] ), $fields ) ); |
|
| 52 | +$response = $build($this, $this->get('childItems', []), $fields); |
|
| 53 | +$response = array_merge($response, $build($this, $this->get('refItems', []), $fields)); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | -echo json_encode( $response, $options ); |
|
| 57 | 56 | \ No newline at end of file |
| 57 | +echo json_encode($response, $options); |
|
| 58 | 58 | \ No newline at end of file |
@@ -1,25 +1,25 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $options = 0; |
| 4 | -if( defined( 'JSON_PRETTY_PRINT' ) ) { |
|
| 4 | +if (defined('JSON_PRETTY_PRINT')) { |
|
| 5 | 5 | $options = JSON_PRETTY_PRINT; |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
| 9 | -$build = function( \Aimeos\MW\View\Iface $view, \Aimeos\MShop\Catalog\Item\Iface $item, array $fields, array $listItems ) |
|
| 9 | +$build = function(\Aimeos\MW\View\Iface $view, \Aimeos\MShop\Catalog\Item\Iface $item, array $fields, array $listItems) |
|
| 10 | 10 | { |
| 11 | 11 | $id = $item->getId(); |
| 12 | 12 | $attributes = $item->toArray(); |
| 13 | 13 | $type = $item->getResourceType(); |
| 14 | - $params = array( 'resource' => $item->getResourceType(), 'id' => $id ); |
|
| 14 | + $params = array('resource' => $item->getResourceType(), 'id' => $id); |
|
| 15 | 15 | |
| 16 | - $target = $view->config( 'admin/jsonadm/url/target' ); |
|
| 17 | - $cntl = $view->config( 'admin/jsonadm/url/controller', 'jsonadm' ); |
|
| 18 | - $action = $view->config( 'admin/jsonadm/url/action', 'get' ); |
|
| 19 | - $config = $view->config( 'admin/jsonadm/url/config', [] ); |
|
| 16 | + $target = $view->config('admin/jsonadm/url/target'); |
|
| 17 | + $cntl = $view->config('admin/jsonadm/url/controller', 'jsonadm'); |
|
| 18 | + $action = $view->config('admin/jsonadm/url/action', 'get'); |
|
| 19 | + $config = $view->config('admin/jsonadm/url/config', []); |
|
| 20 | 20 | |
| 21 | - if( isset( $fields[$type] ) ) { |
|
| 22 | - $attributes = array_intersect_key( $attributes, $fields[$type] ); |
|
| 21 | + if (isset($fields[$type])) { |
|
| 22 | + $attributes = array_intersect_key($attributes, $fields[$type]); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | $result = array( |
@@ -27,30 +27,30 @@ discard block |
||
| 27 | 27 | 'type' => $type, |
| 28 | 28 | 'attributes' => $attributes, |
| 29 | 29 | 'links' => array( |
| 30 | - 'self' => $view->url( $target, $cntl, $action, $params, [], $config ) |
|
| 30 | + 'self' => $view->url($target, $cntl, $action, $params, [], $config) |
|
| 31 | 31 | ), |
| 32 | 32 | 'relationships' => [] |
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | - foreach( $item->getChildren() as $childItem ) |
|
| 35 | + foreach ($item->getChildren() as $childItem) |
|
| 36 | 36 | { |
| 37 | 37 | $type = $childItem->getResourceType(); |
| 38 | - $result['relationships'][$type][] = array( 'data' => array( 'id' => $childItem->getId(), 'type' => $type ) ); |
|
| 38 | + $result['relationships'][$type][] = array('data' => array('id' => $childItem->getId(), 'type' => $type)); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - foreach( $listItems as $listId => $listItem ) |
|
| 41 | + foreach ($listItems as $listId => $listItem) |
|
| 42 | 42 | { |
| 43 | - if( $listItem->getParentId() == $id ) |
|
| 43 | + if ($listItem->getParentId() == $id) |
|
| 44 | 44 | { |
| 45 | 45 | $type = $listItem->getDomain(); |
| 46 | - $params = array( 'resource' => $listItem->getResourceType(), 'id' => $listId ); |
|
| 46 | + $params = array('resource' => $listItem->getResourceType(), 'id' => $listId); |
|
| 47 | 47 | |
| 48 | - $result['relationships'][$type][] = array( 'data' => array( |
|
| 48 | + $result['relationships'][$type][] = array('data' => array( |
|
| 49 | 49 | 'id' => $listItem->getRefId(), 'type' => $type, |
| 50 | 50 | 'attributes' => $listItem->toArray(), 'links' => array( |
| 51 | - 'self' => $view->url( $target, $cntl, $action, $params, [], $config ) |
|
| 51 | + 'self' => $view->url($target, $cntl, $action, $params, [], $config) |
|
| 52 | 52 | ) |
| 53 | - ) ); |
|
| 53 | + )); |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
@@ -58,27 +58,27 @@ discard block |
||
| 58 | 58 | }; |
| 59 | 59 | |
| 60 | 60 | |
| 61 | -$fields = $this->param( 'fields', [] ); |
|
| 61 | +$fields = $this->param('fields', []); |
|
| 62 | 62 | |
| 63 | -foreach( (array) $fields as $resource => $list ) { |
|
| 64 | - $fields[$resource] = array_flip( explode( ',', $list ) ); |
|
| 63 | +foreach ((array) $fields as $resource => $list) { |
|
| 64 | + $fields[$resource] = array_flip(explode(',', $list)); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | |
| 68 | -$data = $this->get( 'data', [] ); |
|
| 69 | -$listItems = $this->get( 'listItems', [] ); |
|
| 68 | +$data = $this->get('data', []); |
|
| 69 | +$listItems = $this->get('listItems', []); |
|
| 70 | 70 | |
| 71 | -if( is_array( $data ) ) |
|
| 71 | +if (is_array($data)) |
|
| 72 | 72 | { |
| 73 | 73 | $response = []; |
| 74 | 74 | |
| 75 | - foreach( $data as $item ) { |
|
| 76 | - $response[] = $build( $this, $item, $fields, $listItems ); |
|
| 75 | + foreach ($data as $item) { |
|
| 76 | + $response[] = $build($this, $item, $fields, $listItems); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | -elseif( $data !== null ) |
|
| 79 | +elseif ($data !== null) |
|
| 80 | 80 | { |
| 81 | - $response = $build( $this, $data, $fields, $listItems ); |
|
| 81 | + $response = $build($this, $data, $fields, $listItems); |
|
| 82 | 82 | } |
| 83 | 83 | else |
| 84 | 84 | { |
@@ -86,4 +86,4 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | |
| 89 | -echo json_encode( $response, $options ); |
|
| 90 | 89 | \ No newline at end of file |
| 90 | +echo json_encode($response, $options); |
|
| 91 | 91 | \ No newline at end of file |
@@ -1,9 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $options = 0; |
| 4 | -if( defined( 'JSON_PRETTY_PRINT' ) ) { |
|
| 4 | +if (defined('JSON_PRETTY_PRINT')) { |
|
| 5 | 5 | $options = JSON_PRETTY_PRINT; |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
| 9 | -echo json_encode( $this->get( 'errors', [] ), $options ); |
|
| 10 | 9 | \ No newline at end of file |
| 10 | +echo json_encode($this->get('errors', []), $options); |
|
| 11 | 11 | \ No newline at end of file |
@@ -1,30 +1,30 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -$target = $this->config( 'admin/jsonadm/url/target' ); |
|
| 4 | -$cntl = $this->config( 'admin/jsonadm/url/controller', 'jsonadm' ); |
|
| 5 | -$action = $this->config( 'admin/jsonadm/url/action', 'get' ); |
|
| 6 | -$config = $this->config( 'admin/jsonadm/url/config', [] ); |
|
| 3 | +$target = $this->config('admin/jsonadm/url/target'); |
|
| 4 | +$cntl = $this->config('admin/jsonadm/url/controller', 'jsonadm'); |
|
| 5 | +$action = $this->config('admin/jsonadm/url/action', 'get'); |
|
| 6 | +$config = $this->config('admin/jsonadm/url/config', []); |
|
| 7 | 7 | |
| 8 | 8 | $resources = $attributes = []; |
| 9 | -$site = $this->param( 'site', 'default' ); |
|
| 9 | +$site = $this->param('site', 'default'); |
|
| 10 | 10 | |
| 11 | -foreach( $this->get( 'resources', [] ) as $resource ) { |
|
| 12 | - $resources[$resource] = $this->url( $target, $cntl, $action, array( 'site' => $site, 'resource' => $resource, 'id' => '' ), [], $config ); |
|
| 11 | +foreach ($this->get('resources', []) as $resource) { |
|
| 12 | + $resources[$resource] = $this->url($target, $cntl, $action, array('site' => $site, 'resource' => $resource, 'id' => ''), [], $config); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | -foreach( $this->get( 'attributes', [] ) as $attr ) { |
|
| 15 | +foreach ($this->get('attributes', []) as $attr) { |
|
| 16 | 16 | $attributes[$attr->getCode()] = $attr->toArray(); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | ?> |
| 20 | 20 | { |
| 21 | 21 | "meta": { |
| 22 | - "prefix": <?php echo json_encode( $this->get( 'prefix' ) ); ?>, |
|
| 23 | - "resources": <?php echo json_encode( $resources ); ?>, |
|
| 24 | - "attributes": <?php echo json_encode( $attributes ); ?> |
|
| 22 | + "prefix": <?php echo json_encode($this->get('prefix')); ?>, |
|
| 23 | + "resources": <?php echo json_encode($resources); ?>, |
|
| 24 | + "attributes": <?php echo json_encode($attributes); ?> |
|
| 25 | 25 | } |
| 26 | -<?php if( isset( $this->errors ) ) : ?> |
|
| 27 | - ,"errors": <?php echo $this->partial( $this->config( 'admin/jsonadm/partials/template-errors', 'partials/errors-standard.php' ), array( 'errors' => $this->errors ) ); ?> |
|
| 26 | +<?php if (isset($this->errors)) : ?> |
|
| 27 | + ,"errors": <?php echo $this->partial($this->config('admin/jsonadm/partials/template-errors', 'partials/errors-standard.php'), array('errors' => $this->errors)); ?> |
|
| 28 | 28 | <?php endif; ?> |
| 29 | 29 | |
| 30 | 30 | } |