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 ExpenseNormalizer 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\\Expense'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function supportsNormalization($data, $format = null) |
30
|
|
|
{ |
31
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\Expense'; |
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\Expense(); |
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, 'categoryName') && $data->{'categoryName'} !== null) { |
66
|
|
|
$object->setCategoryName($data->{'categoryName'}); |
67
|
|
|
} elseif (property_exists($data, 'categoryName') && $data->{'categoryName'} === null) { |
68
|
|
|
$object->setCategoryName(null); |
69
|
|
|
} |
70
|
|
|
if (property_exists($data, 'categoryId') && $data->{'categoryId'} !== null) { |
71
|
|
|
$object->setCategoryId($data->{'categoryId'}); |
72
|
|
|
} elseif (property_exists($data, 'categoryId') && $data->{'categoryId'} === null) { |
73
|
|
|
$object->setCategoryId(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, 'notes') && $data->{'notes'} !== null) { |
91
|
|
|
$object->setNotes($data->{'notes'}); |
92
|
|
|
} elseif (property_exists($data, 'notes') && $data->{'notes'} === null) { |
93
|
|
|
$object->setNotes(null); |
94
|
|
|
} |
95
|
|
|
if (property_exists($data, 'attachment') && $data->{'attachment'} !== null) { |
96
|
|
|
$object->setAttachment($data->{'attachment'}); |
97
|
|
|
} elseif (property_exists($data, 'attachment') && $data->{'attachment'} === null) { |
98
|
|
|
$object->setAttachment(null); |
99
|
|
|
} |
100
|
|
|
if (property_exists($data, 'quantity') && $data->{'quantity'} !== null) { |
101
|
|
|
$object->setQuantity($data->{'quantity'}); |
102
|
|
|
} elseif (property_exists($data, 'quantity') && $data->{'quantity'} === null) { |
103
|
|
|
$object->setQuantity(null); |
104
|
|
|
} |
105
|
|
|
if (property_exists($data, 'rate') && $data->{'rate'} !== null) { |
106
|
|
|
$object->setRate($data->{'rate'}); |
107
|
|
|
} elseif (property_exists($data, 'rate') && $data->{'rate'} === null) { |
108
|
|
|
$object->setRate(null); |
109
|
|
|
} |
110
|
|
|
if (property_exists($data, 'tax') && $data->{'tax'} !== null) { |
111
|
|
|
$object->setTax($data->{'tax'}); |
112
|
|
|
} elseif (property_exists($data, 'tax') && $data->{'tax'} === null) { |
113
|
|
|
$object->setTax(null); |
114
|
|
|
} |
115
|
|
|
if (property_exists($data, 'billable') && $data->{'billable'} !== null) { |
116
|
|
|
$object->setBillable($data->{'billable'}); |
117
|
|
|
} elseif (property_exists($data, 'billable') && $data->{'billable'} === null) { |
118
|
|
|
$object->setBillable(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->getCategoryName()) { |
158
|
|
|
$data->{'categoryName'} = $object->getCategoryName(); |
159
|
|
|
} else { |
160
|
|
|
$data->{'categoryName'} = null; |
161
|
|
|
} |
162
|
|
|
if (null !== $object->getCategoryId()) { |
163
|
|
|
$data->{'categoryId'} = $object->getCategoryId(); |
164
|
|
|
} else { |
165
|
|
|
$data->{'categoryId'} = 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->getNotes()) { |
183
|
|
|
$data->{'notes'} = $object->getNotes(); |
184
|
|
|
} else { |
185
|
|
|
$data->{'notes'} = null; |
186
|
|
|
} |
187
|
|
|
if (null !== $object->getAttachment()) { |
188
|
|
|
$data->{'attachment'} = $object->getAttachment(); |
189
|
|
|
} else { |
190
|
|
|
$data->{'attachment'} = null; |
191
|
|
|
} |
192
|
|
|
if (null !== $object->getQuantity()) { |
193
|
|
|
$data->{'quantity'} = $object->getQuantity(); |
194
|
|
|
} else { |
195
|
|
|
$data->{'quantity'} = null; |
196
|
|
|
} |
197
|
|
|
if (null !== $object->getRate()) { |
198
|
|
|
$data->{'rate'} = $object->getRate(); |
199
|
|
|
} else { |
200
|
|
|
$data->{'rate'} = null; |
201
|
|
|
} |
202
|
|
|
if (null !== $object->getTax()) { |
203
|
|
|
$data->{'tax'} = $object->getTax(); |
204
|
|
|
} else { |
205
|
|
|
$data->{'tax'} = null; |
206
|
|
|
} |
207
|
|
|
if (null !== $object->getBillable()) { |
208
|
|
|
$data->{'billable'} = $object->getBillable(); |
209
|
|
|
} else { |
210
|
|
|
$data->{'billable'} = 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
|
|
|
|