1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Veslo project <https://github.com/symfony-doge/veslo>. |
5
|
|
|
* |
6
|
|
|
* (C) 2019-2021 Pavel Petrov <[email protected]>. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 GPL-3.0 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
declare(strict_types=1); |
15
|
|
|
|
16
|
|
|
namespace Veslo\AnthillBundle\Entity; |
17
|
|
|
|
18
|
|
|
use DateTimeInterface; |
19
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
20
|
|
|
use Doctrine\Common\Collections\Collection; |
21
|
|
|
use Doctrine\ORM\Mapping as ORM; |
22
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
23
|
|
|
use Veslo\AnthillBundle\Entity\Vacancy\Category; |
24
|
|
|
use Veslo\AnthillBundle\Entity\Vacancy\MappedSuperclass\SynchronizableDataFields; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Vacancy entity, contains metadata; all fields which represent a real vacancy data from job websites |
28
|
|
|
* are described by mapped superclass for better code readability |
29
|
|
|
* |
30
|
|
|
* @ORM\Table( |
31
|
|
|
* name="anthill_vacancy", |
32
|
|
|
* uniqueConstraints={ |
33
|
|
|
* @ORM\UniqueConstraint( |
34
|
|
|
* name="anthill_vacancy_roadmap_name_external_identifier_uq", |
35
|
|
|
* columns={"roadmap_name", "external_identifier"} |
36
|
|
|
* ) |
37
|
|
|
* }, |
38
|
|
|
* indexes={ |
39
|
|
|
* @ORM\Index( |
40
|
|
|
* name="anthill_vacancy_synchronization_date_ix", |
41
|
|
|
* columns={"synchronization_date"} |
42
|
|
|
* ) |
43
|
|
|
* } |
44
|
|
|
* ) |
45
|
|
|
* @ORM\Entity(repositoryClass="Veslo\AnthillBundle\Entity\Repository\VacancyRepository") |
46
|
|
|
* @ORM\Cache(usage="READ_ONLY", region="vacancies") |
47
|
|
|
* @Gedmo\Loggable(logEntryClass="Veslo\AnthillBundle\Entity\Vacancy\History\Entry") |
48
|
|
|
* @Gedmo\SoftDeleteable(fieldName="deletionDate", hardDelete=false) |
49
|
|
|
*/ |
50
|
|
|
class Vacancy extends SynchronizableDataFields |
51
|
|
|
{ |
52
|
|
|
// Note: traits are not used for better contextual readability, all fields should be explicit in one scope. |
53
|
|
|
/** |
54
|
|
|
* Vacancy identifier |
55
|
|
|
* |
56
|
|
|
* @var int |
57
|
|
|
* |
58
|
|
|
* @ORM\Column(name="id", type="integer", options={"comment": "Vacancy identifier"}) |
59
|
|
|
* @ORM\Id |
60
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
61
|
|
|
*/ |
62
|
|
|
private $id; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Alternative SEO-friendly vacancy identifier |
66
|
|
|
* |
67
|
|
|
* @var string |
68
|
|
|
* |
69
|
|
|
* @ORM\Column( |
70
|
|
|
* name="slug", |
71
|
|
|
* type="string", |
72
|
|
|
* length=255, |
73
|
|
|
* unique=true, |
74
|
|
|
* options={"comment": "Alternative SEO-friendly vacancy identifier"} |
75
|
|
|
* ) |
76
|
|
|
* @Gedmo\Slug(fields={"id", "title", "regionName"}) |
77
|
|
|
*/ |
78
|
|
|
private $slug; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Roadmap name by which the vacancy has been fetched |
82
|
|
|
* |
83
|
|
|
* @var string |
84
|
|
|
* |
85
|
|
|
* @ORM\Column( |
86
|
|
|
* name="roadmap_name", |
87
|
|
|
* type="string", |
88
|
|
|
* length=255, |
89
|
|
|
* options={"comment": "Roadmap name by which the vacancy has been fetched"} |
90
|
|
|
* ) |
91
|
|
|
*/ |
92
|
|
|
private $roadmapName; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Unique vacancy identifier on provider's website |
96
|
|
|
* |
97
|
|
|
* @var string |
98
|
|
|
* |
99
|
|
|
* @ORM\Column( |
100
|
|
|
* name="external_identifier", |
101
|
|
|
* type="string", |
102
|
|
|
* length=255, |
103
|
|
|
* options={"comment": "Unique vacancy identifier on provider's website"} |
104
|
|
|
* ) |
105
|
|
|
*/ |
106
|
|
|
private $externalIdentifier; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Company that posted the vacancy |
110
|
|
|
* |
111
|
|
|
* @var Company |
112
|
|
|
* |
113
|
|
|
* @ORM\ManyToOne(targetEntity="Veslo\AnthillBundle\Entity\Company", inversedBy="vacancies") |
114
|
|
|
* @ORM\JoinColumn(name="company_id", referencedColumnName="id") |
115
|
|
|
*/ |
116
|
|
|
private $company; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Categories to which vacancy belongs to |
120
|
|
|
* |
121
|
|
|
* @var Collection<Category> |
122
|
|
|
* |
123
|
|
|
* @ORM\ManyToMany( |
124
|
|
|
* targetEntity="Veslo\AnthillBundle\Entity\Vacancy\Category", |
125
|
|
|
* inversedBy="vacancies", |
126
|
|
|
* fetch="EXTRA_LAZY" |
127
|
|
|
* ) |
128
|
|
|
* @ORM\JoinTable( |
129
|
|
|
* name="anthill_vacancy_anthill_vacancy_category", |
130
|
|
|
* joinColumns={@ORM\JoinColumn(name="vacancy_id", referencedColumnName="id")}, |
131
|
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")} |
132
|
|
|
* ) |
133
|
|
|
*/ |
134
|
|
|
private $categories; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Last time when vacancy data has been fetched from external job website |
138
|
|
|
* |
139
|
|
|
* @var DateTimeInterface |
140
|
|
|
* |
141
|
|
|
* @ORM\Column( |
142
|
|
|
* name="synchronization_date", |
143
|
|
|
* type="datetime", |
144
|
|
|
* options={"comment": "Last time when vacancy data has been fetched from external job website"} |
145
|
|
|
* ) |
146
|
|
|
*/ |
147
|
|
|
private $synchronizationDate; |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Date when vacancy has been deleted |
151
|
|
|
* |
152
|
|
|
* @var DateTimeInterface |
153
|
|
|
* |
154
|
|
|
* @ORM\Column( |
155
|
|
|
* name="deletion_date", |
156
|
|
|
* type="datetime", |
157
|
|
|
* nullable=true, |
158
|
|
|
* options={"comment": "Date when vacancy has been deleted"} |
159
|
|
|
* ) |
160
|
|
|
*/ |
161
|
|
|
private $deletionDate; |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Vacancy constructor. |
165
|
|
|
*/ |
166
|
|
|
public function __construct() |
167
|
|
|
{ |
168
|
|
|
$this->categories = new ArrayCollection(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Returns vacancy identifier |
173
|
|
|
* |
174
|
|
|
* @return int |
175
|
|
|
*/ |
176
|
|
|
public function getId(): int |
177
|
|
|
{ |
178
|
|
|
return $this->id; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Returns alternative SEO-friendly vacancy identifier |
183
|
|
|
* |
184
|
|
|
* @return string |
185
|
|
|
*/ |
186
|
|
|
public function getSlug(): string |
187
|
|
|
{ |
188
|
|
|
return $this->slug; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Returns roadmap name by which the vacancy has been fetched |
193
|
|
|
* |
194
|
|
|
* @return string |
195
|
|
|
*/ |
196
|
|
|
public function getRoadmapName(): string |
197
|
|
|
{ |
198
|
|
|
return $this->roadmapName; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Sets roadmap name by which the vacancy has been fetched |
203
|
|
|
* |
204
|
|
|
* @param string $roadmapName Roadmap name by which the vacancy has been fetched |
205
|
|
|
* |
206
|
|
|
* @return void |
207
|
|
|
*/ |
208
|
|
|
public function setRoadmapName(string $roadmapName): void |
209
|
|
|
{ |
210
|
|
|
$this->roadmapName = $roadmapName; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Returns unique vacancy identifier on provider's website |
215
|
|
|
* |
216
|
|
|
* @return string |
217
|
|
|
*/ |
218
|
|
|
public function getExternalIdentifier(): string |
219
|
|
|
{ |
220
|
|
|
return $this->externalIdentifier; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Sets unique vacancy identifier on provider's website |
225
|
|
|
* |
226
|
|
|
* @param string $externalIdentifier Unique vacancy identifier on provider's website |
227
|
|
|
* |
228
|
|
|
* @return void |
229
|
|
|
*/ |
230
|
|
|
public function setExternalIdentifier(string $externalIdentifier): void |
231
|
|
|
{ |
232
|
|
|
$this->externalIdentifier = $externalIdentifier; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Returns company that posted the vacancy |
237
|
|
|
* |
238
|
|
|
* @return Company |
239
|
|
|
*/ |
240
|
|
|
public function getCompany(): Company |
241
|
|
|
{ |
242
|
|
|
return $this->company; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Sets company that posted the vacancy |
247
|
|
|
* |
248
|
|
|
* @param Company $company Company entity instance |
249
|
|
|
* |
250
|
|
|
* @return void |
251
|
|
|
*/ |
252
|
|
|
public function setCompany(Company $company): void |
253
|
|
|
{ |
254
|
|
|
if ($this->company instanceof Company) { |
|
|
|
|
255
|
|
|
$companyIdNew = $company->getId(); |
256
|
|
|
$companyId = $this->company->getId(); |
257
|
|
|
|
258
|
|
|
if ($companyIdNew === $companyId) { |
259
|
|
|
return; |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
$this->company = $company; |
264
|
|
|
|
265
|
|
|
$company->addVacancy($this); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Returns categories to which vacancy belongs to |
270
|
|
|
* |
271
|
|
|
* @return Category[] |
272
|
|
|
*/ |
273
|
|
|
public function getCategories(): array |
274
|
|
|
{ |
275
|
|
|
return $this->categories->toArray(); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Adds a category relation to which vacancy belongs to |
280
|
|
|
* |
281
|
|
|
* @param Category $category Vacancy category |
282
|
|
|
* |
283
|
|
|
* @return void |
284
|
|
|
*/ |
285
|
|
|
public function addCategory(Category $category): void |
286
|
|
|
{ |
287
|
|
|
if ($this->categories->contains($category)) { |
288
|
|
|
return; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
$this->categories->add($category); |
292
|
|
|
$category->addVacancy($this); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* Removes a category relation to which vacancy belongs to |
297
|
|
|
* |
298
|
|
|
* @param Category $category Vacancy category |
299
|
|
|
* |
300
|
|
|
* @return void |
301
|
|
|
*/ |
302
|
|
|
public function removeCategory(Category $category): void |
303
|
|
|
{ |
304
|
|
|
if (!$this->categories->contains($category)) { |
305
|
|
|
return; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
$this->categories->removeElement($category); |
309
|
|
|
$category->removeVacancy($this); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Returns last time when vacancy data has been changed |
314
|
|
|
* |
315
|
|
|
* @return DateTimeInterface |
316
|
|
|
*/ |
317
|
|
|
public function getSynchronizationDate(): DateTimeInterface |
318
|
|
|
{ |
319
|
|
|
return $this->synchronizationDate; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Sets last time when vacancy data has been fetched from external job website |
324
|
|
|
* |
325
|
|
|
* @param DateTimeInterface $synchronizationDate Last time when vacancy data has been changed |
326
|
|
|
* |
327
|
|
|
* @return void |
328
|
|
|
*/ |
329
|
|
|
public function setSynchronizationDate(DateTimeInterface $synchronizationDate): void |
330
|
|
|
{ |
331
|
|
|
$this->synchronizationDate = $synchronizationDate; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* Returns date when vacancy has been deleted |
336
|
|
|
* |
337
|
|
|
* @return DateTimeInterface |
338
|
|
|
*/ |
339
|
|
|
public function getDeletionDate(): DateTimeInterface |
340
|
|
|
{ |
341
|
|
|
return $this->deletionDate; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Sets date when vacancy was deleted |
346
|
|
|
* |
347
|
|
|
* @param DateTimeInterface|null $deletionDate Date when vacancy was deleted |
348
|
|
|
* |
349
|
|
|
* @return void |
350
|
|
|
*/ |
351
|
|
|
public function setDeletionDate(?DateTimeInterface $deletionDate): void |
352
|
|
|
{ |
353
|
|
|
$this->deletionDate = $deletionDate; |
354
|
|
|
} |
355
|
|
|
} |
356
|
|
|
|