feat: add discussion sortmap to container binding (#3377)

This commit is contained in:
Ian Morland 2022-04-04 16:48:28 +01:00 committed by GitHub
parent 9d9594a098
commit 1d27f62c15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 16 deletions

View File

@ -70,7 +70,7 @@ class Index
$page = max(1, intval(Arr::pull($queryParams, 'page')));
$filters = Arr::pull($queryParams, 'filter', []);
$sortMap = $this->getSortMap();
$sortMap = resolve('flarum.forum.discussions.sortmap');
$params = [
'sort' => $sort && isset($sortMap[$sort]) ? $sortMap[$sort] : '',
@ -96,21 +96,6 @@ class Index
return $document;
}
/**
* Get a map of sort query param values and their API sort params.
*
* @return array
*/
private function getSortMap()
{
return [
'latest' => '-lastPostedAt',
'top' => '-commentCount',
'newest' => '-createdAt',
'oldest' => 'createdAt'
];
}
/**
* Get the result of an API request to list discussions.
*

View File

@ -129,6 +129,15 @@ class ForumServiceProvider extends AbstractServiceProvider
$this->container->bind('flarum.frontend.forum', function (Container $container) {
return $container->make('flarum.frontend.factory')('forum');
});
$this->container->singleton('flarum.forum.discussions.sortmap', function () {
return [
'latest' => '-lastPostedAt',
'top' => '-commentCount',
'newest' => '-createdAt',
'oldest' => 'createdAt'
];
});
}
public function boot(Container $container, Dispatcher $events, Factory $view)