Group::getTranslations()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Tag;
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;
23
use Veslo\SanityBundle\Entity\Vacancy\Tag\Group\Translation\Entry;
24
25
/**
26
 * Group for sanity tags
27
 *
28
 * @ORM\Table(name="sanity_vacancy_tag_group")
29
 * @ORM\Entity(readOnly=true)
30
 * @ORM\Cache(usage="READ_ONLY", region="index")
31
 * @Gedmo\TranslationEntity(class="Veslo\SanityBundle\Entity\Vacancy\Tag\Group\Translation\Entry")
32
 */
33
class Group
34
{
35
    /**
36
     * Identifier for group of sanity tags
37
     *
38
     * @var int
39
     *
40
     * @ORM\Column(name="id", type="integer", options={"comment": "Identifier for group of sanity tags"})
41
     * @ORM\Id
42
     * @ORM\GeneratedValue(strategy="AUTO")
43
     */
44
    private $id;
45
46
    /**
47
     * Sanity tags group name
48
     *
49
     * @var string
50
     *
51
     * @ORM\Column(name="name", type="string", length=255, unique=true, options={"comment": "Sanity tags group name"})
52
     */
53
    private $name;
54
55
    /**
56
     * Sanity tags group description
57
     *
58
     * @var string
59
     *
60
     * @ORM\Column(name="description", type="text", nullable=true, options={"comment": "Sanity tags group description"})
61
     * @Gedmo\Translatable
62
     */
63
    private $description;
64
65
    /**
66
     * Sanity tags group color
67
     *
68
     * @var string
69
     *
70
     * @ORM\Column(
71
     *     name="color",
72
     *     type="string",
73
     *     length=255,
74
     *     nullable=true,
75
     *     options={"comment": "Sanity tags group color"}
76
     * )
77
     */
78
    private $color;
79
80
    /**
81
     * Translation entries for sanity group fields
82
     *
83
     * @var Collection<Entry>
84
     *
85
     * @ORM\OneToMany(
86
     *     targetEntity="Veslo\SanityBundle\Entity\Vacancy\Tag\Group\Translation\Entry",
87
     *     mappedBy="object",
88
     *     cascade={"persist"}
89
     * )
90
     */
91
    private $translations;
92
93
    /**
94
     * Sanity tags in this group
95
     *
96
     * @var Collection<Tag>
97
     *
98
     * @ORM\OneToMany(targetEntity="Veslo\SanityBundle\Entity\Vacancy\Tag", mappedBy="group")
99
     */
100
    private $tags;
101
102
    /**
103
     * Group constructor.
104
     */
105
    public function __construct()
106
    {
107
        $this->translations = new ArrayCollection();
108
        $this->tags         = new ArrayCollection();
109
    }
110
111
    /**
112
     * Returns identifier for group of sanity tags
113
     *
114
     * @return int
115
     */
116
    public function getId(): int
117
    {
118
        return $this->id;
119
    }
120
121
    /**
122
     * Returns sanity tags group name
123
     *
124
     * @return string
125
     */
126
    public function getName(): string
127
    {
128
        return $this->name;
129
    }
130
131
    /**
132
     * Sets sanity tags group name
133
     *
134
     * @param string $name Sanity tags group name
135
     *
136
     * @return void
137
     */
138
    public function setName(string $name): void
139
    {
140
        $this->name = $name;
141
    }
142
143
    /**
144
     * Returns sanity tags group description
145
     *
146
     * @return string
147
     */
148
    public function getDescription(): string
149
    {
150
        return $this->description;
151
    }
152
153
    /**
154
     * Sets sanity tags group description
155
     *
156
     * @param string $description Sanity tags group description
157
     *
158
     * @return void
159
     */
160
    public function setDescription(string $description): void
161
    {
162
        $this->description = $description;
163
    }
164
165
    /**
166
     * Returns sanity tags group color
167
     *
168
     * @return string
169
     */
170
    public function getColor(): string
171
    {
172
        return $this->color;
173
    }
174
175
    /**
176
     * Sets sanity tags group color
177
     *
178
     * @param string $color Sanity tags group color
179
     *
180
     * @return void
181
     */
182
    public function setColor(string $color): void
183
    {
184
        $this->color = $color;
185
    }
186
187
    /**
188
     * Returns translation entries for sanity group fields
189
     *
190
     * @return Entry[]
191
     */
192
    public function getTranslations(): array
193
    {
194
        return $this->translations->toArray();
195
    }
196
197
    /**
198
     * Adds a translation entry for sanity group field
199
     *
200
     * @param Entry $translation Sanity group translation entry
201
     *
202
     * @return void
203
     */
204
    public function addTranslation(Entry $translation): void
205
    {
206
        if ($this->translations->contains($translation)) {
207
            return;
208
        }
209
210
        $this->translations->add($translation);
211
        $translation->setObject($this);
212
    }
213
214
    /**
215
     * Returns sanity tags that belongs to the group
216
     *
217
     * @return Tag[]
218
     */
219
    public function getTags(): array
220
    {
221
        return $this->tags->toArray();
222
    }
223
224
    /**
225
     * Adds a sanity tag to the group
226
     *
227
     * @param Tag $tag Sanity tag
228
     *
229
     * @return void
230
     */
231
    public function addTag(Tag $tag): void
232
    {
233
        if ($this->tags->contains($tag)) {
234
            return;
235
        }
236
237
        $this->tags->add($tag);
238
        $tag->setGroup($this);
239
    }
240
}
241