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