1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the timechimp bundle package. |
7
|
|
|
* (c) Connect Holland. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace ConnectHolland\TimechimpBundle\Api\Normalizer; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
13
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; |
14
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
15
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; |
16
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; |
17
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
18
|
|
|
|
19
|
|
|
class MileageNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface |
20
|
|
|
{ |
21
|
|
|
use DenormalizerAwareTrait; |
22
|
|
|
use NormalizerAwareTrait; |
23
|
|
|
|
24
|
|
|
public function supportsDenormalization($data, $type, $format = null) |
25
|
|
|
{ |
26
|
|
|
return $type === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Mileage'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function supportsNormalization($data, $format = null) |
30
|
|
|
{ |
31
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Mileage'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function denormalize($data, $class, $format = null, array $context = []) |
35
|
|
|
{ |
36
|
|
|
if (!is_object($data)) { |
37
|
|
|
return null; |
38
|
|
|
} |
39
|
|
|
$object = new \ConnectHolland\TimechimpBundle\Api\Model\Mileage(); |
40
|
|
|
if (property_exists($data, 'id') && $data->{'id'} !== null) { |
41
|
|
|
$object->setId($data->{'id'}); |
42
|
|
|
} elseif (property_exists($data, 'id') && $data->{'id'} === null) { |
43
|
|
|
$object->setId(null); |
44
|
|
|
} |
45
|
|
|
if (property_exists($data, 'customerId') && $data->{'customerId'} !== null) { |
46
|
|
|
$object->setCustomerId($data->{'customerId'}); |
47
|
|
|
} elseif (property_exists($data, 'customerId') && $data->{'customerId'} === null) { |
48
|
|
|
$object->setCustomerId(null); |
49
|
|
|
} |
50
|
|
|
if (property_exists($data, 'customerName') && $data->{'customerName'} !== null) { |
51
|
|
|
$object->setCustomerName($data->{'customerName'}); |
52
|
|
|
} elseif (property_exists($data, 'customerName') && $data->{'customerName'} === null) { |
53
|
|
|
$object->setCustomerName(null); |
54
|
|
|
} |
55
|
|
|
if (property_exists($data, 'projectId') && $data->{'projectId'} !== null) { |
56
|
|
|
$object->setProjectId($data->{'projectId'}); |
57
|
|
|
} elseif (property_exists($data, 'projectId') && $data->{'projectId'} === null) { |
58
|
|
|
$object->setProjectId(null); |
59
|
|
|
} |
60
|
|
|
if (property_exists($data, 'projectName') && $data->{'projectName'} !== null) { |
61
|
|
|
$object->setProjectName($data->{'projectName'}); |
62
|
|
|
} elseif (property_exists($data, 'projectName') && $data->{'projectName'} === null) { |
63
|
|
|
$object->setProjectName(null); |
64
|
|
|
} |
65
|
|
|
if (property_exists($data, 'vehicleId') && $data->{'vehicleId'} !== null) { |
66
|
|
|
$object->setVehicleId($data->{'vehicleId'}); |
67
|
|
|
} elseif (property_exists($data, 'vehicleId') && $data->{'vehicleId'} === null) { |
68
|
|
|
$object->setVehicleId(null); |
69
|
|
|
} |
70
|
|
|
if (property_exists($data, 'vehicleName') && $data->{'vehicleName'} !== null) { |
71
|
|
|
$object->setVehicleName($data->{'vehicleName'}); |
72
|
|
|
} elseif (property_exists($data, 'vehicleName') && $data->{'vehicleName'} === null) { |
73
|
|
|
$object->setVehicleName(null); |
74
|
|
|
} |
75
|
|
|
if (property_exists($data, 'userId') && $data->{'userId'} !== null) { |
76
|
|
|
$object->setUserId($data->{'userId'}); |
77
|
|
|
} elseif (property_exists($data, 'userId') && $data->{'userId'} === null) { |
78
|
|
|
$object->setUserId(null); |
79
|
|
|
} |
80
|
|
|
if (property_exists($data, 'userDisplayName') && $data->{'userDisplayName'} !== null) { |
81
|
|
|
$object->setUserDisplayName($data->{'userDisplayName'}); |
82
|
|
|
} elseif (property_exists($data, 'userDisplayName') && $data->{'userDisplayName'} === null) { |
83
|
|
|
$object->setUserDisplayName(null); |
84
|
|
|
} |
85
|
|
|
if (property_exists($data, 'date') && $data->{'date'} !== null) { |
86
|
|
|
$object->setDate(\DateTime::createFromFormat('Y-m-d\\TH:i:s', $data->{'date'})); |
|
|
|
|
87
|
|
|
} elseif (property_exists($data, 'date') && $data->{'date'} === null) { |
88
|
|
|
$object->setDate(null); |
89
|
|
|
} |
90
|
|
|
if (property_exists($data, 'fromAddress') && $data->{'fromAddress'} !== null) { |
91
|
|
|
$object->setFromAddress($data->{'fromAddress'}); |
92
|
|
|
} elseif (property_exists($data, 'fromAddress') && $data->{'fromAddress'} === null) { |
93
|
|
|
$object->setFromAddress(null); |
94
|
|
|
} |
95
|
|
|
if (property_exists($data, 'toAddress') && $data->{'toAddress'} !== null) { |
96
|
|
|
$object->setToAddress($data->{'toAddress'}); |
97
|
|
|
} elseif (property_exists($data, 'toAddress') && $data->{'toAddress'} === null) { |
98
|
|
|
$object->setToAddress(null); |
99
|
|
|
} |
100
|
|
|
if (property_exists($data, 'notes') && $data->{'notes'} !== null) { |
101
|
|
|
$object->setNotes($data->{'notes'}); |
102
|
|
|
} elseif (property_exists($data, 'notes') && $data->{'notes'} === null) { |
103
|
|
|
$object->setNotes(null); |
104
|
|
|
} |
105
|
|
|
if (property_exists($data, 'distance') && $data->{'distance'} !== null) { |
106
|
|
|
$object->setDistance($data->{'distance'}); |
107
|
|
|
} elseif (property_exists($data, 'distance') && $data->{'distance'} === null) { |
108
|
|
|
$object->setDistance(null); |
109
|
|
|
} |
110
|
|
|
if (property_exists($data, 'billable') && $data->{'billable'} !== null) { |
111
|
|
|
$object->setBillable($data->{'billable'}); |
112
|
|
|
} elseif (property_exists($data, 'billable') && $data->{'billable'} === null) { |
113
|
|
|
$object->setBillable(null); |
114
|
|
|
} |
115
|
|
|
if (property_exists($data, 'type') && $data->{'type'} !== null) { |
116
|
|
|
$object->setType($data->{'type'}); |
117
|
|
|
} elseif (property_exists($data, 'type') && $data->{'type'} === null) { |
118
|
|
|
$object->setType(null); |
119
|
|
|
} |
120
|
|
|
if (property_exists($data, 'status') && $data->{'status'} !== null) { |
121
|
|
|
$object->setStatus($data->{'status'}); |
122
|
|
|
} elseif (property_exists($data, 'status') && $data->{'status'} === null) { |
123
|
|
|
$object->setStatus(null); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $object; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function normalize($object, $format = null, array $context = []) |
130
|
|
|
{ |
131
|
|
|
$data = new \stdClass(); |
132
|
|
|
if (null !== $object->getId()) { |
133
|
|
|
$data->{'id'} = $object->getId(); |
134
|
|
|
} else { |
135
|
|
|
$data->{'id'} = null; |
136
|
|
|
} |
137
|
|
|
if (null !== $object->getCustomerId()) { |
138
|
|
|
$data->{'customerId'} = $object->getCustomerId(); |
139
|
|
|
} else { |
140
|
|
|
$data->{'customerId'} = null; |
141
|
|
|
} |
142
|
|
|
if (null !== $object->getCustomerName()) { |
143
|
|
|
$data->{'customerName'} = $object->getCustomerName(); |
144
|
|
|
} else { |
145
|
|
|
$data->{'customerName'} = null; |
146
|
|
|
} |
147
|
|
|
if (null !== $object->getProjectId()) { |
148
|
|
|
$data->{'projectId'} = $object->getProjectId(); |
149
|
|
|
} else { |
150
|
|
|
$data->{'projectId'} = null; |
151
|
|
|
} |
152
|
|
|
if (null !== $object->getProjectName()) { |
153
|
|
|
$data->{'projectName'} = $object->getProjectName(); |
154
|
|
|
} else { |
155
|
|
|
$data->{'projectName'} = null; |
156
|
|
|
} |
157
|
|
|
if (null !== $object->getVehicleId()) { |
158
|
|
|
$data->{'vehicleId'} = $object->getVehicleId(); |
159
|
|
|
} else { |
160
|
|
|
$data->{'vehicleId'} = null; |
161
|
|
|
} |
162
|
|
|
if (null !== $object->getVehicleName()) { |
163
|
|
|
$data->{'vehicleName'} = $object->getVehicleName(); |
164
|
|
|
} else { |
165
|
|
|
$data->{'vehicleName'} = null; |
166
|
|
|
} |
167
|
|
|
if (null !== $object->getUserId()) { |
168
|
|
|
$data->{'userId'} = $object->getUserId(); |
169
|
|
|
} else { |
170
|
|
|
$data->{'userId'} = null; |
171
|
|
|
} |
172
|
|
|
if (null !== $object->getUserDisplayName()) { |
173
|
|
|
$data->{'userDisplayName'} = $object->getUserDisplayName(); |
174
|
|
|
} else { |
175
|
|
|
$data->{'userDisplayName'} = null; |
176
|
|
|
} |
177
|
|
|
if (null !== $object->getDate()) { |
178
|
|
|
$data->{'date'} = $object->getDate()->format('Y-m-d\\TH:i:s'); |
179
|
|
|
} else { |
180
|
|
|
$data->{'date'} = null; |
181
|
|
|
} |
182
|
|
|
if (null !== $object->getFromAddress()) { |
183
|
|
|
$data->{'fromAddress'} = $object->getFromAddress(); |
184
|
|
|
} else { |
185
|
|
|
$data->{'fromAddress'} = null; |
186
|
|
|
} |
187
|
|
|
if (null !== $object->getToAddress()) { |
188
|
|
|
$data->{'toAddress'} = $object->getToAddress(); |
189
|
|
|
} else { |
190
|
|
|
$data->{'toAddress'} = null; |
191
|
|
|
} |
192
|
|
|
if (null !== $object->getNotes()) { |
193
|
|
|
$data->{'notes'} = $object->getNotes(); |
194
|
|
|
} else { |
195
|
|
|
$data->{'notes'} = null; |
196
|
|
|
} |
197
|
|
|
if (null !== $object->getDistance()) { |
198
|
|
|
$data->{'distance'} = $object->getDistance(); |
199
|
|
|
} else { |
200
|
|
|
$data->{'distance'} = null; |
201
|
|
|
} |
202
|
|
|
if (null !== $object->getBillable()) { |
203
|
|
|
$data->{'billable'} = $object->getBillable(); |
204
|
|
|
} else { |
205
|
|
|
$data->{'billable'} = null; |
206
|
|
|
} |
207
|
|
|
if (null !== $object->getType()) { |
208
|
|
|
$data->{'type'} = $object->getType(); |
209
|
|
|
} else { |
210
|
|
|
$data->{'type'} = null; |
211
|
|
|
} |
212
|
|
|
if (null !== $object->getStatus()) { |
213
|
|
|
$data->{'status'} = $object->getStatus(); |
214
|
|
|
} else { |
215
|
|
|
$data->{'status'} = null; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
return $data; |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|