Translation::locale()   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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Translation\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Translation extends Model
8
{
9
10
    /**
11
     *  Table name in the database.
12
     *
13
     * @var string
14
     */
15
    protected $table = 'translations';
16
17
    /**
18
     *  List of variables that can be mass assigned
19
     *
20
     * @var array
21
     */
22
    protected $fillable = [
23
        'locale', 'namespace', 'group', 'item', 'text', 'unstable',
24
    ];
25
    // from lararavel support
26
    // protected $fillable = ['table_name', 'column_name', 'foreign_key', 'locale', 'value'];
27
28
    /**
29
     *  Each translation belongs to a language.
30
     */
31
    public function language()
32
    {
33
        return $this->belongsTo(Language::class, 'locale', 'locale');
34
    }
35
36
    /**
37
     *  Returns the full translation code for an entry: namespace.group.item
38
     *
39
     * @return string
40
     */
41
    public function getCodeAttribute()
42
    {
43
        return $this->namespace === '*' ? "{$this->group}.{$this->item}" : "{$this->namespace}::{$this->group}.{$this->item}";
44
    }
45
46
    /**
47
     *  Flag this entry as Reviewed
48
     *
49
     * @return void
50
     */
51
    public function flagAsReviewed()
52
    {
53
        $this->unstable = 0;
54
    }
55
56
    /**
57
     *  Set the translation to the locked state
58
     *
59
     * @return void
60
     */
61
    public function lock()
62
    {
63
        $this->locked = 1;
64
    }
65
66
    /**
67
     *  Check if the translation is locked
68
     *
69
     * @return boolean
70
     */
71
    public function isLocked()
72
    {
73
        return (boolean) $this->locked;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function locale()
80
    {
81
        return $this->belongsTo(Locale::class, 'locale', 'code');
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function parent()
88
    {
89
        return $this->belongsTo(self::class, $this->getForeignKey());
90
    }
91
}