/**
  * @api            {delete} /comments/:commentId/likes Unlike A Comment
  * @apiGroup       Likes
  * @apiDescription Remove the current user's like of a comment.
  * @apiUse         RequiresAuthentication
  *
  * @param Comment $comment
  *
  * @return \Illuminate\Http\Response
  * @throws \Exception
  */
 public function destroy(Comment $comment)
 {
     $user = $this->requireAuthentication();
     $commentLikeManager = $comment->getLikeManager();
     $success = !!$commentLikeManager->unlike($user);
     return $this->response(['success' => $success, 'comment' => $comment->fresh()]);
 }
 /**
  * @param Request      $request
  * @param Post         $post
  * @param Comment|null $parent
  *
  * @return \Illuminate\Http\JsonResponse
  */
 protected function createCommentFromRequest(Request $request, Post $post, Comment $parent = null)
 {
     $this->requireAuthentication();
     $this->validate($request, ['comment' => 'required']);
     $parentCommentId = $parent ? $parent->id : null;
     $depth = $parent ? $parent->depth + 1 : 0;
     $comment = new Comment(['postId' => $post->id, 'userId' => $this->user->id, 'parentCommentId' => $parentCommentId, 'depth' => $depth, 'comment' => $request->input('comment')]);
     $comment->save();
     $comment = $comment->fresh();
     return $this->response(['comment' => $comment]);
 }
 /**
  * @api            {get} /comments/:commentId/replies Get Comment Replies
  * @apiGroup       Post Comments
  * @apiDescription Get replies to a comment.
  *
  * @param Comment $comment
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Comment $comment)
 {
     $comments = $comment->replies()->orderBy('likeCount', 'DESC')->orderBy('createdAt', 'ASC');
     $paginator = $comments->paginate($this->getResultsPerPage());
     $array = $this->paginatorToArray($paginator, 'comments');
     // FIXME: Did I make this unnecessary already?
     // Load the replies to top-level comments
     foreach ($array['comments'] as &$comment) {
         /** @var Comment $comment */
         $comment->load('replies');
     }
     return $this->response($array);
 }
 public function getIndex()
 {
     $pendingSubmissions = Submission::notApproved()->count();
     $ordersNeedPrinting = Order::whereNull('printedAt')->count();
     $ordersNeedShipping = Order::whereNull('shippedAt')->count();
     $newMembers = User::where('createdAt', '>=', date('Y-m-d 00:00:00'))->count();
     $newPosts = Post::where('createdAt', '>=', date('Y-m-d 00:00:00'))->count();
     $newPosts += Comment::where('createdAt', '>=', date('Y-m-d 00:00:00'))->count();
     return $this->view('admin::dashboard', ['pendingSubmissions' => $pendingSubmissions, 'ordersNeedPrinting' => $ordersNeedPrinting, 'ordersNeedShipping' => $ordersNeedShipping, 'newMembers' => $newMembers, 'newPosts' => $newPosts]);
 }
 /**
  * @param User $user
  *
  * @return int
  * @throws Exception
  */
 public function unlike(User $user)
 {
     if (!$this->userLikes($user)) {
         throw new Exception("User does not like that comment");
     }
     $comment = $this->objectOrId instanceof Comment ? $this->objectOrId : Comment::find($this->objectOrId);
     $likes = Like::where('userId', $user->id)->where('commentId', $comment->id)->get();
     $deleted = 0;
     foreach ($likes as $like) {
         if ($like->delete()) {
             ++$deleted;
         }
     }
     if ($deleted) {
         $comment->likeCount -= $deleted;
         $comment->save();
     }
     return $deleted;
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router $router
  *
  * @return void
  */
 public function boot(Router $router)
 {
     /**
      * Route model binding
      */
     $router->bind('category', function ($slug) {
         return app('CategoryRepository')->findBySlugOrFail($slug);
     });
     $router->bind('user', function ($username) {
         return app('UserRepository')->findBySlugOrFail($username);
     });
     $router->bind('sticker', function ($slug) {
         return app('StickerRepository')->findBySlugOrFail($slug);
     });
     $router->bind('task', function ($slug) {
         return app('TaskRepository')->findBySlugOrFail($slug);
     });
     $router->bind('submission', function ($id) {
         return \Stickable\Models\Submission::findOrFail($id);
     });
     $router->bind('post', function ($id) {
         return \Stickable\Models\Post::findOrFail($id);
     });
     $router->bind('comment', function ($id) {
         return \Stickable\Models\Comment::findOrFail($id);
     });
     $router->bind('notification', function ($id) {
         return \Stickable\Models\Notification::findOrFail($id);
     });
     $router->bind('event', function ($id) {
         return \Stickable\Models\EventLog::findOrFail($id);
     });
     $router->bind('todo', function ($id) {
         return \Stickable\Models\ToDo::findOrFail($id);
     });
     parent::boot($router);
 }
 /**
  * Returns the next 3 levels of replies to a comment.
  *
  * @param Comment $comment
  *
  * @return Comment[]
  */
 public function getCommentRepliesWithReplies(Comment $comment)
 {
     $comments = $comment->replies()->where('depth', '<=', $comment->depth + 3)->orderBy('depth', 'ASC')->orderBy('likeCount', 'DESC')->orderBy('createdAt', 'ASC')->get()->getDictionary();
     //Get a dictionary keyed by primary keys
     return $this->sortCommentReplies($comments);
 }
 public function getText()
 {
     $usernames = $this->getUsernameText();
     $postTitle = null;
     if ($this->postId) {
         $post = Post::find($this->postId);
         $postTitle = $post ? $post->title : '';
     } elseif ($this->commentId) {
         if ($comment = Comment::find($this->commentId)) {
             $post = Post::find($comment->postId);
             $postTitle = $post ? $post->title : '';
         }
     }
     $stickerName = null;
     if ($this->stickerId) {
         $stickerRepository = new StickerRepository();
         $sticker = $stickerRepository->find($this->stickerId);
         $stickerName = $sticker ? $sticker->name : '';
     }
     $taskName = null;
     if ($this->taskId) {
         $taskRepository = new TaskRepository();
         $task = $taskRepository->find($this->taskId);
         $taskName = $task ? $task->name : '';
     }
     return Lang::get('notifications.types.' . $this->type, ['usernames' => $usernames, 'stickerName' => $stickerName, 'taskName' => $taskName, 'postTitle' => $postTitle]);
 }
 /**
  * @api            {delete} /comments/:commentId Delete A Comment
  * @apiGroup       Post Comments
  * @apiDescription Delete a comment.
  *
  * @param Comment $comment
  *
  * @return \Illuminate\Http\Response
  */
 public function destroy(Comment $comment)
 {
     $this->requireUserOrRole($comment->getUser(), Role::ROLE_MANAGE_COMMENTS);
     $success = $comment->delete();
     return $this->successResponse($success);
 }