mirror of
https://github.com/flarum/framework.git
synced 2024-11-30 05:13:37 +08:00
Merge pull request #29 from coderstephen/master
Add posts API filter for tags
This commit is contained in:
commit
e84788d646
|
@ -20,6 +20,7 @@ return function (Dispatcher $events) {
|
|||
$events->subscribe(Listener\AddTagsApi::class);
|
||||
$events->subscribe(Listener\CreatePostWhenTagsAreChanged::class);
|
||||
$events->subscribe(Listener\FilterDiscussionListByTags::class);
|
||||
$events->subscribe(Listener\FilterPostsQueryByTags::class);
|
||||
$events->subscribe(Listener\SaveTagsToDatabase::class);
|
||||
$events->subscribe(Listener\UpdateTagMetadata::class);
|
||||
|
||||
|
|
38
extensions/tags/src/Listener/FilterPostsQueryByTag.php
Normal file
38
extensions/tags/src/Listener/FilterPostsQueryByTag.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tags\Listener;
|
||||
|
||||
use Flarum\Event\ConfigurePostsQuery;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class FilterPostsQueryByTag
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ConfigurePostsQuery::class, [$this, 'filterQuery']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigurePostsQuery $event
|
||||
*/
|
||||
public function filterQuery(ConfigurePostsQuery $event)
|
||||
{
|
||||
if ($tagId = array_get($event->filter, 'tag')) {
|
||||
$event->query
|
||||
->join('discussions_tags', 'discussions_tags.discussion_id', '=', 'posts.discussion_id')
|
||||
->where('discussions_tags.tag_id', $tagId);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user