Tag::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Veslo project <https://github.com/symfony-doge/veslo>.
5
 *
6
 * (C) 2019 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\SanityBundle\Entity\Vacancy;
17
18
use Doctrine\Common\Collections\ArrayCollection;
19
use Doctrine\Common\Collections\Collection;
20
use Doctrine\ORM\Mapping as ORM;
21
use Gedmo\Mapping\Annotation as Gedmo;
22
use Veslo\SanityBundle\Entity\Vacancy\Tag\Group;
23
use Veslo\SanityBundle\Entity\Vacancy\Tag\Translation\Entry;
24
25
/**
26
 * Sanity tag
27
 *
28
 * @ORM\Table(name="sanity_vacancy_tag")
29
 * @ORM\Entity(readOnly=true)
30
 * @ORM\Cache(usage="READ_ONLY", region="index")
31
 * @Gedmo\TranslationEntity(class="Veslo\SanityBundle\Entity\Vacancy\Tag\Translation\Entry")
32
 */
33
class Tag
34
{
35
    /**
36
     * Sanity tag identifier
37
     *
38
     * @var int
39
     *
40
     * @ORM\Column(name="id", type="integer", options={"comment": "Sanity tag identifier"})
41
     * @ORM\Id
42
     * @ORM\GeneratedValue(strategy="AUTO")
43
     */
44
    private $id;
45
46
    /**
47
     * Group to which sanity tag belongs to
48
     *
49
     * @var Group
50
     *
51
     * @ORM\ManyToOne(targetEntity="Veslo\SanityBundle\Entity\Vacancy\Tag\Group", inversedBy="tags")
52
     * @ORM\JoinColumn(name="group_id", referencedColumnName="id", onDelete="CASCADE")
53
     */
54
    private $group;
55
56
    /**
57
     * Sanity tag name
58
     *
59
     * @var string
60
     *
61
     * @ORM\Column(name="name", type="string", length=255, unique=true, options={"comment": "Sanity tag name"})
62
     */
63
    private $name;
64
65
    /**
66
     * Sanity tag title
67
     *
68
     * @var string
69
     *
70
     * @ORM\Column(name="title", type="string", length=255, options={"comment": "Sanity tag title"})
71
     * @Gedmo\Translatable
72
     */
73
    private $title;
74
75
    /**
76
     * Sanity tag description
77
     *
78
     * @var string
79
     *
80
     * @ORM\Column(name="description", type="text", options={"comment": "Sanity tag description"})
81
     * @Gedmo\Translatable
82
     */
83
    private $description;
84
85
    /**
86
     * Sanity tag color
87
     *
88
     * @var string
89
     *
90
     * @ORM\Column(name="color", type="string", length=255, options={"comment": "Sanity tag color"})
91
     */
92
    private $color;
93
94
    /**
95
     * Sanity tag image URL
96
     *
97
     * @var string
98
     *
99
     * @ORM\Column(name="image_url", type="string", length=255, options={"comment": "Sanity tag image URL"})
100
     */
101
    private $imageUrl;
102
103
    /**
104
     * Translation entries for sanity tag fields
105
     *
106
     * @var Collection<Entry>
107
     *
108
     * @ORM\OneToMany(
109
     *     targetEntity="Veslo\SanityBundle\Entity\Vacancy\Tag\Translation\Entry",
110
     *     mappedBy="object",
111
     *     cascade={"persist"}
112
     * )
113
     */
114
    private $translations;
115
116
    /**
117
     * Indexes to which sanity tag was offered by indexation result
118
     *
119
     * @var Collection<Index>
120
     *
121
     * @ORM\ManyToMany(targetEntity="Veslo\SanityBundle\Entity\Vacancy\Index", mappedBy="tags")
122
     */
123
    private $indexes;
124
125
    /**
126
     * Tag constructor.
127
     */
128
    public function __construct()
129
    {
130
        $this->translations = new ArrayCollection();
131
        $this->indexes      = new ArrayCollection();
132
    }
133
134
    /**
135
     * Returns sanity tag identifier
136
     *
137
     * @return int
138
     */
139
    public function getId(): int
140
    {
141
        return $this->id;
142
    }
143
144
    /**
145
     * Returns group to which sanity tag belongs to
146
     *
147
     * @return Group
148
     */
149
    public function getGroup(): Group
150
    {
151
        return $this->group;
152
    }
153
154
    /**
155
     * Sets group to which sanity tag belongs to
156
     *
157
     * @param Group $group Group to which sanity tag belongs to
158
     *
159
     * @return void
160
     */
161
    public function setGroup(Group $group): void
162
    {
163
        // Group change for sanity tag normally should not happen.
164
        // We do not directly control sanity index data, it comes from external source.
165
        if ($this->group instanceof Group) {
0 ignored issues
show
introduced by
$this->group is always a sub-type of Veslo\SanityBundle\Entity\Vacancy\Tag\Group.
Loading history...
166
            return;
167
        }
168
169
        $this->group = $group;
170
        $group->addTag($this);
171
    }
172
173
    /**
174
     * Returns sanity tag name
175
     *
176
     * @return string
177
     */
178
    public function getName(): string
179
    {
180
        return $this->name;
181
    }
182
183
    /**
184
     * Sets sanity tag name
185
     *
186
     * @param string $name Sanity tag name
187
     *
188
     * @return void
189
     */
190
    public function setName(string $name): void
191
    {
192
        $this->name = $name;
193
    }
194
195
    /**
196
     * Returns sanity tag title
197
     *
198
     * @return string
199
     */
200
    public function getTitle(): string
201
    {
202
        return $this->title;
203
    }
204
205
    /**
206
     * Sets sanity tag title
207
     *
208
     * @param string $title Sanity tag title
209
     *
210
     * @return void
211
     */
212
    public function setTitle(string $title): void
213
    {
214
        $this->title = $title;
215
    }
216
217
    /**
218
     * Returns sanity tag description
219
     *
220
     * @return string
221
     */
222
    public function getDescription(): string
223
    {
224
        return $this->description;
225
    }
226
227
    /**
228
     * Sets sanity tag description
229
     *
230
     * @param string $description Sanity tag description
231
     */
232
    public function setDescription(string $description): void
233
    {
234
        $this->description = $description;
235
    }
236
237
    /**
238
     * Returns sanity tag color
239
     *
240
     * @return string
241
     */
242
    public function getColor(): string
243
    {
244
        return $this->color;
245
    }
246
247
    /**
248
     * Sets sanity tag color
249
     *
250
     * @param string $color Sanity tag color
251
     *
252
     * @return void
253
     */
254
    public function setColor(string $color): void
255
    {
256
        $this->color = $color;
257
    }
258
259
    /**
260
     * Returns sanity tag image URL
261
     *
262
     * @return string
263
     */
264
    public function getImageUrl(): string
265
    {
266
        return $this->imageUrl;
267
    }
268
269
    /**
270
     * Sets sanity tag image URL
271
     *
272
     * @param string $imageUrl Sanity tag image URL
273
     *
274
     * @return void
275
     */
276
    public function setImageUrl(string $imageUrl): void
277
    {
278
        $this->imageUrl = $imageUrl;
279
    }
280
281
    /**
282
     * Returns translation entries for sanity tag fields
283
     *
284
     * @return Entry[]
285
     */
286
    public function getTranslations(): array
287
    {
288
        return $this->translations->toArray();
289
    }
290
291
    /**
292
     * Adds a translation entry for sanity tag field
293
     *
294
     * @param Entry $translation Sanity tag translation entry
295
     *
296
     * @return void
297
     */
298
    public function addTranslation(Entry $translation): void
299
    {
300
        if ($this->translations->contains($translation)) {
301
            return;
302
        }
303
304
        $this->translations->add($translation);
305
        $translation->setObject($this);
306
    }
307
308
    /**
309
     * Returns indexes to which sanity tag was offered
310
     *
311
     * @return Index[]
312
     */
313
    public function getIndexes(): array
314
    {
315
        return $this->indexes->toArray();
316
    }
317
318
    /**
319
     * Adds an index to which sanity tag was offered
320
     *
321
     * @param Index $index Index to which sanity tag was offered
322
     *
323
     * @return void
324
     */
325
    public function addIndex(Index $index): void
326
    {
327
        if ($this->indexes->contains($index)) {
328
            return;
329
        }
330
331
        $this->indexes->add($index);
332
        $index->addTag($this);
333
    }
334
}
335