mirror of
https://github.com/flarum/framework.git
synced 2025-04-26 14:44:03 +08:00
feat: add discussion sortmap to container binding (#3377)
This commit is contained in:
parent
9d9594a098
commit
1d27f62c15
@ -70,7 +70,7 @@ class Index
|
|||||||
$page = max(1, intval(Arr::pull($queryParams, 'page')));
|
$page = max(1, intval(Arr::pull($queryParams, 'page')));
|
||||||
$filters = Arr::pull($queryParams, 'filter', []);
|
$filters = Arr::pull($queryParams, 'filter', []);
|
||||||
|
|
||||||
$sortMap = $this->getSortMap();
|
$sortMap = resolve('flarum.forum.discussions.sortmap');
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'sort' => $sort && isset($sortMap[$sort]) ? $sortMap[$sort] : '',
|
'sort' => $sort && isset($sortMap[$sort]) ? $sortMap[$sort] : '',
|
||||||
@ -96,21 +96,6 @@ class Index
|
|||||||
return $document;
|
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.
|
* Get the result of an API request to list discussions.
|
||||||
*
|
*
|
||||||
|
@ -129,6 +129,15 @@ class ForumServiceProvider extends AbstractServiceProvider
|
|||||||
$this->container->bind('flarum.frontend.forum', function (Container $container) {
|
$this->container->bind('flarum.frontend.forum', function (Container $container) {
|
||||||
return $container->make('flarum.frontend.factory')('forum');
|
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)
|
public function boot(Container $container, Dispatcher $events, Factory $view)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user