1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\ControlDB\Models\Tags; |
4
|
|
|
|
5
|
|
|
use BristolSU\ControlDB\Scopes\RoleTagScope; |
6
|
|
|
use BristolSU\ControlDB\Traits\Tags\RoleTagTrait; |
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
8
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class RoleTag |
12
|
|
|
*/ |
|
|
|
|
13
|
|
|
class RoleTag extends Model implements \BristolSU\ControlDB\Contracts\Models\Tags\RoleTag |
14
|
|
|
{ |
15
|
|
|
use SoftDeletes, RoleTagTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Boot the model |
19
|
|
|
* |
20
|
|
|
* - Add a global scope to only return role tags |
21
|
|
|
*/ |
|
|
|
|
22
|
49 |
|
protected static function boot() |
23
|
|
|
{ |
24
|
49 |
|
parent::boot(); |
25
|
49 |
|
static::addGlobalScope(new RoleTagScope()); |
26
|
49 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Table to use |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $table = 'control_tags'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Fillable properties |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $fillable = [ |
41
|
|
|
'name', 'description', 'reference', 'tag_category_id' |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Append the full reference |
46
|
|
|
* |
47
|
|
|
* @var array Attributes to append |
48
|
|
|
*/ |
49
|
|
|
protected $appends = [ |
50
|
|
|
'full_reference' |
51
|
|
|
]; |
52
|
|
|
|
53
|
7 |
|
public function getFullReferenceAttribute() |
|
|
|
|
54
|
|
|
{ |
55
|
7 |
|
return $this->fullReference(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* ID of the role tag |
60
|
|
|
* |
61
|
|
|
* @return int |
62
|
|
|
*/ |
63
|
25 |
|
public function id(): int |
64
|
|
|
{ |
65
|
25 |
|
return $this->id; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Name of the tag |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
3 |
|
public function name(): string |
74
|
|
|
{ |
75
|
3 |
|
return $this->name; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Description of the tag |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
3 |
|
public function description(): string |
84
|
|
|
{ |
85
|
3 |
|
return $this->description; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Reference of the tag |
90
|
|
|
* |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
11 |
|
public function reference(): string |
94
|
|
|
{ |
95
|
11 |
|
return $this->reference; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* ID of the tag category |
100
|
|
|
* |
101
|
|
|
* @return int |
102
|
|
|
*/ |
103
|
13 |
|
public function categoryId(): int |
104
|
|
|
{ |
105
|
13 |
|
return $this->tag_category_id; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Set the name of the tag |
110
|
|
|
* |
111
|
|
|
* @param string $name |
|
|
|
|
112
|
|
|
*/ |
|
|
|
|
113
|
2 |
|
public function setName(string $name): void |
114
|
|
|
{ |
115
|
2 |
|
$this->name = $name; |
116
|
2 |
|
$this->save(); |
117
|
2 |
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Set the description of the tagTag Reference |
121
|
|
|
* |
122
|
|
|
* @param string $description |
|
|
|
|
123
|
|
|
*/ |
|
|
|
|
124
|
2 |
|
public function setDescription(string $description): void |
125
|
|
|
{ |
126
|
2 |
|
$this->description = $description; |
127
|
2 |
|
$this->save(); |
128
|
2 |
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Set the reference of the tag |
132
|
|
|
* |
133
|
|
|
* @param string $reference |
|
|
|
|
134
|
|
|
*/ |
|
|
|
|
135
|
2 |
|
public function setReference(string $reference): void |
136
|
|
|
{ |
137
|
2 |
|
$this->reference = $reference; |
138
|
2 |
|
$this->save(); |
139
|
2 |
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Set the tag category ID |
143
|
|
|
* |
144
|
|
|
* @param int $categoryId |
|
|
|
|
145
|
|
|
*/ |
|
|
|
|
146
|
2 |
|
public function setTagCategoryId($categoryId): void |
147
|
|
|
{ |
148
|
2 |
|
$this->tag_category_id = $categoryId; |
149
|
2 |
|
$this->save(); |
150
|
2 |
|
} |
151
|
|
|
|
152
|
|
|
} |
153
|
|
|
|