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 ProjectTaskNormalizer 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\\ProjectTask'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function supportsNormalization($data, $format = null) |
30
|
|
|
{ |
31
|
|
|
return is_object($data) && get_class($data) === 'ConnectHolland\\TimechimpBundle\\Api\\Model\\ProjectTask'; |
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\ProjectTask(); |
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, 'taskId') && $data->{'taskId'} !== null) { |
46
|
|
|
$object->setTaskId($data->{'taskId'}); |
47
|
|
|
} elseif (property_exists($data, 'taskId') && $data->{'taskId'} === null) { |
48
|
|
|
$object->setTaskId(null); |
49
|
|
|
} |
50
|
|
|
if (property_exists($data, 'taskName') && $data->{'taskName'} !== null) { |
51
|
|
|
$object->setTaskName($data->{'taskName'}); |
52
|
|
|
} elseif (property_exists($data, 'taskName') && $data->{'taskName'} === null) { |
53
|
|
|
$object->setTaskName(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, 'billable') && $data->{'billable'} !== null) { |
61
|
|
|
$object->setBillable($data->{'billable'}); |
62
|
|
|
} elseif (property_exists($data, 'billable') && $data->{'billable'} === null) { |
63
|
|
|
$object->setBillable(null); |
64
|
|
|
} |
65
|
|
|
if (property_exists($data, 'unspecified') && $data->{'unspecified'} !== null) { |
66
|
|
|
$object->setUnspecified($data->{'unspecified'}); |
67
|
|
|
} elseif (property_exists($data, 'unspecified') && $data->{'unspecified'} === null) { |
68
|
|
|
$object->setUnspecified(null); |
69
|
|
|
} |
70
|
|
|
if (property_exists($data, 'budgetHours') && $data->{'budgetHours'} !== null) { |
71
|
|
|
$object->setBudgetHours($data->{'budgetHours'}); |
72
|
|
|
} elseif (property_exists($data, 'budgetHours') && $data->{'budgetHours'} === null) { |
73
|
|
|
$object->setBudgetHours(null); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $object; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function normalize($object, $format = null, array $context = []) |
80
|
|
|
{ |
81
|
|
|
$data = new \stdClass(); |
82
|
|
|
if (null !== $object->getId()) { |
83
|
|
|
$data->{'id'} = $object->getId(); |
84
|
|
|
} else { |
85
|
|
|
$data->{'id'} = null; |
86
|
|
|
} |
87
|
|
|
if (null !== $object->getTaskId()) { |
88
|
|
|
$data->{'taskId'} = $object->getTaskId(); |
89
|
|
|
} else { |
90
|
|
|
$data->{'taskId'} = null; |
91
|
|
|
} |
92
|
|
|
if (null !== $object->getTaskName()) { |
93
|
|
|
$data->{'taskName'} = $object->getTaskName(); |
94
|
|
|
} else { |
95
|
|
|
$data->{'taskName'} = null; |
96
|
|
|
} |
97
|
|
|
if (null !== $object->getHourlyRate()) { |
98
|
|
|
$data->{'hourlyRate'} = $object->getHourlyRate(); |
99
|
|
|
} else { |
100
|
|
|
$data->{'hourlyRate'} = null; |
101
|
|
|
} |
102
|
|
|
if (null !== $object->getBillable()) { |
103
|
|
|
$data->{'billable'} = $object->getBillable(); |
104
|
|
|
} else { |
105
|
|
|
$data->{'billable'} = null; |
106
|
|
|
} |
107
|
|
|
if (null !== $object->getUnspecified()) { |
108
|
|
|
$data->{'unspecified'} = $object->getUnspecified(); |
109
|
|
|
} else { |
110
|
|
|
$data->{'unspecified'} = null; |
111
|
|
|
} |
112
|
|
|
if (null !== $object->getBudgetHours()) { |
113
|
|
|
$data->{'budgetHours'} = $object->getBudgetHours(); |
114
|
|
|
} else { |
115
|
|
|
$data->{'budgetHours'} = null; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $data; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|