|
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\Vacancy; |
|
17
|
|
|
|
|
18
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
19
|
|
|
use Doctrine\Common\Collections\Collection; |
|
20
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
21
|
|
|
use Veslo\AnthillBundle\Entity\Vacancy; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Vacancy category |
|
25
|
|
|
* |
|
26
|
|
|
* @ORM\Table(name="anthill_vacancy_category") |
|
27
|
|
|
* @ORM\Entity(readOnly=true) |
|
28
|
|
|
* @ORM\Cache(usage="READ_ONLY", region="vacancies") |
|
29
|
|
|
*/ |
|
30
|
|
|
class Category |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Vacancy category identifier |
|
34
|
|
|
* |
|
35
|
|
|
* @var int |
|
36
|
|
|
* |
|
37
|
|
|
* @ORM\Column(name="id", type="integer", options={"comment": "Vacancy category identifier"}) |
|
38
|
|
|
* @ORM\Id |
|
39
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
40
|
|
|
*/ |
|
41
|
|
|
private $id; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Vacancy category name |
|
45
|
|
|
* |
|
46
|
|
|
* @var string |
|
47
|
|
|
* |
|
48
|
|
|
* @ORM\Column(name="name", type="string", length=255, unique=true, options={"comment": "Vacancy category name"}) |
|
49
|
|
|
*/ |
|
50
|
|
|
private $name; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Vacancies that belongs to category |
|
54
|
|
|
* |
|
55
|
|
|
* @var Collection<Vacancy> |
|
56
|
|
|
* |
|
57
|
|
|
* @ORM\ManyToMany(targetEntity="Veslo\AnthillBundle\Entity\Vacancy", mappedBy="categories", fetch="EXTRA_LAZY") |
|
58
|
|
|
*/ |
|
59
|
|
|
private $vacancies; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Category constructor. |
|
63
|
|
|
*/ |
|
64
|
|
|
public function __construct() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->vacancies = new ArrayCollection(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Returns vacancy category identifier |
|
71
|
|
|
* |
|
72
|
|
|
* @return int |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getId(): int |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->id; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Sets vacancy category name |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $name Vacancy category name |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
*/ |
|
86
|
|
|
public function setName(string $name): void |
|
87
|
|
|
{ |
|
88
|
|
|
$this->name = $name; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Returns vacancy category name |
|
93
|
|
|
* |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getName(): string |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->name; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Returns vacancies that belongs to the category |
|
103
|
|
|
* |
|
104
|
|
|
* @return Vacancy[] |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getVacancies(): array |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->vacancies->toArray(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Adds a vacancy to the category |
|
113
|
|
|
* |
|
114
|
|
|
* @param Vacancy $vacancy Vacancy |
|
115
|
|
|
* |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
|
|
public function addVacancy(Vacancy $vacancy): void |
|
119
|
|
|
{ |
|
120
|
|
|
$this->vacancies->add($vacancy); |
|
121
|
|
|
$vacancy->addCategory($this); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Removes a vacancy from the category |
|
126
|
|
|
* |
|
127
|
|
|
* @param Vacancy $vacancy Vacancy |
|
128
|
|
|
* |
|
129
|
|
|
* @return void |
|
130
|
|
|
*/ |
|
131
|
|
|
public function removeVacancy(Vacancy $vacancy): void |
|
132
|
|
|
{ |
|
133
|
|
|
if (!$this->vacancies->contains($vacancy)) { |
|
134
|
|
|
return; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
$this->vacancies->removeElement($vacancy); |
|
138
|
|
|
$vacancy->removeCategory($this); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|