Example #1
0
 public function setDepthAttribute()
 {
     if ($this->attributes['parent'] == 0) {
         $depth = 0;
     } else {
         $parentComment = Comment::find($this->parent);
         $depth = $parentComment->attributes['depth'] + 1;
     }
     $this->attributes['depth'] = $depth;
 }
 public function edit($object_id, $comment_id)
 {
     $comment = Comment::find($comment_id);
     // Make sure that the request for editing is from the user who owns the comment
     // and isn't already trashed
     if ($comment->user_id == Auth::id() && !$comment->trashed()) {
         $comment->comment = Input::get('comment.comment');
         $comment->save();
         return response()->json($comment, 200);
     }
     return response()->json(null, 402);
 }
 /**
  * GET (HTTP). Home.
  *
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
  */
 public function home()
 {
     if (Auth::isSubscriber()) {
         // Fetch data
         $objects['latest'] = Object::authedVisibility()->inMissionControl()->orderBy('created_at', 'desc')->take(10)->get();
         $objects['hot'] = Object::authedVisibility()->inMissionControl()->selectRaw('objects.*, LOG10(greatest(1, count(comments.object_id)) + greatest(1, count(favorites.object_id))) / TIMESTAMPDIFF(HOUR, objects.actioned_at, NOW()) as score')->leftJoin('comments', 'comments.object_id', '=', 'objects.object_id')->leftJoin('favorites', 'favorites.object_id', '=', 'objects.object_id')->groupBy('objects.object_id')->orderBy(DB::raw('score'))->take(10)->get();
         $objects['discussions'] = Object::authedVisibility()->inMissionControl()->where('type', MissionControlType::Text)->join('comments', 'comments.object_id', '=', 'objects.object_id')->orderBy('comments.created_at')->select('objects.*')->take(10)->get();
         $objects['mission'] = Object::authedVisibility()->inMissionControl()->whereHas('Mission', function ($q) {
             $q->future()->take(1);
         })->take(10)->get();
         $objects['random'] = Object::authedVisibility()->inMissionControl()->orderByRaw("RAND()")->take(10)->get();
         // Leaderboards
         $leaderboards['week'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subWeek())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['month'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subMonth())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['year'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->where('awards.created_at', '>=', Carbon::now()->subYear())->groupBy('users.user_id')->take(10)->get();
         $leaderboards['alltime'] = User::join('awards', 'awards.user_id', '=', 'users.user_id')->selectRaw('users.user_id, users.username, sum(awards.value) as totalDeltaV')->groupBy('users.user_id')->take(10)->get();
         // Comments
         $comments = Comment::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         // Favorites
         $favorites = Favorite::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         // Downloads
         $downloads = Download::with(['object' => function ($query) {
             $query->select('object_id', 'title');
         }])->with(['user' => function ($query) {
             $query->select('user_id', 'username');
         }])->orderBy('created_at', 'DESC')->take(10)->get();
         return view('missionControl.home', ['upcomingMission' => Mission::future()->first(), 'leaderboards' => $leaderboards, 'objects' => $objects, 'comments' => $comments, 'favorites' => $favorites, 'downloads' => $downloads]);
     } else {
         return redirect()->action('MissionControl\\MissionControlController@about');
     }
 }