ActivityFilter.php
3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
namespace App\ModelFilters;
use App\Support\ModelFilter;
use Auth;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Arr;
class ActivityFilter extends ModelFilter
{
/**
* @param string $songName
* @return void
*/
public function songName(string $songName): void
{
$this->whereLike('song_name', $songName);
}
/**
* @param string $projectName
* @return void
*/
public function projectName(string $projectName): void
{
$this->whereRelation('project', 'projects.name', 'like', '%' . $projectName . '%');
}
/**
* @param string $tagName
* @return void
*/
public function tagName(string $tagName): void
{
$this->whereRelation('tags', 'system_tags.name', 'like', '%' . $tagName . '%');
}
/**
* @param string $userName
* @return void
*/
public function userName(string $userName): void
{
$this->whereRelation('user', 'users.nick_name', 'like', '%' . $userName . '%');
}
/**
* @param $tag
* @return void
*/
public function tag($tag): void
{
$this->whereRelation('tags', fn(Builder $builder) => $builder->whereIn('system_tags.id', Arr::wrap($tag)));
}
/**
* @param string|array $sex
* @return void
*/
public function sex(array|string $sex): void
{
$this->whereIn('sex', Arr::wrap($sex));
}
/**
* @param array|string $lang
* @return void
*/
public function lang(array|string $lang): void
{
$this->where(function ($query) use ($lang) {
foreach (Arr::wrap($lang) as $value) {
$query->orWhereJsonContains('lang', $value);
}
});
}
/**
* @param $value
* @return void
*/
public function unListen($value): void
{
if ($value) {
$this->whereNotExists(function (QueryBuilder $builder) {
$builder->selectRaw(1)->from('user_view_activitys')
->whereColumn('user_view_activitys.activity_id', 'activitys.id')
->where('user_view_activitys.user_id', Auth::id());
});
}
}
/**
* @param int|array $project
* @return void
*/
public function project(int|array $project): void
{
$this->where('project_id', Arr::wrap($project));
}
/**
* @param int $user
* @return void
*/
public function user(int $user): void
{
$this->where('user_id', $user);
}
/**
* @param int|array $status
* @return void
*/
public function auditStatus(int|array $status): void
{
$this->whereIn('audit_status', Arr::wrap($status));
}
/**
* @param int|array $status
* @return void
*/
public function status(int|array $status): void
{
$this->whereIn('status', Arr::wrap($status));
}
/**
* @param int|array $weight
* @return void
*/
public function weight(int|array $weight): void
{
$this->whereIn('weight', Arr::wrap($weight));
}
/**
* @param int|array $form
* @return void
*/
public function createdForm(int|array $form): void
{
$this->whereIn('created_form', Arr::wrap($form));
}
/**
* @param int|array $type
* @return void
*/
public function songType(int|array $type): void
{
$this->where('song_type', Arr::wrap($type));
}
/**
* @param array<int,string> $createBetween
* @return void
*/
public function auditBetween(array $createBetween): void
{
$this->whereBetween('audit_at', $createBetween);
}
}