Example #1
0
 /**
  * @param array $postIds
  *
  * @return mixed
  */
 public function getPostsByIds(array $postIds)
 {
     $unviewableForums = $this->permissionChecker->getUnviewableIdsForContent('forum');
     return $this->postModel->whereIn('id', $postIds)->whereHas('topic', function ($query) use($unviewableForums) {
         $query->whereNotIn('forum_id', $unviewableForums);
     })->with(['author', 'topic'])->get();
 }
Example #2
0
 /**
  * @param int         $id
  * @param Request     $request
  * @param Breadcrumbs $breadcrumbs
  *
  * @return \Illuminate\View\View
  */
 public function results($id, Request $request, Breadcrumbs $breadcrumbs)
 {
     // TODO: sorts
     $search = $this->searchRepository->find($id);
     if (!$search) {
         throw new NotFoundHttpException();
     }
     $breadcrumbs->setCurrentRoute('search.results', $search);
     $orderBy = $request->get('orderBy');
     $orderDir = $request->get('orderDir');
     if (!isset($this->sorts[$orderBy])) {
         $orderBy = 'postdate';
     }
     if ($orderDir != 'asc') {
         $orderDir = 'desc';
     }
     $urlDirs = [];
     foreach ($this->sorts as $sortName => $sort) {
         $urlDirs[$sortName] = $sort['asc'];
     }
     if ($orderDir == $urlDirs[$orderBy]) {
         if ($urlDirs[$orderBy] == 'desc') {
             $urlDirs[$orderBy] = 'asc';
         } else {
             $urlDirs[$orderBy] = 'desc';
         }
     }
     if ($search->as_topics) {
         $results = Topic::whereIn('id', explode(',', $search->topics))->with(['lastPost', 'author', 'lastPost.author'])->orderBy($this->sorts[$orderBy]['name'], $this->sorts[$orderBy][$orderDir])->paginate(10);
     } else {
         $results = Post::whereIn('id', explode(',', $search->posts))->with(['topic', 'author'])->orderBy($this->sorts[$orderBy]['name'], $this->sorts[$orderBy][$orderDir])->paginate(10);
     }
     if ($search->as_topics) {
         return view('search.result_topics', compact('results', 'search', 'orderDir', 'orderBy', 'urlDirs'));
     } else {
         return view('search.result_posts', compact('results', 'search'));
     }
 }