Beispiel #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();
 }
Beispiel #2
0
 private function recountUsers()
 {
     $this->info('Recounting user counters...');
     $users = User::all();
     foreach ($users as $user) {
         $user->num_posts = Post::where('user_id', '=', $user->id)->count();
         $user->num_topics = Topic::where('user_id', '=', $user->id)->count();
         $user->save();
     }
     $this->info('Done' . PHP_EOL);
 }
Beispiel #3
0
 /**
  * @param int $pid
  *
  * @return string
  */
 public static function getPostLink($pid)
 {
     $post = Post::find($pid);
     return route('topics.showPost', [$post->topic->slug, $post->topic->id, $post->id]);
 }
Beispiel #4
0
 /**
  * @param Post  $post
  * @param Topic $topic
  */
 public function movePostToTopic(Post $post, Topic $topic)
 {
     $post->topic->decrement('num_posts');
     $post->topic->forum->decrement('num_posts');
     $post->topic_id = $topic->id;
     $post->save();
     $topic->increment('num_posts');
     $topic->forum->increment('num_posts');
     $topic->update(['last_post_id' => $post->id]);
     $topic->forum->update(['last_post_id' => $post->id, 'last_post_user_id' => $post->author->id]);
 }
Beispiel #5
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'));
     }
 }
 /**
  * @return \Illuminate\View\View
  */
 public function queue()
 {
     $topics = Topic::where('approved', 0)->get();
     $posts = Post::where('approved', 0)->get();
     return view('moderation.queue', ['queued_topics' => $topics, 'queued_posts' => $posts])->withActive('queue');
 }