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 UserNormalizer 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\\User'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function supportsNormalization($data, $format = null) |
30
|
|
|
{ |
31
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\User'; |
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\User(); |
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, 'userName') && $data->{'userName'} !== null) { |
46
|
|
|
$object->setUserName($data->{'userName'}); |
47
|
|
|
} elseif (property_exists($data, 'userName') && $data->{'userName'} === null) { |
48
|
|
|
$object->setUserName(null); |
49
|
|
|
} |
50
|
|
|
if (property_exists($data, 'displayName') && $data->{'displayName'} !== null) { |
51
|
|
|
$object->setDisplayName($data->{'displayName'}); |
52
|
|
|
} elseif (property_exists($data, 'displayName') && $data->{'displayName'} === null) { |
53
|
|
|
$object->setDisplayName(null); |
54
|
|
|
} |
55
|
|
|
if (property_exists($data, 'accountType') && $data->{'accountType'} !== null) { |
56
|
|
|
$object->setAccountType($data->{'accountType'}); |
57
|
|
|
} elseif (property_exists($data, 'accountType') && $data->{'accountType'} === null) { |
58
|
|
|
$object->setAccountType(null); |
59
|
|
|
} |
60
|
|
|
if (property_exists($data, 'isLocked') && $data->{'isLocked'} !== null) { |
61
|
|
|
$object->setIsLocked($data->{'isLocked'}); |
62
|
|
|
} elseif (property_exists($data, 'isLocked') && $data->{'isLocked'} === null) { |
63
|
|
|
$object->setIsLocked(null); |
64
|
|
|
} |
65
|
|
|
if (property_exists($data, 'picture') && $data->{'picture'} !== null) { |
66
|
|
|
$object->setPicture($data->{'picture'}); |
67
|
|
|
} elseif (property_exists($data, 'picture') && $data->{'picture'} === null) { |
68
|
|
|
$object->setPicture(null); |
69
|
|
|
} |
70
|
|
|
if (property_exists($data, 'tagNames') && $data->{'tagNames'} !== null) { |
71
|
|
|
$values = []; |
72
|
|
|
foreach ($data->{'tagNames'} as $value) { |
73
|
|
|
$values[] = $value; |
74
|
|
|
} |
75
|
|
|
$object->setTagNames($values); |
76
|
|
|
} elseif (property_exists($data, 'tagNames') && $data->{'tagNames'} === null) { |
77
|
|
|
$object->setTagNames(null); |
78
|
|
|
} |
79
|
|
|
if (property_exists($data, 'language') && $data->{'language'} !== null) { |
80
|
|
|
$object->setLanguage($data->{'language'}); |
81
|
|
|
} elseif (property_exists($data, 'language') && $data->{'language'} === null) { |
82
|
|
|
$object->setLanguage(null); |
83
|
|
|
} |
84
|
|
|
if (property_exists($data, 'contractHours') && $data->{'contractHours'} !== null) { |
85
|
|
|
$object->setContractHours($data->{'contractHours'}); |
86
|
|
|
} elseif (property_exists($data, 'contractHours') && $data->{'contractHours'} === null) { |
87
|
|
|
$object->setContractHours(null); |
88
|
|
|
} |
89
|
|
|
if (property_exists($data, 'contractHourlyRate') && $data->{'contractHourlyRate'} !== null) { |
90
|
|
|
$object->setContractHourlyRate($data->{'contractHourlyRate'}); |
91
|
|
|
} elseif (property_exists($data, 'contractHourlyRate') && $data->{'contractHourlyRate'} === null) { |
92
|
|
|
$object->setContractHourlyRate(null); |
93
|
|
|
} |
94
|
|
|
if (property_exists($data, 'contractCostHourlyRate') && $data->{'contractCostHourlyRate'} !== null) { |
95
|
|
|
$object->setContractCostHourlyRate($data->{'contractCostHourlyRate'}); |
96
|
|
|
} elseif (property_exists($data, 'contractCostHourlyRate') && $data->{'contractCostHourlyRate'} === null) { |
97
|
|
|
$object->setContractCostHourlyRate(null); |
98
|
|
|
} |
99
|
|
|
if (property_exists($data, 'contractStartDate') && $data->{'contractStartDate'} !== null) { |
100
|
|
|
$object->setContractStartDate(\DateTime::createFromFormat('Y-m-d\\TH:i:s', $data->{'contractStartDate'})); |
|
|
|
|
101
|
|
|
} elseif (property_exists($data, 'contractStartDate') && $data->{'contractStartDate'} === null) { |
102
|
|
|
$object->setContractStartDate(null); |
103
|
|
|
} |
104
|
|
|
if (property_exists($data, 'contractEndDate') && $data->{'contractEndDate'} !== null) { |
105
|
|
|
$object->setContractEndDate(\DateTime::createFromFormat('Y-m-d\\TH:i:s', $data->{'contractEndDate'})); |
|
|
|
|
106
|
|
|
} elseif (property_exists($data, 'contractEndDate') && $data->{'contractEndDate'} === null) { |
107
|
|
|
$object->setContractEndDate(null); |
108
|
|
|
} |
109
|
|
|
if (property_exists($data, 'created') && $data->{'created'} !== null) { |
110
|
|
|
$object->setCreated(\DateTime::createFromFormat('Y-m-d\\TH:i:s.v', $data->{'created'})); |
|
|
|
|
111
|
|
|
} elseif (property_exists($data, 'created') && $data->{'created'} === null) { |
112
|
|
|
$object->setCreated(null); |
113
|
|
|
} |
114
|
|
|
if (property_exists($data, 'teamName') && $data->{'teamName'} !== null) { |
115
|
|
|
$object->setTeamName($data->{'teamName'}); |
116
|
|
|
} elseif (property_exists($data, 'teamName') && $data->{'teamName'} === null) { |
117
|
|
|
$object->setTeamName(null); |
118
|
|
|
} |
119
|
|
|
if (property_exists($data, 'employeeNumber') && $data->{'employeeNumber'} !== null) { |
120
|
|
|
$object->setEmployeeNumber($data->{'employeeNumber'}); |
121
|
|
|
} elseif (property_exists($data, 'employeeNumber') && $data->{'employeeNumber'} === null) { |
122
|
|
|
$object->setEmployeeNumber(null); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return $object; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function normalize($object, $format = null, array $context = []) |
129
|
|
|
{ |
130
|
|
|
$data = new \stdClass(); |
131
|
|
|
if (null !== $object->getId()) { |
132
|
|
|
$data->{'id'} = $object->getId(); |
133
|
|
|
} else { |
134
|
|
|
$data->{'id'} = null; |
135
|
|
|
} |
136
|
|
|
if (null !== $object->getUserName()) { |
137
|
|
|
$data->{'userName'} = $object->getUserName(); |
138
|
|
|
} else { |
139
|
|
|
$data->{'userName'} = null; |
140
|
|
|
} |
141
|
|
|
if (null !== $object->getDisplayName()) { |
142
|
|
|
$data->{'displayName'} = $object->getDisplayName(); |
143
|
|
|
} else { |
144
|
|
|
$data->{'displayName'} = null; |
145
|
|
|
} |
146
|
|
|
if (null !== $object->getAccountType()) { |
147
|
|
|
$data->{'accountType'} = $object->getAccountType(); |
148
|
|
|
} else { |
149
|
|
|
$data->{'accountType'} = null; |
150
|
|
|
} |
151
|
|
|
if (null !== $object->getIsLocked()) { |
152
|
|
|
$data->{'isLocked'} = $object->getIsLocked(); |
153
|
|
|
} else { |
154
|
|
|
$data->{'isLocked'} = null; |
155
|
|
|
} |
156
|
|
|
if (null !== $object->getPicture()) { |
157
|
|
|
$data->{'picture'} = $object->getPicture(); |
158
|
|
|
} else { |
159
|
|
|
$data->{'picture'} = null; |
160
|
|
|
} |
161
|
|
|
if (null !== $object->getTagNames()) { |
162
|
|
|
$values = []; |
163
|
|
|
foreach ($object->getTagNames() as $value) { |
164
|
|
|
$values[] = $value; |
165
|
|
|
} |
166
|
|
|
$data->{'tagNames'} = $values; |
167
|
|
|
} else { |
168
|
|
|
$data->{'tagNames'} = null; |
169
|
|
|
} |
170
|
|
|
if (null !== $object->getLanguage()) { |
171
|
|
|
$data->{'language'} = $object->getLanguage(); |
172
|
|
|
} else { |
173
|
|
|
$data->{'language'} = null; |
174
|
|
|
} |
175
|
|
|
if (null !== $object->getContractHours()) { |
176
|
|
|
$data->{'contractHours'} = $object->getContractHours(); |
177
|
|
|
} else { |
178
|
|
|
$data->{'contractHours'} = null; |
179
|
|
|
} |
180
|
|
|
if (null !== $object->getContractHourlyRate()) { |
181
|
|
|
$data->{'contractHourlyRate'} = $object->getContractHourlyRate(); |
182
|
|
|
} else { |
183
|
|
|
$data->{'contractHourlyRate'} = null; |
184
|
|
|
} |
185
|
|
|
if (null !== $object->getContractCostHourlyRate()) { |
186
|
|
|
$data->{'contractCostHourlyRate'} = $object->getContractCostHourlyRate(); |
187
|
|
|
} else { |
188
|
|
|
$data->{'contractCostHourlyRate'} = null; |
189
|
|
|
} |
190
|
|
|
if (null !== $object->getContractStartDate()) { |
191
|
|
|
$data->{'contractStartDate'} = $object->getContractStartDate()->format('Y-m-d\\TH:i:s'); |
192
|
|
|
} else { |
193
|
|
|
$data->{'contractStartDate'} = null; |
194
|
|
|
} |
195
|
|
|
if (null !== $object->getContractEndDate()) { |
196
|
|
|
$data->{'contractEndDate'} = $object->getContractEndDate()->format('Y-m-d\\TH:i:s'); |
197
|
|
|
} else { |
198
|
|
|
$data->{'contractEndDate'} = null; |
199
|
|
|
} |
200
|
|
|
if (null !== $object->getCreated()) { |
201
|
|
|
$data->{'created'} = $object->getCreated()->format('Y-m-d\\TH:i:s'); |
202
|
|
|
} else { |
203
|
|
|
$data->{'created'} = null; |
204
|
|
|
} |
205
|
|
|
if (null !== $object->getTeamName()) { |
206
|
|
|
$data->{'teamName'} = $object->getTeamName(); |
207
|
|
|
} else { |
208
|
|
|
$data->{'teamName'} = null; |
209
|
|
|
} |
210
|
|
|
if (null !== $object->getEmployeeNumber()) { |
211
|
|
|
$data->{'employeeNumber'} = $object->getEmployeeNumber(); |
212
|
|
|
} else { |
213
|
|
|
$data->{'employeeNumber'} = null; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
return $data; |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|