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\Traits\Tag; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent; |
15
|
|
|
use Illuminate\Database\Query; |
16
|
|
|
use Tinyissue\Model\Role; |
17
|
|
|
use Tinyissue\Model\Tag as TagModel; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* QueryTrait is trait class containing the database queries methods for the Tag model. |
21
|
|
|
* |
22
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
23
|
|
|
* |
24
|
|
|
* @method Eloquent\Builder with($relations) |
25
|
|
|
* @method Eloquent\Model where($column, $operator = null, $value = null, $boolean = 'and') |
26
|
|
|
* @method Query\Builder whereIn($column, $values, $boolean = 'and', $not = false) |
27
|
|
|
*/ |
28
|
|
|
trait QueryTrait |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Returns collection of all groups and eager load their tags. |
32
|
|
|
* |
33
|
|
|
* @return Eloquent\Collection |
34
|
|
|
*/ |
35
|
31 |
|
public function getGroupTags() |
36
|
|
|
{ |
37
|
31 |
|
return $this->with([ |
38
|
|
|
'tags' => function (Eloquent\Relations\HasMany $query) { |
39
|
|
|
$query->where(function(Eloquent\Builder $query) { |
40
|
31 |
|
$query->where('role_limit', '<=', auth()->user()->role_id); |
|
|
|
|
41
|
31 |
|
$query->orWhere('role_limit', '=', null); |
42
|
31 |
|
}); |
43
|
31 |
|
}, |
44
|
|
|
]) |
45
|
31 |
|
->where('group', '=', true)->orderBy('group', 'DESC')->orderBy('name', 'ASC')->get(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Search tags by name. |
50
|
|
|
* |
51
|
|
|
* @param string $term |
52
|
|
|
* |
53
|
|
|
* @return Eloquent\Collection|static[] |
54
|
|
|
*/ |
55
|
|
|
public function searchTags($term) |
56
|
|
|
{ |
57
|
|
|
return $this->with('parent')->where('name', 'like', '%' . $term . '%')->where('parent_id', '<>', 0)->get(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns tag groups list. |
62
|
|
|
* |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
public function groupsDropdown() |
66
|
|
|
{ |
67
|
29 |
|
return $this->getGroups()->map(function ($group) { |
68
|
29 |
|
$group->keyname = 'tag:' . $group->id; |
69
|
29 |
|
$group->name = ucwords($group->name); |
70
|
|
|
|
71
|
29 |
|
return $group; |
72
|
29 |
|
})->lists('name', 'keyname')->all(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns collection of all groups. |
77
|
|
|
* |
78
|
|
|
* @return Eloquent\Collection |
79
|
|
|
*/ |
80
|
31 |
|
public function getGroups() |
81
|
|
|
{ |
82
|
31 |
|
return $this->where('group', '=', true)->orderBy('name', 'ASC')->get(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Return tag by name. |
87
|
|
|
* |
88
|
|
|
* @param string $name |
89
|
|
|
* |
90
|
|
|
* @return static |
91
|
|
|
*/ |
92
|
7 |
|
public function getTagByName($name) |
93
|
|
|
{ |
94
|
7 |
|
return static::where('name', '=', $name)->first(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Returns collection of tags in status group. |
99
|
|
|
* |
100
|
|
|
* @return Eloquent\Collection |
101
|
|
|
*/ |
102
|
6 |
|
public function getStatusTags() |
103
|
|
|
{ |
104
|
6 |
|
return $this->getTagByName('status')->tags(); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns collection of tags in type group. |
109
|
|
|
* |
110
|
|
|
* @return Eloquent\Collection |
111
|
|
|
*/ |
112
|
2 |
|
public function getTypeTags() |
113
|
|
|
{ |
114
|
2 |
|
return $this->getTagByName('type')->tags(); |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Returns collection of tags in type group. |
119
|
|
|
* |
120
|
|
|
* @return Eloquent\Collection |
121
|
|
|
*/ |
122
|
|
|
public function getResolutionTags() |
123
|
|
|
{ |
124
|
|
|
return $this->getTagByName('resolution')->tags(); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
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: