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
|
|
|
public function __construct() |
69
|
|
|
{ |
70
|
|
|
$this->setStatus("pending"); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get id. |
75
|
|
|
* |
76
|
|
|
* @return int |
77
|
|
|
*/ |
78
|
|
|
public function getId() |
79
|
|
|
{ |
80
|
|
|
return $this->id; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Set type. |
85
|
|
|
* |
86
|
|
|
* @param $type |
87
|
|
|
* |
88
|
|
|
* @return FormRequest |
89
|
|
|
*/ |
90
|
|
|
public function setType($type) |
91
|
|
|
{ |
92
|
|
|
if (in_array($type, self::TYPE)) { |
93
|
|
|
$this->type = $type; |
94
|
1 |
|
} |
95
|
|
|
return $this; |
96
|
1 |
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get type. |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getType() |
104
|
|
|
{ |
105
|
|
|
return $this->type; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Set status. |
110
|
|
|
* |
111
|
|
|
* @param string $status |
112
|
|
|
* |
113
|
|
|
* @return FormRequest |
114
|
|
|
*/ |
115
|
|
|
public function setStatus($status) |
116
|
|
|
{ |
117
|
|
|
if (in_array($status, self::STATUS)) { |
118
|
1 |
|
$this->status = $status; |
119
|
|
|
} |
120
|
1 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get status. |
125
|
|
|
* |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
public function getStatus() |
129
|
|
|
{ |
130
|
|
|
return $this->status; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Set user. |
135
|
|
|
* |
136
|
|
|
* @param User $user |
137
|
|
|
* |
138
|
|
|
* @return FormRequest |
139
|
|
|
*/ |
140
|
|
|
public function setUser(User $user) |
141
|
|
|
{ |
142
|
|
|
$this->user = $user; |
143
|
|
|
|
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Get user. |
149
|
|
|
* |
150
|
|
|
* @return User |
151
|
|
|
*/ |
152
|
|
|
public function getUser() |
153
|
|
|
{ |
154
|
|
|
return $this->user; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Set date. |
159
|
|
|
* |
160
|
|
|
* @param \DateTime $date |
161
|
|
|
* |
162
|
|
|
* @return FormRequest |
163
|
|
|
*/ |
164
|
|
|
public function setDate($date) |
165
|
1 |
|
{ |
166
|
|
|
$this->date = new \DateTime($date); |
167
|
1 |
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
/** |
171
|
|
|
* Get date. |
172
|
|
|
* |
173
|
|
|
* @return \DateTime |
174
|
|
|
*/ |
175
|
|
|
public function getDate() |
176
|
|
|
{ |
177
|
|
|
return $this->date; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|