Add event to modify user search

This commit is contained in:
Toby Zerner 2015-05-03 12:07:15 +09:30
parent 5ffdd8227c
commit ee6de22014
4 changed files with 24 additions and 6 deletions

View File

@ -0,0 +1,16 @@
<?php namespace Flarum\Core\Events;
use Flarum\Core\Search\Discussions\DiscussionSearcher;
class DiscussionSearchWillBePerformed
{
public $searcher;
public $criteria;
public function __construct(DiscussionSearcher $searcher, $criteria)
{
$this->searcher = $searcher;
$this->criteria = $criteria;
}
}

View File

@ -1,14 +1,14 @@
<?php namespace Flarum\Core\Events;
use Flarum\Core\Search\SearcherInterface;
use Flarum\Core\Search\Users\UserSearcher;
class SearchWillBePerformed
class UserSearchWillBePerformed
{
public $searcher;
public $criteria;
public function __construct(SearcherInterface $searcher, $criteria)
public function __construct(UserSearcher $searcher, $criteria)
{
$this->searcher = $searcher;
$this->criteria = $criteria;

View File

@ -5,11 +5,11 @@ use Flarum\Core\Search\SearcherInterface;
use Flarum\Core\Search\GambitManager;
use Flarum\Core\Repositories\DiscussionRepositoryInterface;
use Flarum\Core\Repositories\PostRepositoryInterface;
use Flarum\Core\Events\SearchWillBePerformed;
use Flarum\Core\Events\DiscussionSearchWillBePerformed;
class DiscussionSearcher implements SearcherInterface
{
public $query;
protected $query;
protected $relevantPosts = [];
@ -72,7 +72,7 @@ class DiscussionSearcher implements SearcherInterface
$this->query->take($limit + 1);
}
event(new SearchWillBePerformed($this, $criteria));
event(new DiscussionSearchWillBePerformed($this, $criteria));
$discussions = $this->query->get();

View File

@ -60,6 +60,8 @@ class UserSearcher implements SearcherInterface
$this->query->take($limit + 1);
}
event(new UserSearchWillBePerformed($this, $criteria));
$users = $this->query->get();
if ($count > 0 && $areMoreResults = $users->count() > $count) {