File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change 15
15
use Flarum \Api \Serializer \DiscussionSerializer ;
16
16
use Flarum \Discussion \Discussion ;
17
17
use Flarum \Discussion \Event \Saving ;
18
+ use Flarum \Discussion \Filter \DiscussionFilterer ;
18
19
use Flarum \Discussion \Search \DiscussionSearcher ;
19
20
use Flarum \Extend ;
20
21
use FoF \FrontPage \Gambits \FrontGambit ;
34
35
(new Extend \SimpleFlarumSearch (DiscussionSearcher::class))
35
36
->addGambit (FrontGambit::class),
36
37
38
+ (new Extend \Filter (DiscussionFilterer::class))
39
+ ->addFilter (FrontGambit::class),
40
+
37
41
(new Extend \Model (Discussion::class))
38
42
->dateAttribute ('frontdate ' ),
39
43
Original file line number Diff line number Diff line change 11
11
12
12
namespace FoF \FrontPage \Gambits ;
13
13
14
+ use Flarum \Filter \FilterInterface ;
15
+ use Flarum \Filter \FilterState ;
14
16
use Flarum \Query \AbstractQueryState ;
15
17
use Flarum \Search \AbstractRegexGambit ;
18
+ use Illuminate \Database \Query \Builder ;
16
19
17
- class FrontGambit extends AbstractRegexGambit
20
+ class FrontGambit extends AbstractRegexGambit implements FilterInterface
18
21
{
19
22
/**
20
- * @return [type]
23
+ * @return string
21
24
*/
22
25
public function getGambitPattern ()
23
26
{
24
27
return 'is:frontpage ' ;
25
28
}
26
29
30
+ /**
31
+ * @return string
32
+ */
33
+ public function getFilterKey (): string
34
+ {
35
+ return 'frontpage ' ;
36
+ }
37
+
27
38
/**
28
39
* @param AbstractQueryState $search
29
40
* @param array $matches
30
41
* @param mixed $negate
31
42
*
32
- * @return [type]
43
+ * @return void
33
44
*/
34
45
public function conditions (AbstractQueryState $ search , array $ matches , $ negate )
35
46
{
36
- $ search ->getQuery ()->where ('frontpage ' , !$ negate );
47
+ $ this ->constrain ($ search ->getQuery (), $ negate );
48
+ }
49
+
50
+ /**
51
+ * @param FilterState $search
52
+ * @param string $filterValue
53
+ * @param mixed $negate
54
+ *
55
+ * @return void
56
+ */
57
+ public function filter (FilterState $ filterState , string $ filterValue , bool $ negate )
58
+ {
59
+ $ this ->constrain ($ filterState ->getQuery (), $ negate );
60
+ }
61
+
62
+ protected function constrain (Builder $ query , bool $ negate )
63
+ {
64
+ $ query ->where ('frontpage ' , !$ negate );
37
65
}
38
66
}
You can’t perform that action at this time.
0 commit comments