Completed
Push — master ( 1b817e...6c15b7 )
by Jeroen
39:29
created

Kunstmaan/TranslatorBundle/Entity/Translation.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\TranslatorBundle\Entity;
4
5
use DateTime;
6
use Doctrine\ORM\Mapping as ORM;
7
use Kunstmaan\TranslatorBundle\Model\Translation as TranslationModel;
8
use Symfony\Component\Validator\Constraints as Assert;
9
10
/**
11
 * @ORM\Entity(repositoryClass="Kunstmaan\TranslatorBundle\Repository\TranslationRepository")
12
 * @ORM\Table(
13
 *     name="kuma_translation",
14
 *     uniqueConstraints={
15
 *         @ORM\UniqueConstraint(name="keyword_per_locale", columns={"keyword", "locale", "domain"}),
16
 *         @ORM\UniqueConstraint(name="translation_id_per_locale", columns={"translation_id", "locale"}),
17
 *     },
18
 *     indexes={@ORM\Index(name="idx_translation_locale_domain", columns={"locale", "domain"})}
19
 * )
20
 * @ORM\HasLifecycleCallbacks
21
 */
22
class Translation
23
{
24
    const FLAG_NEW = 'new';
25
    const FLAG_UPDATED = 'updated';
26
    const STATUS_DEPRECATED = 'deprecated';
27
    const STATUS_DISABLED = 'disabled';
28
    const STATUS_ENABLED = 'enabled';
29
30
    /**
31
     * @ORM\Id
32
     * @ORM\Column(type="integer")
33
     * @ORM\GeneratedValue(strategy="AUTO")
34
     */
35
    protected $id;
36
37
    /**
38
     * @ORM\Column(type="integer", name="translation_id", nullable=true)
39
     * @Assert\NotBlank()
40
     */
41
    protected $translationId;
42
43
    /**
44
     * The translations keyword to use in your template or call from the translator
45
     *
46
     * @ORM\Column(type="string", nullable=true)
47
     * @Assert\NotBlank()
48
     */
49
    protected $keyword;
50
51
    /**
52
     * The translations keyword to use in your template or call from the translator
53
     *
54
     * @ORM\Column(type="string", length=5, nullable=true)
55
     * @Assert\NotBlank()
56
     */
57
    protected $locale;
58
59
    /**
60
     * @var string
61
     *             The translations deprecation date
62
     *
63
     * @ORM\column(type="string", length=10, options={"default" : "enabled"})
64
     */
65
    protected $status = self::STATUS_ENABLED;
66
67
    /**
68
     * Location where the translation comes from
69
     *
70
     * @ORM\Column(type="string", length=50, nullable=true)
71
     */
72
    protected $file;
73
74
    /**
75
     * Translation
76
     *
77
     * @var string
78
     * @ORM\Column(type="text", nullable=true)
79
     * @Assert\NotBlank()
80
     */
81
    protected $text;
82
83
    /**
84
     * @ORM\Column(type="string", length=30, nullable=true)
85
     * @Assert\NotBlank()
86
     */
87
    protected $domain;
88
89
    /**
90
     * @var \DateTime
91
     *
92
     * @ORM\Column(type="datetime", name="created_at", nullable=true)
93
     */
94
    protected $createdAt;
95
96
    /**
97
     * @var \DateTime
98
     *
99
     * @ORM\Column(type="datetime", name="updated_at", nullable=true)
100
     */
101
    protected $updatedAt;
102
103
    /**
104
     * A flag which defines the status of a specific translations ('updated', 'new', ..)
105
     *
106
     * @var string
107
     *
108
     * @ORM\Column(type="string", length=20, nullable=true)
109
     */
110
    protected $flag = null;
111
112
    /**
113
     * @ORM\PrePersist
114
     */
115 View Code Duplication
    public function prePersist()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
    {
117
        $this->createdAt = new DateTime();
118
        $this->updatedAt = new DateTime();
119
        $this->flag = self::FLAG_NEW;
120
121
        return $this->id;
122
    }
123
124
    /**
125
     * @ORM\PreUpdate
126
     */
127 View Code Duplication
    public function preUpdate()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
    {
129
        $this->updatedAt = new DateTime();
130
131
        if ($this->flag === null) {
132
            $this->flag = self::FLAG_UPDATED;
133
        }
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    public function getId()
140
    {
141
        return $this->id;
142
    }
143
144
    /**
145
     * @param string $id
146
     *
147
     * @return Translation
148
     */
149
    public function setId($id)
150
    {
151
        $this->id = $id;
152
153
        return $this;
154
    }
155
156
    /**
157
     * @return string
158
     */
159
    public function getKeyword()
160
    {
161
        return $this->keyword;
162
    }
163
164
    /**
165
     * @param string $keyword
166
     *
167
     * @return Translation
168
     */
169
    public function setKeyword($keyword)
170
    {
171
        $this->keyword = $keyword;
172
173
        return $this;
174
    }
175
176
    /**
177
     * @return string
178
     */
179
    public function getLocale()
180
    {
181
        return $this->locale;
182
    }
183
184
    /**
185
     * @param string $locale
186
     *
187
     * @return Translation
188
     */
189
    public function setLocale($locale)
190
    {
191
        $this->locale = $locale;
192
193
        return $this;
194
    }
195
196
    /**
197
     * @return string
198
     */
199
    public function getFile()
200
    {
201
        return $this->file;
202
    }
203
204
    /**
205
     * @param string $file
206
     *
207
     * @return Translation
208
     */
209
    public function setFile($file)
210
    {
211
        $this->file = $file;
212
213
        return $this;
214
    }
215
216
    /**
217
     * @return string
218
     */
219
    public function getText()
220
    {
221
        return $this->text;
222
    }
223
224
    /**
225
     * @param string $text
226
     *
227
     * @return Translation
228
     */
229
    public function setText($text)
230
    {
231
        $this->text = $text;
232
233
        return $this;
234
    }
235
236
    /**
237
     * @return string
238
     */
239
    public function getDomain()
240
    {
241
        return $this->domain;
242
    }
243
244
    /**
245
     * @param string $domain
246
     *
247
     * @return Translation
248
     */
249
    public function setDomain($domain)
250
    {
251
        $this->domain = $domain;
252
253
        return $this;
254
    }
255
256
    /**
257
     * @return \DateTime
258
     */
259
    public function getCreatedAt()
260
    {
261
        return $this->createdAt;
262
    }
263
264
    /**
265
     * @param \DateTime $createdAt
266
     *
267
     * @return Translation
268
     */
269
    public function setCreatedAt(DateTime $createdAt)
270
    {
271
        $this->createdAt = $createdAt;
272
273
        return $this;
274
    }
275
276
    /**
277
     * @return \DateTime
278
     */
279
    public function getUpdatedAt()
280
    {
281
        return $this->updatedAt;
282
    }
283
284
    /**
285
     * @param DateTime $updatedAt
286
     *
287
     * @return Translation
288
     */
289
    public function setUpdatedAt(DateTime $updatedAt)
290
    {
291
        $this->updatedAt = $updatedAt;
292
293
        return $this;
294
    }
295
296
    /**
297
     * @return string
298
     */
299
    public function getFlag()
300
    {
301
        return $this->flag;
302
    }
303
304
    /**
305
     * @param string $flag
306
     *
307
     * @return Translation
308
     */
309
    public function setFlag($flag)
310
    {
311
        $this->flag = $flag;
312
313
        return $this;
314
    }
315
316
    /**
317
     * @param string $translationId
318
     *
319
     * @return Translation
320
     */
321
    public function setTranslationId($translationId)
322
    {
323
        $this->translationId = $translationId;
324
325
        return $this;
326
    }
327
328
    /**
329
     * @return string
330
     */
331
    public function getTranslationId()
332
    {
333
        return $this->translationId;
334
    }
335
336
    /**
337
     * @return string
338
     */
339
    public function getStatus()
340
    {
341
        return $this->status;
342
    }
343
344
    /**
345
     * @param string $status
346
     *
347
     * @return Translation
348
     */
349
    public function setStatus($status)
350
    {
351
        $this->status = $status;
352
353
        return $this;
354
    }
355
356
    /**
357
     * @return bool
358
     */
359
    public function isDisabled()
360
    {
361
        return $this->getStatus() === self::STATUS_DISABLED;
362
    }
363
364
    /**
365
     * @return bool
366
     */
367
    public function isDeprecated()
368
    {
369
        return $this->getStatus() === self::STATUS_DEPRECATED;
370
    }
371
372
    /**
373
     * @param int $id
374
     *
375
     * @return TranslationModel
376
     */
377
    public function getTranslationModel($id = null)
378
    {
379
        $translationModel = new TranslationModel();
380
        $translationModel->setKeyword($this->getKeyword());
381
        $translationModel->setDomain($this->getDomain());
382
        $translationModel->addText($this->getLocale(), $this->getText(), $id);
383
384
        return $translationModel;
385
    }
386
}
387