Ejemplo n.º 1
0
 /**
  * @param Topic $topic
  *
  * @return bool
  */
 public function deleteTopic(Topic $topic)
 {
     if ($topic->deleted_at == null) {
         $topic->forum->decrement('num_topics');
         $topic->forum->decrement('num_posts', $topic->num_posts);
         if ($topic->user_id > 0) {
             $topic->author->decrement('num_topics');
         }
         $success = $topic->delete();
         if ($success) {
             if ($topic->last_post_id == $topic->forum->last_post_id) {
                 $this->forumRepository->updateLastPost($topic->forum);
             }
         }
         return $success;
     } else {
         // First we need to remove old foreign keys - otherwise we can't delete posts
         $topic->update(['first_post_id' => null, 'last_post_id' => null]);
         // Now delete the posts for this topic
         $this->postRepository->deletePostsForTopic($topic);
         // Don't forget the polls
         if ($topic->has_poll) {
             $this->pollRepository->remove($topic->poll);
         }
         // And finally delete the topic
         $topic->forceDelete();
     }
     return true;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
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]);
 }
Ejemplo n.º 4
0
 /**
  * @param Topic $topic
  * @param Forum $forum
  */
 public function moveTopicToForum(Topic $topic, Forum $forum)
 {
     $topic->forum->decrement('num_topics');
     $topic->forum->decrement('num_posts', $topic->num_posts);
     $topic->forum_id = $forum->id;
     $topic->save();
     $topic->forum->increment('num_topics');
     $topic->forum->increment('num_posts', $topic->num_posts);
     $this->updateLastPost($forum);
 }
Ejemplo n.º 5
0
 /**
  * Add a post to a topic.
  *
  * @param Topic $topic       The topic to add a post to.
  * @param array $postDetails The details of the post to add.
  *
  * @return mixed
  */
 public function addPostToTopic(Topic $topic, array $postDetails)
 {
     $postDetails = array_merge(['user_id' => $this->guard->user()->id, 'username' => null, 'content' => '', 'content_parsed' => ''], $postDetails);
     $postDetails['content_parsed'] = $this->formatter->parse($postDetails['content'], [MessageFormatter::ME_USERNAME => $this->guard->user()->name]);
     // TODO: Parser options...
     if ($postDetails['user_id'] > 0) {
         $postDetails['username'] = User::find($postDetails['user_id'])->name;
     } else {
         $postDetails['user_id'] = null;
         if ($postDetails['username'] == trans('general.guest')) {
             $postDetails['username'] = null;
         }
     }
     $post = $topic->posts()->create($postDetails);
     if ($post !== false) {
         $topic->increment('num_posts');
         $topic->update(['last_post_id' => $post['id']]);
         $topic->forum->increment('num_posts');
         $topic->forum->update(['last_post_id' => $post->id, 'last_post_user_id' => $postDetails['user_id']]);
     }
     if ($post->user_id > 0) {
         $post->author->increment('num_posts');
     }
     return $post;
 }
Ejemplo n.º 6
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'));
     }
 }
Ejemplo n.º 7
0
 /**
  * @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');
 }