mirror of
https://github.com/flarum/framework.git
synced 2024-12-04 08:13:39 +08:00
Remove file accidentally added in merge
This commit is contained in:
parent
05c8e12761
commit
5aa15f5b27
|
@ -1,87 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Flarum\Forum\Controller;
|
|
||||||
|
|
||||||
use Flarum\Api\Client as ApiClient;
|
|
||||||
use Flarum\Forum\Frontend;
|
|
||||||
use Flarum\User\User;
|
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
||||||
|
|
||||||
class IndexController extends FrontendController
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var ApiClient
|
|
||||||
*/
|
|
||||||
protected $api;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A map of sort query param values to their API sort param.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $sortMap = [
|
|
||||||
'latest' => '-lastPostedAt',
|
|
||||||
'top' => '-commentCount',
|
|
||||||
'newest' => '-createdAt',
|
|
||||||
'oldest' => 'createdAt'
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function __construct(Frontend $webApp, Dispatcher $events, ApiClient $api)
|
|
||||||
{
|
|
||||||
parent::__construct($webApp, $events);
|
|
||||||
|
|
||||||
$this->api = $api;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function getView(Request $request)
|
|
||||||
{
|
|
||||||
$view = parent::getView($request);
|
|
||||||
|
|
||||||
$queryParams = $request->getQueryParams();
|
|
||||||
|
|
||||||
$sort = array_pull($queryParams, 'sort');
|
|
||||||
$q = array_pull($queryParams, 'q');
|
|
||||||
$page = array_pull($queryParams, 'page', 1);
|
|
||||||
|
|
||||||
$params = [
|
|
||||||
'sort' => $sort && isset($this->sortMap[$sort]) ? $this->sortMap[$sort] : '',
|
|
||||||
'filter' => compact('q'),
|
|
||||||
'page' => ['offset' => ($page - 1) * 20, 'limit' => 20]
|
|
||||||
];
|
|
||||||
|
|
||||||
$document = $this->getDocument($request->getAttribute('actor'), $params);
|
|
||||||
|
|
||||||
$view->document = $document;
|
|
||||||
$view->content = app('view')->make('flarum.forum::frontend.content.index', compact('document', 'page', 'forum'));
|
|
||||||
|
|
||||||
return $view;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the result of an API request to list discussions.
|
|
||||||
*
|
|
||||||
* @param User $actor
|
|
||||||
* @param array $params
|
|
||||||
* @return object
|
|
||||||
*/
|
|
||||||
private function getDocument(User $actor, array $params)
|
|
||||||
{
|
|
||||||
return json_decode($this->api->send('Flarum\Api\Controller\ListDiscussionsController', $actor, $params)->getBody());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user