1 | <?php |
||
2 | |||
3 | namespace GeodisBundle\Model\Base; |
||
4 | |||
5 | /** |
||
6 | * Author: Nils méchin <[email protected]> |
||
7 | * Author: Maxime Lambot <[email protected]>. |
||
8 | */ |
||
9 | abstract class Model |
||
10 | { |
||
11 | public function toJson($skipNullValues = null) |
||
0 ignored issues
–
show
|
|||
12 | { |
||
13 | $json = array(); |
||
14 | foreach ($this as $key => $value) { |
||
15 | if ('url' === $key or 'primaryKey' === $key) { |
||
16 | continue; |
||
17 | } |
||
18 | |||
19 | if (null === $value) { |
||
20 | continue; |
||
21 | } |
||
22 | |||
23 | // If an array of entity is passed to the json, it squizzed it, |
||
24 | // rebuild an proper array without being entity and pass it to the $json array |
||
25 | if ('listEnvois' == $key) { |
||
26 | $value = $this->encodeLines($value); |
||
27 | } |
||
28 | |||
29 | $json[$key] = $value; |
||
30 | } |
||
31 | |||
32 | return json_encode($json); |
||
33 | } |
||
34 | |||
35 | private function encodeLines($value) |
||
36 | { |
||
37 | $salesOrderLines = array(); |
||
38 | foreach ($value as $line) { |
||
39 | $salesOrderLine = array(); |
||
40 | foreach ($line as $entryKey => $entry) { |
||
41 | if ('url' === $entryKey or 'primaryKey' === $entryKey) { |
||
42 | continue; |
||
43 | } |
||
44 | if (null === $entry) { |
||
45 | continue; |
||
46 | } |
||
47 | |||
48 | /* |
||
49 | if ('destinataire' == $entryKey) { |
||
50 | $entry = $this->encodeSubLines($value); |
||
51 | } |
||
52 | if ('expediteur' == $entryKey) { |
||
53 | $entry = $this->encodeSubLines($value); |
||
54 | } |
||
55 | if ('listUmgs' == $entryKey) { |
||
56 | $entry = $this->encodeSubLines($value); |
||
57 | } |
||
58 | */ |
||
59 | $salesOrderLine[$entryKey] = $entry; |
||
60 | } |
||
61 | array_push($salesOrderLines, $salesOrderLine); |
||
62 | } |
||
63 | |||
64 | return $salesOrderLines; |
||
65 | } |
||
66 | |||
67 | private function encodeSubLines($value) |
||
0 ignored issues
–
show
|
|||
68 | { |
||
69 | $salesOrderLines = array(); |
||
70 | foreach ($value as $line) { |
||
71 | $salesOrderLine = array(); |
||
72 | foreach ($line as $entryKey => $entry) { |
||
73 | if ('url' === $entryKey or 'primaryKey' === $entryKey) { |
||
74 | continue; |
||
75 | } |
||
76 | if (null === $entry) { |
||
77 | continue; |
||
78 | } |
||
79 | $salesOrderLine[$entryKey] = $entry; |
||
80 | } |
||
81 | array_push($salesOrderLines, $salesOrderLine); |
||
82 | } |
||
83 | |||
84 | return $salesOrderLines; |
||
85 | } |
||
86 | } |
||
87 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.