Update some APIs

- Rename DiscussionSearchWillBePerformed to ConfigureDiscussionSearch, same with users
- Add some handy methods
This commit is contained in:
Toby Zerner 2015-10-11 22:31:06 +10:30
parent 663de42917
commit 1c3fda4a71
6 changed files with 27 additions and 6 deletions

View File

@ -16,7 +16,7 @@ use Flarum\Core\Search\SearchCriteria;
use Flarum\Core\Search\GambitManager;
use Flarum\Core\Repository\DiscussionRepository;
use Flarum\Core\Repository\PostRepository;
use Flarum\Event\DiscussionSearchWillBePerformed;
use Flarum\Event\ConfigureDiscussionSearch;
use Flarum\Core\Search\SearchResults;
use Illuminate\Database\Eloquent\Collection;
@ -82,7 +82,7 @@ class DiscussionSearcher
$this->applyLimit($search, $limit + 1);
// TODO: inject dispatcher
event(new DiscussionSearchWillBePerformed($search, $criteria));
event(new ConfigureDiscussionSearch($search, $criteria));
// Execute the search query and retrieve the results. We get one more
// results than the user asked for, so that we can say if there are more

View File

@ -15,7 +15,7 @@ use Flarum\Core\Search\GambitManager;
use Flarum\Core\Search\SearchCriteria;
use Flarum\Core\Search\SearchResults;
use Flarum\Core\Repository\UserRepository;
use Flarum\Event\UserSearchWillBePerformed;
use Flarum\Event\ConfigureUserSearch;
/**
* Takes a UserSearchCriteria object, performs a search using gambits,
@ -68,7 +68,7 @@ class UserSearcher
$this->applyOffset($search, $offset);
$this->applyLimit($search, $limit + 1);
event(new UserSearchWillBePerformed($search, $criteria));
event(new ConfigureUserSearch($search, $criteria));
// Execute the search query and retrieve the results. We get one more
// results than the user asked for, so that we can say if there are more

View File

@ -13,7 +13,7 @@ namespace Flarum\Event;
use Flarum\Core\Search\Discussion\DiscussionSearch;
use Flarum\Core\Search\SearchCriteria;
class DiscussionSearchWillBePerformed
class ConfigureDiscussionSearch
{
/**
* @var DiscussionSearch

View File

@ -37,4 +37,13 @@ class ConfigureModelDates
$this->model = $model;
$this->dates = &$dates;
}
/**
* @param string $model
* @return bool
*/
public function isModel($model)
{
return $this->model instanceof $model;
}
}

View File

@ -13,7 +13,7 @@ namespace Flarum\Event;
use Flarum\Core\Search\User\UserSearch;
use Flarum\Core\Search\SearchCriteria;
class UserSearchWillBePerformed
class ConfigureUserSearch
{
/**
* @var UserSearch

View File

@ -10,6 +10,7 @@
namespace Flarum\Event;
use DateTime;
use Flarum\Api\Serializer\AbstractSerializer;
/**
@ -67,4 +68,15 @@ class PrepareApiAttributes
{
return $this->serializer instanceof $serializer;
}
/**
* @param DateTime|null $date
* @return string|null
*/
public function formatDate(DateTime $date = null)
{
if ($date) {
return $date->format(DateTime::RFC3339);
}
}
}