mirror of
https://github.com/flarum/core.git
synced 2025-07-31 13:40:20 +02:00
Upgrade to JSON-API RC3 + latest version of tobscure/json-api
Note: npm source for ember-json-api changed to a fork, but I still had to apply a custom change to get polymorphic relationships to work (see https://github.com/kurko/ember-json-api/pull/71#issuecomment-85257281)
This commit is contained in:
@@ -36,16 +36,14 @@ class IndexAction extends BaseAction
|
||||
{
|
||||
$query = $params->get('q');
|
||||
$start = $params->start();
|
||||
$include = $params->included(['startPost', 'lastPost', 'relevantPosts']);
|
||||
$include = $params->included(['startUser', 'lastUser', 'startPost', 'lastPost', 'relevantPosts']);
|
||||
$count = $params->count(20, 50);
|
||||
$sort = $params->sort(['', 'lastPost', 'replies', 'created']);
|
||||
|
||||
$relations = array_merge(['startUser', 'lastUser'], $include);
|
||||
|
||||
// Set up the discussion searcher with our search criteria, and get the
|
||||
// requested range of results with the necessary relations loaded.
|
||||
$criteria = new DiscussionSearchCriteria($this->actor->getUser(), $query, $sort['field'], $sort['order']);
|
||||
$load = array_merge($relations, ['state']);
|
||||
$load = array_merge($include, ['state']);
|
||||
|
||||
$results = $this->searcher->search($criteria, $count, $start, $load);
|
||||
|
||||
@@ -61,9 +59,8 @@ class IndexAction extends BaseAction
|
||||
// specified.
|
||||
if ($results->areMoreResults()) {
|
||||
$start += $count;
|
||||
$include = implode(',', $include);
|
||||
$sort = $sort['string'];
|
||||
$input = array_filter(compact('query', 'sort', 'start', 'count', 'include'));
|
||||
$input = array_filter(compact('query', 'sort', 'start', 'count')) + ['include' => implode(',', $include)];
|
||||
$moreUrl = $this->buildUrl('discussions.index', [], $input);
|
||||
} else {
|
||||
$moreUrl = '';
|
||||
@@ -72,8 +69,8 @@ class IndexAction extends BaseAction
|
||||
|
||||
// Finally, we can set up the discussion serializer and use it to create
|
||||
// a collection of discussion results.
|
||||
$serializer = new DiscussionSerializer($relations);
|
||||
$document->setPrimaryElement($serializer->collection($results->getDiscussions()));
|
||||
$serializer = new DiscussionSerializer($include);
|
||||
$document->setData($serializer->collection($results->getDiscussions()));
|
||||
|
||||
return $this->respondWithDocument($document);
|
||||
}
|
||||
|
Reference in New Issue
Block a user