@@ -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\Common\Item\Iface $item, array $fields, array $childItems, array $listItems ) |
|
9 | +$build = function(\Aimeos\MW\View\Iface $view, \Aimeos\MShop\Common\Item\Iface $item, array $fields, array $childItems, 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', array() ); |
|
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', array()); |
|
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,31 +27,31 @@ discard block |
||
27 | 27 | 'type' => $type, |
28 | 28 | 'attributes' => $attributes, |
29 | 29 | 'links' => array( |
30 | - 'self' => $view->url( $target, $cntl, $action, $params, array(), $config ) |
|
30 | + 'self' => $view->url($target, $cntl, $action, $params, array(), $config) |
|
31 | 31 | ), |
32 | 32 | 'relationships' => array() |
33 | 33 | ); |
34 | 34 | |
35 | - foreach( $childItems as $childItem ) |
|
35 | + foreach ($childItems as $childItem) |
|
36 | 36 | { |
37 | - if( $childItem->getParentId() == $id ) |
|
37 | + if ($childItem->getParentId() == $id) |
|
38 | 38 | { |
39 | 39 | $type = $childItem->getResourceType(); |
40 | - $result['relationships'][$type][] = array( 'data' => array( 'id' => $childItem->getId(), 'type' => $type ) ); |
|
40 | + $result['relationships'][$type][] = array('data' => array('id' => $childItem->getId(), 'type' => $type)); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | - foreach( $listItems as $listId => $listItem ) |
|
44 | + foreach ($listItems as $listId => $listItem) |
|
45 | 45 | { |
46 | - if( $listItem->getParentId() == $id ) |
|
46 | + if ($listItem->getParentId() == $id) |
|
47 | 47 | { |
48 | 48 | $type = $listItem->getDomain(); |
49 | - $params = array( 'resource' => $listItem->getResourceType(), 'id' => $listId ); |
|
49 | + $params = array('resource' => $listItem->getResourceType(), 'id' => $listId); |
|
50 | 50 | |
51 | 51 | $result['relationships'][$type][] = array( |
52 | - 'data' => array( 'id' => $listItem->getRefId(), 'type' => $type, |
|
52 | + 'data' => array('id' => $listItem->getRefId(), 'type' => $type, |
|
53 | 53 | 'attributes' => $listItem->toArray(), 'links' => array( |
54 | - 'self' => $view->url( $target, $cntl, $action, $params, array(), $config ) |
|
54 | + 'self' => $view->url($target, $cntl, $action, $params, array(), $config) |
|
55 | 55 | ) |
56 | 56 | ) ); |
57 | 57 | } |
@@ -61,28 +61,28 @@ discard block |
||
61 | 61 | }; |
62 | 62 | |
63 | 63 | |
64 | -$fields = $this->param( 'fields', array() ); |
|
64 | +$fields = $this->param('fields', array()); |
|
65 | 65 | |
66 | -foreach( (array) $fields as $resource => $list ) { |
|
67 | - $fields[$resource] = array_flip( explode( ',', $list ) ); |
|
66 | +foreach ((array) $fields as $resource => $list) { |
|
67 | + $fields[$resource] = array_flip(explode(',', $list)); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
71 | -$data = $this->get( 'data', array() ); |
|
72 | -$childItems = $this->get( 'childItems', array() ); |
|
73 | -$listItems = $this->get( 'listItems', array() ); |
|
71 | +$data = $this->get('data', array()); |
|
72 | +$childItems = $this->get('childItems', array()); |
|
73 | +$listItems = $this->get('listItems', array()); |
|
74 | 74 | |
75 | -if( is_array( $data ) ) |
|
75 | +if (is_array($data)) |
|
76 | 76 | { |
77 | 77 | $response = array(); |
78 | 78 | |
79 | - foreach( $data as $item ) { |
|
80 | - $response[] = $build( $this, $item, $fields, $childItems, $listItems ); |
|
79 | + foreach ($data as $item) { |
|
80 | + $response[] = $build($this, $item, $fields, $childItems, $listItems); |
|
81 | 81 | } |
82 | 82 | } |
83 | -elseif( $data !== null ) |
|
83 | +elseif ($data !== null) |
|
84 | 84 | { |
85 | - $response = $build( $this, $data, $fields, $childItems, $listItems ); |
|
85 | + $response = $build($this, $data, $fields, $childItems, $listItems); |
|
86 | 86 | } |
87 | 87 | else |
88 | 88 | { |
@@ -90,4 +90,4 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | |
93 | -echo json_encode( $response, $options ); |
|
94 | 93 | \ No newline at end of file |
94 | +echo json_encode($response, $options); |
|
95 | 95 | \ No newline at end of file |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | $templatePaths = \TestHelperJadm::getJsonadmPaths(); |
23 | 23 | $this->view = $this->context->getView(); |
24 | 24 | |
25 | - $this->object = new \Aimeos\Admin\JsonAdm\Product\Standard( $this->context, $this->view, $templatePaths, 'product' ); |
|
25 | + $this->object = new \Aimeos\Admin\JsonAdm\Product\Standard($this->context, $this->view, $templatePaths, 'product'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | |
@@ -30,34 +30,34 @@ discard block |
||
30 | 30 | { |
31 | 31 | $params = array( |
32 | 32 | 'filter' => array( |
33 | - '==' => array( 'product.code' => 'CNE' ) |
|
33 | + '==' => array('product.code' => 'CNE') |
|
34 | 34 | ), |
35 | 35 | 'include' => 'text,product,product/property,product/stock' |
36 | 36 | ); |
37 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
38 | - $this->view->addHelper( 'param', $helper ); |
|
37 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
38 | + $this->view->addHelper('param', $helper); |
|
39 | 39 | |
40 | 40 | $header = array(); |
41 | 41 | $status = 500; |
42 | 42 | |
43 | - $result = json_decode( $this->object->get( '', $header, $status ), true ); |
|
44 | - |
|
45 | - $this->assertEquals( 200, $status ); |
|
46 | - $this->assertEquals( 1, count( $header ) ); |
|
47 | - $this->assertEquals( 1, $result['meta']['total'] ); |
|
48 | - $this->assertEquals( 1, count( $result['data'] ) ); |
|
49 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
50 | - $this->assertEquals( 6, count( $result['data'][0]['relationships']['text'] ) ); |
|
51 | - $this->assertArrayHaskey( 'self', $result['data'][0]['relationships']['text'][0]['data']['links'] ); |
|
52 | - $this->assertEquals( 5, count( $result['data'][0]['relationships']['product'] ) ); |
|
53 | - $this->assertArrayHaskey( 'self', $result['data'][0]['relationships']['product'][0]['data']['links'] ); |
|
54 | - $this->assertEquals( 4, count( $result['data'][0]['relationships']['product/property'] ) ); |
|
55 | - $this->assertEquals( 1, count( $result['data'][0]['relationships']['product/stock'] ) ); |
|
56 | - $this->assertEquals( 15, count( $result['included'] ) ); |
|
57 | - $this->assertEquals( 'product/property', $result['included'][0]['type'] ); |
|
58 | - $this->assertArrayHaskey( 'self', $result['included'][0]['links'] ); |
|
59 | - $this->assertArrayHaskey( 'related', $result['included'][0]['links'] ); |
|
60 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
43 | + $result = json_decode($this->object->get('', $header, $status), true); |
|
44 | + |
|
45 | + $this->assertEquals(200, $status); |
|
46 | + $this->assertEquals(1, count($header)); |
|
47 | + $this->assertEquals(1, $result['meta']['total']); |
|
48 | + $this->assertEquals(1, count($result['data'])); |
|
49 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
50 | + $this->assertEquals(6, count($result['data'][0]['relationships']['text'])); |
|
51 | + $this->assertArrayHaskey('self', $result['data'][0]['relationships']['text'][0]['data']['links']); |
|
52 | + $this->assertEquals(5, count($result['data'][0]['relationships']['product'])); |
|
53 | + $this->assertArrayHaskey('self', $result['data'][0]['relationships']['product'][0]['data']['links']); |
|
54 | + $this->assertEquals(4, count($result['data'][0]['relationships']['product/property'])); |
|
55 | + $this->assertEquals(1, count($result['data'][0]['relationships']['product/stock'])); |
|
56 | + $this->assertEquals(15, count($result['included'])); |
|
57 | + $this->assertEquals('product/property', $result['included'][0]['type']); |
|
58 | + $this->assertArrayHaskey('self', $result['included'][0]['links']); |
|
59 | + $this->assertArrayHaskey('related', $result['included'][0]['links']); |
|
60 | + $this->assertArrayNotHasKey('errors', $result); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
@@ -70,22 +70,22 @@ discard block |
||
70 | 70 | 'sort' => 'product.id', |
71 | 71 | 'include' => 'product,product/stock' |
72 | 72 | ); |
73 | - $helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params ); |
|
74 | - $this->view->addHelper( 'param', $helper ); |
|
73 | + $helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params); |
|
74 | + $this->view->addHelper('param', $helper); |
|
75 | 75 | |
76 | 76 | $header = array(); |
77 | 77 | $status = 500; |
78 | 78 | |
79 | - $result = json_decode( $this->object->get( '', $header, $status ), true ); |
|
80 | - |
|
81 | - $this->assertEquals( 200, $status ); |
|
82 | - $this->assertEquals( 1, count( $header ) ); |
|
83 | - $this->assertEquals( 28, $result['meta']['total'] ); |
|
84 | - $this->assertEquals( 25, count( $result['data'] ) ); |
|
85 | - $this->assertEquals( 'product', $result['data'][0]['type'] ); |
|
86 | - $this->assertEquals( 2, count( $result['data'][0]['attributes'] ) ); |
|
87 | - $this->assertEquals( 5, count( $result['data'][0]['relationships']['product'] ) ); |
|
88 | - $this->assertEquals( 27, count( $result['included'] ) ); |
|
89 | - $this->assertArrayNotHasKey( 'errors', $result ); |
|
79 | + $result = json_decode($this->object->get('', $header, $status), true); |
|
80 | + |
|
81 | + $this->assertEquals(200, $status); |
|
82 | + $this->assertEquals(1, count($header)); |
|
83 | + $this->assertEquals(28, $result['meta']['total']); |
|
84 | + $this->assertEquals(25, count($result['data'])); |
|
85 | + $this->assertEquals('product', $result['data'][0]['type']); |
|
86 | + $this->assertEquals(2, count($result['data'][0]['attributes'])); |
|
87 | + $this->assertEquals(5, count($result['data'][0]['relationships']['product'])); |
|
88 | + $this->assertEquals(27, count($result['included'])); |
|
89 | + $this->assertArrayNotHasKey('errors', $result); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | \ No newline at end of file |