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
|
|
|
*/ |
29
|
|
|
class Tag extends Model |
30
|
|
|
{ |
31
|
|
|
use Traits\Tag\CrudTrait, |
32
|
|
|
Traits\Tag\QueryTrait, |
33
|
|
|
Traits\Tag\RelationTrait, |
34
|
|
|
Traits\Tag\CountTrait, |
35
|
|
|
Traits\Tag\DataMappingTrait; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Core tag: Open. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
const STATUS_OPEN = 'open'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Core tag: Closed. |
46
|
|
|
* |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
const STATUS_CLOSED = 'closed'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Core tag group: Status. |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
const GROUP_STATUS = 'status'; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Timestamp enabled. |
60
|
|
|
* |
61
|
|
|
* @var bool |
62
|
|
|
*/ |
63
|
|
|
public $timestamps = true; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* List of allowed columns to be used in $this->fill(). |
67
|
|
|
* |
68
|
|
|
* @var array |
69
|
|
|
*/ |
70
|
|
|
public $fillable = ['parent_id', 'name', 'bgcolor', 'group', 'role_limit']; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Name of database table. |
74
|
|
|
* |
75
|
|
|
* @var string |
76
|
|
|
*/ |
77
|
|
|
protected $table = 'tags'; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Generate a URL for the tag. |
81
|
|
|
* |
82
|
|
|
* @param string $url |
83
|
|
|
* |
84
|
|
|
* @return mixed |
85
|
|
|
*/ |
86
|
2 |
|
public function to($url) |
87
|
|
|
{ |
88
|
2 |
|
return \URL::to('administration/tag/' . $this->id . (($url) ? '/' . $url : '')); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns tag full name with prefix group name and ":" in between. |
93
|
|
|
* |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
30 |
|
public function getFullNameAttribute() |
97
|
|
|
{ |
98
|
30 |
|
return ucwords($this->attributes['name']); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Whether or not the current user can view this tag |
103
|
|
|
* |
104
|
|
|
* @return bool |
105
|
|
|
*/ |
106
|
7 |
|
public function canView() |
107
|
|
|
{ |
108
|
7 |
|
return auth()->user()->role_id >= $this->role_limit; |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Whether or not the tag is core tag |
113
|
|
|
* |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
1 |
|
public function isCore() |
117
|
|
|
{ |
118
|
1 |
|
return $this->name == static::STATUS_OPEN || $this->name == static::STATUS_CLOSED; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
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: