1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[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
|
|
|
|
12
|
|
|
namespace Tinyissue\Model; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Model; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Tag is model class for tags. |
18
|
|
|
* |
19
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
20
|
|
|
* |
21
|
|
|
* @property int $id |
22
|
|
|
* @property int $parent_id |
23
|
|
|
* @property string $name |
24
|
|
|
* @property string $fullname |
25
|
|
|
* @property string $bgcolor |
26
|
|
|
* @property bool $group |
27
|
|
|
* @property Tag $parent |
28
|
|
|
* @property int $role_limit |
29
|
|
|
* @property int $message_limit |
30
|
|
|
* @property int $readonly |
31
|
|
|
*/ |
32
|
|
|
class Tag extends Model |
33
|
|
|
{ |
34
|
|
|
use Traits\Tag\CrudTrait, |
35
|
|
|
Traits\Tag\QueryTrait, |
36
|
|
|
Traits\Tag\RelationTrait, |
37
|
|
|
Traits\Tag\CountTrait; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Core tag: Open. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
const STATUS_OPEN = 'open'; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Core tag: Closed. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
const STATUS_CLOSED = 'closed'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Core tag group: Status. |
55
|
|
|
* |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
const GROUP_STATUS = 'status'; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Core tag group: Type. |
62
|
|
|
* |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
const GROUP_TYPE = 'type'; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Core tag group: Resolution. |
69
|
|
|
* |
70
|
|
|
* @var string |
71
|
|
|
*/ |
72
|
|
|
const GROUP_RESOLUTION = 'resolution'; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Timestamp enabled. |
76
|
|
|
* |
77
|
|
|
* @var bool |
78
|
|
|
*/ |
79
|
|
|
public $timestamps = true; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* List of allowed columns to be used in $this->fill(). |
83
|
|
|
* |
84
|
|
|
* @var array |
85
|
|
|
*/ |
86
|
|
|
public $fillable = ['parent_id', 'name', 'bgcolor', 'group', 'role_limit', 'message_limit', 'readonly']; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Name of database table. |
90
|
|
|
* |
91
|
|
|
* @var string |
92
|
|
|
*/ |
93
|
|
|
protected $table = 'tags'; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Generate a URL for the tag. |
97
|
|
|
* |
98
|
|
|
* @param string $url |
99
|
|
|
* |
100
|
|
|
* @return mixed |
101
|
2 |
|
*/ |
102
|
|
|
public function to($url) |
103
|
2 |
|
{ |
104
|
|
|
return \URL::to('administration/tag/' . $this->id . (($url) ? '/' . $url : '')); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns tag full name with prefix group name and ":" in between. |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
33 |
|
*/ |
112
|
|
|
public function getFullNameAttribute() |
113
|
33 |
|
{ |
114
|
|
|
return ucwords($this->attributes['name']); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Whether or not the current user can view this tag. |
119
|
|
|
* |
120
|
|
|
* @return bool |
121
|
7 |
|
*/ |
122
|
|
|
public function canView() |
123
|
7 |
|
{ |
124
|
|
|
return auth()->user()->role_id >= $this->role_limit; |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Whether or not the tag to mark issue as ready only. |
129
|
|
|
* |
130
|
|
|
* @return bool |
131
|
5 |
|
*/ |
132
|
|
|
public function isReadOnly() |
133
|
|
|
{ |
134
|
5 |
|
return (boolean) $this->readonly; |
135
|
5 |
|
} |
136
|
5 |
|
|
137
|
5 |
|
/** |
138
|
5 |
|
* Return an array of tag details. |
139
|
|
|
* |
140
|
|
|
* @return array |
141
|
|
|
*/ |
142
|
|
|
public function toShortArray() |
143
|
|
|
{ |
144
|
|
|
return [ |
145
|
|
|
'id' => $this->id, |
146
|
|
|
'name' => $this->fullname, |
147
|
4 |
|
'bgcolor' => $this->bgcolor, |
148
|
|
|
'message_limit' => $this->message_limit, |
149
|
|
|
'group' => $this->parent->fullname, |
150
|
4 |
|
]; |
151
|
4 |
|
} |
152
|
4 |
|
|
153
|
|
|
/** |
154
|
|
|
* Returns an array of core groups. |
155
|
|
|
* |
156
|
|
|
* @return array |
157
|
|
|
*/ |
158
|
|
|
public static function getCoreGroups() |
159
|
|
|
{ |
160
|
|
|
return [ |
161
|
|
|
self::GROUP_STATUS, |
162
|
|
|
self::GROUP_TYPE, |
163
|
3 |
|
self::GROUP_RESOLUTION, |
164
|
|
|
]; |
165
|
3 |
|
} |
166
|
3 |
|
|
167
|
|
|
/** |
168
|
|
|
* Whether or not the user is allowed to receive messages that contains the current tag. |
169
|
1 |
|
* |
170
|
|
|
* @param User $user |
171
|
|
|
* |
172
|
|
|
* @return bool |
173
|
|
|
*/ |
174
|
|
|
public function allowMessagesToUser(User $user) |
175
|
|
|
{ |
176
|
|
|
if (!$this->message_limit || $this->message_limit <= $user->role_id) { |
177
|
|
|
return true; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
return false; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: