1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Knp\DoctrineBehaviors\Model as ORMBehaviors; |
7
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
8
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* FormRequest. |
12
|
|
|
* |
13
|
|
|
* @ORM\Entity(repositoryClass="AppBundle\Repository\FormRequestRepository") |
14
|
|
|
*/ |
15
|
|
|
class FormRequest |
16
|
|
|
{ |
17
|
|
|
use ORMBehaviors\Timestampable\Timestampable; |
18
|
|
|
|
19
|
|
|
const STATUS = ['pending', 'approved', 'rejected']; |
20
|
|
|
const TYPE = ['personal day', 'overnight guest', 'sick day']; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var int |
24
|
|
|
* |
25
|
|
|
* @ORM\Column(name="id", type="integer") |
26
|
|
|
* @ORM\Id |
27
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
28
|
|
|
*/ |
29
|
|
|
private $id; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
* @Assert\NotBlank() |
34
|
|
|
* @Assert\Choice(FormRequest::TYPE) |
35
|
|
|
* @ORM\Column(type="string", length=25) |
36
|
|
|
* @Groups({"Detail"}) |
37
|
|
|
*/ |
38
|
|
|
private $type; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
* @Assert\NotBlank() |
43
|
|
|
* @Assert\Type("string") |
44
|
|
|
* @Assert\Length( |
45
|
|
|
* max = 255 |
46
|
|
|
* ) |
47
|
|
|
* @ORM\Column(type="string", length=255) |
48
|
|
|
* @Groups({"Detail"}) |
49
|
|
|
*/ |
50
|
|
|
private $status; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var User |
54
|
|
|
* @Assert\Type("object") |
55
|
|
|
* @Assert\Valid |
56
|
|
|
* @ORM\ManyToOne(targetEntity="User", inversedBy="formRequests") |
57
|
|
|
*/ |
58
|
|
|
private $user; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var \DateTime |
62
|
|
|
* @Assert\DateTime() |
63
|
|
|
* @ORM\Column(type="datetime") |
64
|
|
|
* @Assert\GreaterThan("+2 days") |
65
|
|
|
* @Groups({"Detail"}) |
66
|
|
|
*/ |
67
|
|
|
private $date; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var string |
71
|
|
|
* |
72
|
|
|
* @ORM\Column(type="string", nullable=true) |
73
|
|
|
* @Assert\Length(min="5", max="100") |
74
|
|
|
* @Groups({"Detail"}) |
75
|
|
|
*/ |
76
|
|
|
private $reason; |
77
|
|
|
|
78
|
|
|
public function __construct() |
79
|
|
|
{ |
80
|
|
|
$this->setStatus('pending'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get id. |
85
|
|
|
* |
86
|
|
|
* @return int |
87
|
|
|
*/ |
88
|
1 |
|
public function getId() |
89
|
|
|
{ |
90
|
1 |
|
return $this->id; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Set type. |
95
|
|
|
* |
96
|
|
|
* @param $type |
97
|
|
|
* |
98
|
|
|
* @return FormRequest |
99
|
|
|
*/ |
100
|
|
|
public function setType($type) |
101
|
|
|
{ |
102
|
|
|
if (in_array($type, self::TYPE)) { |
103
|
|
|
$this->type = $type; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Get type. |
111
|
|
|
* |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
1 |
|
public function getType() |
115
|
|
|
{ |
116
|
1 |
|
return $this->type; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Set status. |
121
|
|
|
* |
122
|
|
|
* @param string $status |
123
|
|
|
* |
124
|
|
|
* @return FormRequest |
125
|
|
|
*/ |
126
|
|
|
public function setStatus($status) |
127
|
|
|
{ |
128
|
|
|
if (in_array($status, self::STATUS)) { |
129
|
|
|
$this->status = $status; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get status. |
137
|
|
|
* |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
1 |
|
public function getStatus() |
141
|
|
|
{ |
142
|
1 |
|
return $this->status; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Set user. |
147
|
|
|
* |
148
|
|
|
* @param User $user |
149
|
|
|
* |
150
|
|
|
* @return FormRequest |
151
|
|
|
*/ |
152
|
|
|
public function setUser(User $user) |
153
|
|
|
{ |
154
|
|
|
$this->user = $user; |
155
|
|
|
|
156
|
|
|
return $this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get user. |
161
|
|
|
* |
162
|
|
|
* @return User |
163
|
|
|
*/ |
164
|
|
|
public function getUser() |
165
|
|
|
{ |
166
|
|
|
return $this->user; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Set date. |
171
|
|
|
* |
172
|
|
|
* @param \DateTime $date |
173
|
|
|
* |
174
|
|
|
* @return FormRequest |
175
|
|
|
*/ |
176
|
|
|
public function setDate($date) |
177
|
|
|
{ |
178
|
|
|
try { |
179
|
|
|
$this->date = date_create_from_format(\DATE_RFC3339, $date); |
180
|
|
|
} catch (\Exception $e) { |
181
|
|
|
$this->date = false; |
|
|
|
|
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
return $this; |
185
|
|
|
} |
186
|
|
|
/** |
187
|
|
|
* Get date. |
188
|
|
|
* |
189
|
|
|
* @return \DateTime |
190
|
|
|
*/ |
191
|
1 |
|
public function getDate() |
192
|
|
|
{ |
193
|
1 |
|
return $this->date; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @return string |
198
|
|
|
*/ |
199
|
1 |
|
public function getReason() |
200
|
|
|
{ |
201
|
1 |
|
return $this->reason; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @param string $reason |
206
|
|
|
* |
207
|
|
|
* @return $this |
208
|
|
|
*/ |
209
|
|
|
public function setReason($reason) |
210
|
|
|
{ |
211
|
|
|
$this->reason = $reason; |
212
|
|
|
|
213
|
|
|
return $this; |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..