Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function getView(Request $request)
 {
     $view = parent::getView($request);
     $queryParams = $request->getQueryParams();
     $page = max(1, array_get($queryParams, 'page'));
     $params = ['id' => (int) array_get($queryParams, 'id'), 'page' => ['near' => array_get($queryParams, 'near'), 'offset' => ($page - 1) * 20, 'limit' => 20]];
     $document = $this->getDocument($request->getAttribute('actor'), $params);
     $getResource = function ($link) use($document) {
         return array_first($document->included, function ($key, $value) use($link) {
             return $value->type === $link->type && $value->id === $link->id;
         });
     };
     $url = function ($newQueryParams) use($queryParams, $document) {
         $newQueryParams = array_merge($queryParams, $newQueryParams);
         $queryString = http_build_query($newQueryParams);
         return $this->url->toRoute('discussion', ['id' => $document->data->id]) . ($queryString ? '?' . $queryString : '');
     };
     $posts = [];
     foreach ($document->included as $resource) {
         if ($resource->type === 'posts' && isset($resource->relationships->discussion) && isset($resource->attributes->contentHtml)) {
             $posts[] = $resource;
         }
     }
     $view->setTitle($document->data->attributes->title);
     $view->setDocument($document);
     $view->setContent(app('view')->make('flarum.forum::discussion', compact('document', 'page', 'getResource', 'posts', 'url')));
     return $view;
 }
Exemplo n.º 2
0
 /**
  * {@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->setDocument($document);
     $view->setContent(app('view')->make('flarum.forum::index', compact('document', 'page', 'forum')));
     return $view;
 }