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 ProjectUserNormalizer 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\\ProjectUser'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function supportsNormalization($data, $format = null) |
30
|
|
|
{ |
31
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\ProjectUser'; |
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\ProjectUser(); |
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, 'userId') && $data->{'userId'} !== null) { |
46
|
|
|
$object->setUserId($data->{'userId'}); |
47
|
|
|
} elseif (property_exists($data, 'userId') && $data->{'userId'} === null) { |
48
|
|
|
$object->setUserId(null); |
49
|
|
|
} |
50
|
|
|
if (property_exists($data, 'userDisplayName') && $data->{'userDisplayName'} !== null) { |
51
|
|
|
$object->setUserDisplayName($data->{'userDisplayName'}); |
52
|
|
|
} elseif (property_exists($data, 'userDisplayName') && $data->{'userDisplayName'} === null) { |
53
|
|
|
$object->setUserDisplayName(null); |
54
|
|
|
} |
55
|
|
|
if (property_exists($data, 'hourlyRate') && $data->{'hourlyRate'} !== null) { |
56
|
|
|
$object->setHourlyRate($data->{'hourlyRate'}); |
57
|
|
|
} elseif (property_exists($data, 'hourlyRate') && $data->{'hourlyRate'} === null) { |
58
|
|
|
$object->setHourlyRate(null); |
59
|
|
|
} |
60
|
|
|
if (property_exists($data, 'budgetHours') && $data->{'budgetHours'} !== null) { |
61
|
|
|
$object->setBudgetHours($data->{'budgetHours'}); |
62
|
|
|
} elseif (property_exists($data, 'budgetHours') && $data->{'budgetHours'} === null) { |
63
|
|
|
$object->setBudgetHours(null); |
64
|
|
|
} |
65
|
|
|
if (property_exists($data, 'projectManager') && $data->{'projectManager'} !== null) { |
66
|
|
|
$object->setProjectManager($data->{'projectManager'}); |
67
|
|
|
} elseif (property_exists($data, 'projectManager') && $data->{'projectManager'} === null) { |
68
|
|
|
$object->setProjectManager(null); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $object; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function normalize($object, $format = null, array $context = []) |
75
|
|
|
{ |
76
|
|
|
$data = new \stdClass(); |
77
|
|
|
if (null !== $object->getId()) { |
78
|
|
|
$data->{'id'} = $object->getId(); |
79
|
|
|
} else { |
80
|
|
|
$data->{'id'} = null; |
81
|
|
|
} |
82
|
|
|
if (null !== $object->getUserId()) { |
83
|
|
|
$data->{'userId'} = $object->getUserId(); |
84
|
|
|
} else { |
85
|
|
|
$data->{'userId'} = null; |
86
|
|
|
} |
87
|
|
|
if (null !== $object->getUserDisplayName()) { |
88
|
|
|
$data->{'userDisplayName'} = $object->getUserDisplayName(); |
89
|
|
|
} else { |
90
|
|
|
$data->{'userDisplayName'} = null; |
91
|
|
|
} |
92
|
|
|
if (null !== $object->getHourlyRate()) { |
93
|
|
|
$data->{'hourlyRate'} = $object->getHourlyRate(); |
94
|
|
|
} else { |
95
|
|
|
$data->{'hourlyRate'} = null; |
96
|
|
|
} |
97
|
|
|
if (null !== $object->getBudgetHours()) { |
98
|
|
|
$data->{'budgetHours'} = $object->getBudgetHours(); |
99
|
|
|
} else { |
100
|
|
|
$data->{'budgetHours'} = null; |
101
|
|
|
} |
102
|
|
|
if (null !== $object->getProjectManager()) { |
103
|
|
|
$data->{'projectManager'} = $object->getProjectManager(); |
104
|
|
|
} else { |
105
|
|
|
$data->{'projectManager'} = null; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $data; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|