1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
3 | |||
4 | namespace BristolSU\ControlDB\Models; |
||
5 | |||
6 | |||
7 | use BristolSU\ControlDB\Traits\RoleTrait; |
||
8 | use Illuminate\Database\Eloquent\Model; |
||
9 | use Illuminate\Database\Eloquent\SoftDeletes; |
||
10 | |||
11 | /** |
||
12 | * Represents a role |
||
13 | */ |
||
0 ignored issues
–
show
|
|||
14 | class Role extends Model implements \BristolSU\ControlDB\Contracts\Models\Role |
||
15 | { |
||
16 | |||
17 | use SoftDeletes, RoleTrait { |
||
18 | setDataProviderId as baseSetDataProviderId; |
||
19 | setGroupId as baseSetGroupId; |
||
20 | setPositionId as baseSetPositionId; |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Table to use |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $table = 'control_roles'; |
||
29 | |||
30 | /** |
||
31 | * Fillable attributes |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $fillable = ['data_provider_id', 'group_id', 'position_id']; |
||
36 | |||
37 | /** |
||
38 | * Attributes to append when casting to an array |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $appends = [ |
||
43 | 'data' |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * ID of the role |
||
48 | * |
||
49 | * @return int |
||
50 | */ |
||
51 | 61 | public function id(): int |
|
52 | { |
||
53 | 61 | return $this->id; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * ID of the data provider for the role |
||
58 | * |
||
59 | * @return int |
||
60 | */ |
||
61 | 26 | public function dataProviderId(): int |
|
62 | { |
||
63 | 26 | return $this->data_provider_id; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Laravel integration for a data property |
||
68 | * |
||
69 | * @return \BristolSU\ControlDB\Contracts\Models\DataRole |
||
70 | */ |
||
71 | 14 | public function getDataAttribute(): \BristolSU\ControlDB\Contracts\Models\DataRole |
|
72 | { |
||
73 | 14 | return $this->data(); |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * ID of the position the role has |
||
78 | * |
||
79 | * @return mixed |
||
80 | */ |
||
81 | 15 | public function positionId(): int |
|
82 | { |
||
83 | 15 | return $this->position_id; |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * ID of the group the role belongs to |
||
88 | * |
||
89 | * @return mixed |
||
90 | */ |
||
91 | 15 | public function groupId(): int |
|
92 | { |
||
93 | 15 | return $this->group_id; |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Set the ID of the data provider |
||
98 | * |
||
99 | * @param int $dataProviderId |
||
0 ignored issues
–
show
|
|||
100 | */ |
||
0 ignored issues
–
show
|
|||
101 | 2 | public function setDataProviderId(int $dataProviderId): void |
|
102 | { |
||
103 | 2 | $this->baseSetDataProviderId($dataProviderId); |
|
104 | 2 | $this->refresh(); |
|
105 | 2 | } |
|
106 | |||
107 | /** |
||
108 | * Set a group ID |
||
109 | * |
||
110 | * @param int $groupId |
||
0 ignored issues
–
show
|
|||
111 | */ |
||
0 ignored issues
–
show
|
|||
112 | 2 | public function setGroupId(int $groupId): void |
|
113 | { |
||
114 | 2 | $this->baseSetGroupId($groupId); |
|
115 | 2 | $this->refresh(); |
|
116 | 2 | } |
|
117 | |||
118 | /** |
||
119 | * Set a position ID |
||
120 | * |
||
121 | * @param int $positionId |
||
0 ignored issues
–
show
|
|||
122 | */ |
||
0 ignored issues
–
show
|
|||
123 | 2 | public function setPositionId(int $positionId): void |
|
124 | { |
||
125 | 2 | $this->baseSetPositionId($positionId); |
|
126 | 2 | $this->refresh(); |
|
127 | 2 | } |
|
128 | |||
129 | |||
130 | } |
||
131 |