コード例 #1
0
 /**
  * Shows the specific user.
  * @param string $username
  * @return Response
  */
 public function show($username)
 {
     $post_upvotes = 0;
     $user = User::where('username', '=', $username)->firstOrFail();
     $user_posts = Post::where('user_id', '=', $user->id)->take(3)->get();
     foreach ($user_posts as $post) {
         $post->username = $user->username;
         $post->comment_count = Comment::where('post_id', '=', $post->id)->count();
         $post->hub_name = Hub::where('id', '=', $post->hub_id)->firstOrFail()->name;
         $post_upvotes = $post_upvotes + (int) $post->upvotes;
         $hub = Hub::find($post->hub_id);
         if (in_array($post->user_id, explode(',', $hub->moderators))) {
             $post->user_is_mod = true;
         } else {
             $post->user_is_mod = false;
         }
         $user = User::find($post->user_id);
         if ($user->is_admin) {
             $post->user_is_admin = true;
         } else {
             $post->user_is_admin = false;
         }
     }
     $comment_upvotes = 0;
     $user_comments = Comment::where('user_id', '=', $user->id)->take(3)->get();
     foreach ($user_comments as $comment) {
         $comment_upvotes = $comment_upvotes + (int) $comment->upvotes;
         $comment->email = md5($user->email);
     }
     return view('user.show', ['user' => $user, 'email' => md5($user->email), 'post_upvotes' => $post_upvotes, 'comment_upvotes' => $comment_upvotes, 'comments' => $user_comments, 'posts' => $user_posts]);
 }
コード例 #2
0
ファイル: HubController.php プロジェクト: NotBlizzard/phoenix
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($title)
 {
     $hub = Hub::where('name', 'LIKE', $title)->firstOrFail();
     $posts = Post::where('hub_id', '=', $hub->id)->get()->sortByDesc('upvotes');
     $mods;
     $ids = [];
     foreach (explode(',', $hub->moderators) as $moderator_id) {
         if ($moderator_id !== '') {
             array_push($ids, $moderator_id);
         }
     }
     $stickied_posts = [];
     $moderators = User::whereIn('id', $ids)->get();
     foreach ($posts as $post) {
         $post->username = User::where('id', '=', $post->user_id)->firstOrFail()->username;
         $post->comment_count = Comment::where('post_id', '=', $post->id)->count();
         if (in_array($post->user_id, explode(',', $hub->moderators))) {
             $post->user_is_mod = true;
         } else {
             $post->user_is_mod = false;
         }
         $user = User::find($post->user_id);
         if ($user->is_admin) {
             $post->user_is_admin = true;
         } else {
             $post->user_is_admin = false;
         }
     }
     $posts = $posts->sortByDesc('is_stickied');
     $subscription_count = User::where('subscriptions', 'LIKE', "%{$hub->name}%")->count();
     if (Auth::check()) {
         $subscriptions = explode(',', Auth::user()->subscriptions);
         if (in_array($hub->name, $subscriptions)) {
             return view('hub.show', ['subscriptions' => $subscription_count, 'moderators' => $moderators, 'hub' => $hub, 'posts' => $posts, 'name' => $title, 'subscribed' => true, 'subscriptions' => $subscription_count]);
         } else {
             return view('hub.show', ['subscriptions' => $subscription_count, 'moderators' => $moderators, 'hub' => $hub, 'posts' => $posts, 'name' => $title, 'subscribed' => false, 'subscriptions' => $subscription_count]);
         }
     } else {
         return view('hub.show', ['subscriptions' => $subscription_count, 'moderators' => $moderators, 'hub' => $hub, 'posts' => $posts, 'name' => $title, 'subscribed' => false]);
     }
 }
コード例 #3
0
 /**
  * Display the specified resource.
  *
  * @param  string $title, string $slug
  * @return Response
  */
 public function show($title, $slug)
 {
     $post = Post::where('slug', '=', $slug)->firstOrFail();
     $user = User::where('id', '=', $post->user_id)->first();
     $hub = Hub::where('name', '=', $title)->firstOrFail();
     $ids = [];
     foreach (explode(',', $hub->moderators) as $moderator_id) {
         if ($moderator_id !== '') {
             $ids[] = $moderator_id;
         }
     }
     if (in_array($user->id, $ids)) {
         $user->moderator = true;
     } else {
         $user->moderator = false;
     }
     $comments = Comment::where('post_id', '=', $post->id)->get();
     foreach ($comments as $comment) {
         $user = User::where('id', '=', $comment->user_id)->firstOrFail();
         $comment->email = md5($user->email);
         $comment->username = $user->username;
         $comment->user_is_admin = $user->is_admin;
         if (in_array($user->id, $ids)) {
             $comment->user_is_mod = true;
         } else {
             $comment->user_is_mod = false;
         }
     }
     return view('post.show', ['post' => $post, 'user' => $user, 'title' => $title, 'comments' => $comments]);
 }