|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Realshadow\Redtube\Filters; |
|
4
|
|
|
|
|
5
|
|
|
use Realshadow\Redtube\Enumerators\Thumbsize; |
|
6
|
|
|
use Realshadow\Redtube\Enumerators\OrderBy; |
|
7
|
|
|
use Realshadow\Redtube\Enumerators\Period; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Video Filter |
|
12
|
|
|
* |
|
13
|
|
|
* @package Realshadow\Redtube\Filters |
|
14
|
|
|
* @author Lukáš Homza <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class VideoFilter implements Filterable |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Page that should be pulled |
|
21
|
|
|
* |
|
22
|
|
|
* @var int $page |
|
23
|
|
|
*/ |
|
24
|
|
|
private $page = 1; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Query string that should be searched for |
|
28
|
|
|
* |
|
29
|
|
|
* @var string $search |
|
30
|
|
|
*/ |
|
31
|
|
|
private $search; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Category the videos should belong to |
|
35
|
|
|
* |
|
36
|
|
|
* @var string $category |
|
37
|
|
|
*/ |
|
38
|
|
|
private $category; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* List of tags |
|
42
|
|
|
* |
|
43
|
|
|
* @var array $tags |
|
44
|
|
|
*/ |
|
45
|
|
|
private $tags = []; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* List of stars |
|
49
|
|
|
* |
|
50
|
|
|
* @var array $stars |
|
51
|
|
|
*/ |
|
52
|
|
|
private $stars = []; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Thumbsize |
|
56
|
|
|
* |
|
57
|
|
|
* @var string $thumbsize |
|
58
|
|
|
*/ |
|
59
|
|
|
private $thumbsize; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Order by |
|
63
|
|
|
* |
|
64
|
|
|
* @var string $orderBy |
|
65
|
|
|
*/ |
|
66
|
|
|
private $orderBy = OrderBy::NEWEST; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Period of creation |
|
70
|
|
|
* |
|
71
|
|
|
* @var string $period |
|
72
|
|
|
*/ |
|
73
|
|
|
private $period = Period::ALL_TIME; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Create new filter instance |
|
77
|
|
|
* |
|
78
|
|
|
* @return static |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function create() |
|
81
|
|
|
{ |
|
82
|
|
|
return new static; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Search by provided string |
|
87
|
|
|
* |
|
88
|
|
|
* @param $search |
|
89
|
|
|
* |
|
90
|
|
|
* @return $this |
|
91
|
|
|
*/ |
|
92
|
|
|
public function search($search) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->search = $search; |
|
95
|
|
|
|
|
96
|
|
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Filter results by provided page (works like limit) |
|
101
|
|
|
* |
|
102
|
|
|
* @param $page |
|
103
|
|
|
* |
|
104
|
|
|
* @return $this |
|
105
|
|
|
*/ |
|
106
|
|
|
public function page($page) |
|
107
|
|
|
{ |
|
108
|
|
|
$this->page = $page; |
|
109
|
|
|
|
|
110
|
|
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Get requested page |
|
115
|
|
|
* |
|
116
|
|
|
* Used mostly internally |
|
117
|
|
|
* |
|
118
|
|
|
* @return int |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getRequestedPage() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->page; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Category the videos should belong to |
|
127
|
|
|
* |
|
128
|
|
|
* @param $category |
|
129
|
|
|
* |
|
130
|
|
|
* @return $this |
|
131
|
|
|
*/ |
|
132
|
|
|
public function category($category) |
|
133
|
|
|
{ |
|
134
|
|
|
$this->category = $category; |
|
135
|
|
|
|
|
136
|
|
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Filter by provided list of tags |
|
141
|
|
|
* |
|
142
|
|
|
* @param array $tags |
|
143
|
|
|
* |
|
144
|
|
|
* @return $this |
|
145
|
|
|
*/ |
|
146
|
|
|
public function tags(array $tags) |
|
147
|
|
|
{ |
|
148
|
|
|
$this->tags = $tags; |
|
149
|
|
|
|
|
150
|
|
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Filter by provided list of stars |
|
155
|
|
|
* |
|
156
|
|
|
* @param array $stars |
|
157
|
|
|
* |
|
158
|
|
|
* @return $this |
|
159
|
|
|
*/ |
|
160
|
|
|
public function stars(array $stars) |
|
161
|
|
|
{ |
|
162
|
|
|
$this->stars = $stars; |
|
163
|
|
|
|
|
164
|
|
|
return $this; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Get only provided thumbsizes |
|
169
|
|
|
* |
|
170
|
|
|
* @param $thumbsize |
|
171
|
|
|
* |
|
172
|
|
|
* @return $this |
|
173
|
|
|
* @throws \InvalidArgumentException |
|
174
|
|
|
*/ |
|
175
|
|
|
public function thumbsize($thumbsize) |
|
176
|
|
|
{ |
|
177
|
|
|
if ( ! Thumbsize::isValid($thumbsize)) { |
|
178
|
|
|
throw new \InvalidArgumentException('Unsupported thumbsize value "' . $thumbsize . '".'); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
$this->thumbsize = $thumbsize; |
|
182
|
|
|
|
|
183
|
|
|
return $this; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Order result by |
|
188
|
|
|
* |
|
189
|
|
|
* @param $orderBy |
|
190
|
|
|
* |
|
191
|
|
|
* @return $this |
|
192
|
|
|
* @throws \InvalidArgumentException |
|
193
|
|
|
*/ |
|
194
|
|
|
public function orderBy($orderBy) |
|
195
|
|
|
{ |
|
196
|
|
|
if ( ! OrderBy::isValid($orderBy)) { |
|
197
|
|
|
throw new \InvalidArgumentException('Unsupported orderBy value "' . $orderBy . '".'); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
$this->orderBy = $orderBy; |
|
201
|
|
|
|
|
202
|
|
|
return $this; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Get only vidoes created during provided period |
|
207
|
|
|
* |
|
208
|
|
|
* @param $period |
|
209
|
|
|
* |
|
210
|
|
|
* @return $this |
|
211
|
|
|
* @throws \InvalidArgumentException |
|
212
|
|
|
*/ |
|
213
|
|
|
public function period($period) |
|
214
|
|
|
{ |
|
215
|
|
|
if ( ! Period::isValid($period)) { |
|
216
|
|
|
throw new \InvalidArgumentException('Unsupported period value "' . $period . '".'); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
$this->period = $period; |
|
220
|
|
|
|
|
221
|
|
|
return $this; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @inheritdoc |
|
226
|
|
|
*/ |
|
227
|
|
|
public function compile() |
|
228
|
|
|
{ |
|
229
|
|
|
return http_build_query(get_object_vars($this)); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
} |
|
233
|
|
|
|