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\Exception\InvalidArgumentException; |
13
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; |
14
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait; |
15
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
16
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; |
17
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; |
18
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
19
|
|
|
|
20
|
|
|
class ProjectNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface |
21
|
|
|
{ |
22
|
|
|
use DenormalizerAwareTrait; |
23
|
|
|
use NormalizerAwareTrait; |
24
|
|
|
|
25
|
|
|
public function supportsDenormalization($data, $type, $format = null) |
26
|
|
|
{ |
27
|
|
|
return $type === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Project'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function supportsNormalization($data, $format = null) |
31
|
|
|
{ |
32
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Project'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function denormalize($data, $class, $format = null, array $context = []) |
36
|
|
|
{ |
37
|
|
|
if (!is_object($data)) { |
38
|
|
|
throw new InvalidArgumentException(sprintf('Given $data is not an object (%s given). We need an object in order to continue denormalize method.', gettype($data))); |
39
|
|
|
} |
40
|
|
|
$object = new \ConnectHolland\TimechimpBundle\Api\Model\Project(); |
41
|
|
|
if (property_exists($data, 'remainingBudgetHours')) { |
42
|
|
|
$object->setRemainingBudgetHours($data->{'remainingBudgetHours'}); |
43
|
|
|
} |
44
|
|
|
if (property_exists($data, 'tagIds')) { |
45
|
|
|
$values = []; |
46
|
|
|
foreach ($data->{'tagIds'} as $value) { |
47
|
|
|
$values[] = $value; |
48
|
|
|
} |
49
|
|
|
$object->setTagIds($values); |
50
|
|
|
} |
51
|
|
|
if (property_exists($data, 'tagNames')) { |
52
|
|
|
$values_1 = []; |
53
|
|
|
foreach ($data->{'tagNames'} as $value_1) { |
54
|
|
|
$values_1[] = $value_1; |
55
|
|
|
} |
56
|
|
|
$object->setTagNames($values_1); |
57
|
|
|
} |
58
|
|
|
if (property_exists($data, 'unspecified')) { |
59
|
|
|
$object->setUnspecified($data->{'unspecified'}); |
60
|
|
|
} |
61
|
|
|
if (property_exists($data, 'invoiceDate')) { |
62
|
|
|
$object->setInvoiceDate(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'invoiceDate'})); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
if (property_exists($data, 'invoiceInInstallments')) { |
65
|
|
|
$object->setInvoiceInInstallments($data->{'invoiceInInstallments'}); |
66
|
|
|
} |
67
|
|
|
if (property_exists($data, 'budgetNotificationPercentage')) { |
68
|
|
|
$object->setBudgetNotificationPercentage($data->{'budgetNotificationPercentage'}); |
69
|
|
|
} |
70
|
|
|
if (property_exists($data, 'budgetNotificationHasBeenSent')) { |
71
|
|
|
$object->setBudgetNotificationHasBeenSent($data->{'budgetNotificationHasBeenSent'}); |
72
|
|
|
} |
73
|
|
|
if (property_exists($data, 'clientId')) { |
74
|
|
|
$object->setClientId($data->{'clientId'}); |
75
|
|
|
} |
76
|
|
|
if (property_exists($data, 'invoiceStatus')) { |
77
|
|
|
$object->setInvoiceStatus($data->{'invoiceStatus'}); |
78
|
|
|
} |
79
|
|
|
if (property_exists($data, 'invoiceId')) { |
80
|
|
|
$object->setInvoiceId($data->{'invoiceId'}); |
81
|
|
|
} |
82
|
|
|
if (property_exists($data, 'color')) { |
83
|
|
|
$object->setColor($data->{'color'}); |
84
|
|
|
} |
85
|
|
|
if (property_exists($data, 'visibleOnSchedule')) { |
86
|
|
|
$object->setVisibleOnSchedule($data->{'visibleOnSchedule'}); |
87
|
|
|
} |
88
|
|
|
if (property_exists($data, 'externalUrl')) { |
89
|
|
|
$object->setExternalUrl($data->{'externalUrl'}); |
90
|
|
|
} |
91
|
|
|
if (property_exists($data, 'externalName')) { |
92
|
|
|
$object->setExternalName($data->{'externalName'}); |
93
|
|
|
} |
94
|
|
|
if (property_exists($data, 'invoiceReference')) { |
95
|
|
|
$object->setInvoiceReference($data->{'invoiceReference'}); |
96
|
|
|
} |
97
|
|
|
if (property_exists($data, 'projectTasks')) { |
98
|
|
|
$values_2 = []; |
99
|
|
|
foreach ($data->{'projectTasks'} as $value_2) { |
100
|
|
|
$values_2[] = $this->denormalizer->denormalize($value_2, 'ConnectHolland\\TimechimpBundle\\Api\\Model\\ProjectTask', 'json', $context); |
101
|
|
|
} |
102
|
|
|
$object->setProjectTasks($values_2); |
103
|
|
|
} |
104
|
|
|
if (property_exists($data, 'projectUsers')) { |
105
|
|
|
$values_3 = []; |
106
|
|
|
foreach ($data->{'projectUsers'} as $value_3) { |
107
|
|
|
$values_3[] = $this->denormalizer->denormalize($value_3, 'ConnectHolland\\TimechimpBundle\\Api\\Model\\ProjectUser', 'json', $context); |
108
|
|
|
} |
109
|
|
|
$object->setProjectUsers($values_3); |
110
|
|
|
} |
111
|
|
|
if (property_exists($data, 'id')) { |
112
|
|
|
$object->setId($data->{'id'}); |
113
|
|
|
} |
114
|
|
|
if (property_exists($data, 'active')) { |
115
|
|
|
$object->setActive($data->{'active'}); |
116
|
|
|
} |
117
|
|
|
if (property_exists($data, 'customerId')) { |
118
|
|
|
$object->setCustomerId($data->{'customerId'}); |
119
|
|
|
} |
120
|
|
|
if (property_exists($data, 'customerName')) { |
121
|
|
|
$object->setCustomerName($data->{'customerName'}); |
122
|
|
|
} |
123
|
|
|
if (property_exists($data, 'name')) { |
124
|
|
|
$object->setName($data->{'name'}); |
125
|
|
|
} |
126
|
|
|
if (property_exists($data, 'code')) { |
127
|
|
|
$object->setCode($data->{'code'}); |
128
|
|
|
} |
129
|
|
|
if (property_exists($data, 'notes')) { |
130
|
|
|
$object->setNotes($data->{'notes'}); |
131
|
|
|
} |
132
|
|
|
if (property_exists($data, 'invoiceMethod')) { |
133
|
|
|
$object->setInvoiceMethod($data->{'invoiceMethod'}); |
134
|
|
|
} |
135
|
|
|
if (property_exists($data, 'hourlyRate')) { |
136
|
|
|
$object->setHourlyRate($data->{'hourlyRate'}); |
137
|
|
|
} |
138
|
|
|
if (property_exists($data, 'rate')) { |
139
|
|
|
$object->setRate($data->{'rate'}); |
140
|
|
|
} |
141
|
|
|
if (property_exists($data, 'budgetMethod')) { |
142
|
|
|
$object->setBudgetMethod($data->{'budgetMethod'}); |
143
|
|
|
} |
144
|
|
|
if (property_exists($data, 'budgetRate')) { |
145
|
|
|
$object->setBudgetRate($data->{'budgetRate'}); |
146
|
|
|
} |
147
|
|
|
if (property_exists($data, 'budgetHours')) { |
148
|
|
|
$object->setBudgetHours($data->{'budgetHours'}); |
149
|
|
|
} |
150
|
|
|
if (property_exists($data, 'startDate')) { |
151
|
|
|
$object->setStartDate(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'startDate'})); |
|
|
|
|
152
|
|
|
} |
153
|
|
|
if (property_exists($data, 'endDate')) { |
154
|
|
|
$object->setEndDate(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data->{'endDate'})); |
|
|
|
|
155
|
|
|
} |
156
|
|
|
if (property_exists($data, 'projectSubscription')) { |
157
|
|
|
$object->setProjectSubscription($this->denormalizer->denormalize($data->{'projectSubscription'}, 'ConnectHolland\\TimechimpBundle\\Api\\Model\\ProjectSubscription', 'json', $context)); |
|
|
|
|
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
return $object; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function normalize($object, $format = null, array $context = []) |
164
|
|
|
{ |
165
|
|
|
$data = new \stdClass(); |
166
|
|
|
if (null !== $object->getRemainingBudgetHours()) { |
167
|
|
|
$data->{'remainingBudgetHours'} = $object->getRemainingBudgetHours(); |
168
|
|
|
} |
169
|
|
|
if (null !== $object->getTagIds()) { |
170
|
|
|
$values = []; |
171
|
|
|
foreach ($object->getTagIds() as $value) { |
172
|
|
|
$values[] = $value; |
173
|
|
|
} |
174
|
|
|
$data->{'tagIds'} = $values; |
175
|
|
|
} |
176
|
|
|
if (null !== $object->getTagNames()) { |
177
|
|
|
$values_1 = []; |
178
|
|
|
foreach ($object->getTagNames() as $value_1) { |
179
|
|
|
$values_1[] = $value_1; |
180
|
|
|
} |
181
|
|
|
$data->{'tagNames'} = $values_1; |
182
|
|
|
} |
183
|
|
|
if (null !== $object->getUnspecified()) { |
184
|
|
|
$data->{'unspecified'} = $object->getUnspecified(); |
185
|
|
|
} |
186
|
|
|
if (null !== $object->getInvoiceDate()) { |
187
|
|
|
$data->{'invoiceDate'} = $object->getInvoiceDate()->format('Y-m-d\\TH:i:sP'); |
188
|
|
|
} |
189
|
|
|
if (null !== $object->getInvoiceInInstallments()) { |
190
|
|
|
$data->{'invoiceInInstallments'} = $object->getInvoiceInInstallments(); |
191
|
|
|
} |
192
|
|
|
if (null !== $object->getBudgetNotificationPercentage()) { |
193
|
|
|
$data->{'budgetNotificationPercentage'} = $object->getBudgetNotificationPercentage(); |
194
|
|
|
} |
195
|
|
|
if (null !== $object->getBudgetNotificationHasBeenSent()) { |
196
|
|
|
$data->{'budgetNotificationHasBeenSent'} = $object->getBudgetNotificationHasBeenSent(); |
197
|
|
|
} |
198
|
|
|
if (null !== $object->getClientId()) { |
199
|
|
|
$data->{'clientId'} = $object->getClientId(); |
200
|
|
|
} |
201
|
|
|
if (null !== $object->getInvoiceStatus()) { |
202
|
|
|
$data->{'invoiceStatus'} = $object->getInvoiceStatus(); |
203
|
|
|
} |
204
|
|
|
if (null !== $object->getInvoiceId()) { |
205
|
|
|
$data->{'invoiceId'} = $object->getInvoiceId(); |
206
|
|
|
} |
207
|
|
|
if (null !== $object->getColor()) { |
208
|
|
|
$data->{'color'} = $object->getColor(); |
209
|
|
|
} |
210
|
|
|
if (null !== $object->getVisibleOnSchedule()) { |
211
|
|
|
$data->{'visibleOnSchedule'} = $object->getVisibleOnSchedule(); |
212
|
|
|
} |
213
|
|
|
if (null !== $object->getExternalUrl()) { |
214
|
|
|
$data->{'externalUrl'} = $object->getExternalUrl(); |
215
|
|
|
} |
216
|
|
|
if (null !== $object->getExternalName()) { |
217
|
|
|
$data->{'externalName'} = $object->getExternalName(); |
218
|
|
|
} |
219
|
|
|
if (null !== $object->getInvoiceReference()) { |
220
|
|
|
$data->{'invoiceReference'} = $object->getInvoiceReference(); |
221
|
|
|
} |
222
|
|
|
if (null !== $object->getProjectTasks()) { |
223
|
|
|
$values_2 = []; |
224
|
|
|
foreach ($object->getProjectTasks() as $value_2) { |
225
|
|
|
$values_2[] = $this->normalizer->normalize($value_2, 'json', $context); |
226
|
|
|
} |
227
|
|
|
$data->{'projectTasks'} = $values_2; |
228
|
|
|
} |
229
|
|
|
if (null !== $object->getProjectUsers()) { |
230
|
|
|
$values_3 = []; |
231
|
|
|
foreach ($object->getProjectUsers() as $value_3) { |
232
|
|
|
$values_3[] = $this->normalizer->normalize($value_3, 'json', $context); |
233
|
|
|
} |
234
|
|
|
$data->{'projectUsers'} = $values_3; |
235
|
|
|
} |
236
|
|
|
if (null !== $object->getId()) { |
237
|
|
|
$data->{'id'} = $object->getId(); |
238
|
|
|
} |
239
|
|
|
if (null !== $object->getActive()) { |
240
|
|
|
$data->{'active'} = $object->getActive(); |
241
|
|
|
} |
242
|
|
|
if (null !== $object->getCustomerId()) { |
243
|
|
|
$data->{'customerId'} = $object->getCustomerId(); |
244
|
|
|
} |
245
|
|
|
if (null !== $object->getCustomerName()) { |
246
|
|
|
$data->{'customerName'} = $object->getCustomerName(); |
247
|
|
|
} |
248
|
|
|
if (null !== $object->getName()) { |
249
|
|
|
$data->{'name'} = $object->getName(); |
250
|
|
|
} |
251
|
|
|
if (null !== $object->getCode()) { |
252
|
|
|
$data->{'code'} = $object->getCode(); |
253
|
|
|
} |
254
|
|
|
if (null !== $object->getNotes()) { |
255
|
|
|
$data->{'notes'} = $object->getNotes(); |
256
|
|
|
} |
257
|
|
|
if (null !== $object->getInvoiceMethod()) { |
258
|
|
|
$data->{'invoiceMethod'} = $object->getInvoiceMethod(); |
259
|
|
|
} |
260
|
|
|
if (null !== $object->getHourlyRate()) { |
261
|
|
|
$data->{'hourlyRate'} = $object->getHourlyRate(); |
262
|
|
|
} |
263
|
|
|
if (null !== $object->getRate()) { |
264
|
|
|
$data->{'rate'} = $object->getRate(); |
265
|
|
|
} |
266
|
|
|
if (null !== $object->getBudgetMethod()) { |
267
|
|
|
$data->{'budgetMethod'} = $object->getBudgetMethod(); |
268
|
|
|
} |
269
|
|
|
if (null !== $object->getBudgetRate()) { |
270
|
|
|
$data->{'budgetRate'} = $object->getBudgetRate(); |
271
|
|
|
} |
272
|
|
|
if (null !== $object->getBudgetHours()) { |
273
|
|
|
$data->{'budgetHours'} = $object->getBudgetHours(); |
274
|
|
|
} |
275
|
|
|
if (null !== $object->getStartDate()) { |
276
|
|
|
$data->{'startDate'} = $object->getStartDate()->format('Y-m-d\\TH:i:sP'); |
277
|
|
|
} |
278
|
|
|
if (null !== $object->getEndDate()) { |
279
|
|
|
$data->{'endDate'} = $object->getEndDate()->format('Y-m-d\\TH:i:sP'); |
280
|
|
|
} |
281
|
|
|
if (null !== $object->getProjectSubscription()) { |
282
|
|
|
$data->{'projectSubscription'} = $this->normalizer->normalize($object->getProjectSubscription(), 'json', $context); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
return $data; |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|