-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJobOffer.php
More file actions
219 lines (184 loc) · 4.51 KB
/
Copy pathJobOffer.php
File metadata and controls
219 lines (184 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
namespace App\Entity\Project;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use App\Entity\Skill as BaseSkill;
/**
* @ORM\Entity()
* @ORM\Table(name="project__job_offers")
* @ORM\HasLifecycleCallbacks
*/
class JobOffer implements \JsonSerializable
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Project")
*/
protected $project;
/**
* @ORM\Column(type="string", length=80)
* @Assert\NotBlank(message="project.job_offers.empty_title")
* @Assert\Length(
* min = 5,
* max = 80,
* minMessage = "project.job_offers.title_too_short",
* maxMessage = "project.job_offers.title_too_long"
* )
*/
protected $title;
/**
* @ORM\Column(type="string", length=80)
*/
protected $slug;
/**
* @ORM\Column(type="text")
* @Assert\NotBlank(message="project.job_offers.empty_content")
*/
protected $content;
/**
* @ORM\Column(type="boolean")
*/
protected $isActive;
/**
* @ORM\OneToMany(targetEntity="Skill", mappedBy="jobOffer", cascade={"persist", "remove"}, fetch="EAGER")
*/
protected $skills;
/**
* @ORM\Column(type="datetime")
*/
protected $createdAt;
/**
* @ORM\Column(type="datetime")
*/
protected $updatedAt;
/**
* @ORM\PrePersist()
*/
public function prePersist()
{
$this->isActive = true;
$this->createdAt = $this->updatedAt = new \DateTime();
}
/**
* @ORM\PreUpdate()
*/
public function preUpdate()
{
$this->updatedAt = new \DateTime();
}
public function __construct()
{
$this->skills = new ArrayCollection();
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getTitle(): string
{
return $this->title;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getSlug(): string
{
return $this->slug;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getContent(): string
{
return $this->content;
}
public function activate(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function isActive(): bool
{
return $this->isActive;
}
public function addSkill(Skill $skill): self
{
$this->skills->add($skill);
return $this;
}
public function hasSkill(Skill $skill): bool
{
return $this->skills->contains($skill);
}
public function removeSkill(Skill $skill): self
{
$this->skills->removeElement($skill);
return $this;
}
public function findSkill(BaseSkill $skill): ?Skill
{
foreach ($this->skills as $jobOfferSkill) {
if ($jobOfferSkill->getSkill() === $skill) {
return $jobOfferSkill;
}
}
return null;
}
public function getSkills(): Collection
{
return $this->skills;
}
public function setProject(Project $project): self
{
$this->project = $project;
return $this;
}
public function getProject(): Project
{
return $this->project;
}
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
public function setUpdatedAt(\DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
public function jsonSerialize()
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'content' => $this->content,
'is_active' => $this->isActive,
'project' => $this->project,
'skills' => $this->skills->toArray(),
'created_at' => $this->createdAt->format('c'),
'updated_at' => $this->updatedAt->format('c')
];
}
}