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