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
|
|
|
* @Groups({"Detail"}) |
65
|
|
|
*/ |
66
|
|
|
private $date; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var string |
70
|
|
|
* |
71
|
|
|
* @ORM\Column(type="text", nullable=true) |
72
|
|
|
* @Groups({"Detail"}) |
73
|
|
|
*/ |
74
|
|
|
private $reason; |
75
|
|
|
|
76
|
|
|
public function __construct() |
77
|
|
|
{ |
78
|
|
|
$this->setStatus('pending'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get id. |
83
|
|
|
* |
84
|
|
|
* @return int |
85
|
|
|
*/ |
86
|
1 |
|
public function getId() |
87
|
|
|
{ |
88
|
1 |
|
return $this->id; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Set type. |
93
|
|
|
* |
94
|
|
|
* @param $type |
95
|
|
|
* |
96
|
|
|
* @return FormRequest |
97
|
|
|
*/ |
98
|
|
|
public function setType($type) |
99
|
|
|
{ |
100
|
|
|
if (in_array($type, self::TYPE)) { |
101
|
|
|
$this->type = $type; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get type. |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
1 |
|
public function getType() |
113
|
|
|
{ |
114
|
1 |
|
return $this->type; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Set status. |
119
|
|
|
* |
120
|
|
|
* @param string $status |
121
|
|
|
* |
122
|
|
|
* @return FormRequest |
123
|
|
|
*/ |
124
|
|
|
public function setStatus($status) |
125
|
|
|
{ |
126
|
|
|
if (in_array($status, self::STATUS)) { |
127
|
|
|
$this->status = $status; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get status. |
135
|
|
|
* |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
1 |
|
public function getStatus() |
139
|
|
|
{ |
140
|
1 |
|
return $this->status; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Set user. |
145
|
|
|
* |
146
|
|
|
* @param User $user |
147
|
|
|
* |
148
|
|
|
* @return FormRequest |
149
|
|
|
*/ |
150
|
|
|
public function setUser(User $user) |
151
|
|
|
{ |
152
|
|
|
$this->user = $user; |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Get user. |
159
|
|
|
* |
160
|
|
|
* @return User |
161
|
|
|
*/ |
162
|
|
|
public function getUser() |
163
|
|
|
{ |
164
|
|
|
return $this->user; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Set date. |
169
|
|
|
* |
170
|
|
|
* @param \DateTime $date |
171
|
|
|
* |
172
|
|
|
* @return FormRequest |
173
|
|
|
*/ |
174
|
|
|
public function setDate($date) |
175
|
|
|
{ |
176
|
|
|
$this->date = new \DateTime($date); |
177
|
|
|
|
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
/** |
181
|
|
|
* Get date. |
182
|
|
|
* |
183
|
|
|
* @return \DateTime |
184
|
|
|
*/ |
185
|
1 |
|
public function getDate() |
186
|
|
|
{ |
187
|
1 |
|
return $this->date; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return string |
192
|
|
|
*/ |
193
|
1 |
|
public function getReason() |
194
|
|
|
{ |
195
|
1 |
|
return $this->reason; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param string $reason |
200
|
|
|
* |
201
|
|
|
* @return $this |
202
|
|
|
*/ |
203
|
|
|
public function setReason($reason) |
204
|
|
|
{ |
205
|
|
|
$this->reason = $reason; |
206
|
|
|
|
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
} |
211
|
|
|
|