/** * Handle the event. * * @param VoteUpdated $event * @return void */ public function handle(VoteUpdated $event) { $vote = $event->vote; $dirty = $vote->getDirty(); if (!isset($dirty['position'])) { //Position hasn't been changed return true; } $original = $vote->getOriginal(); if ($original['position'] <= 0 && $dirty['position'] <= 0) { //Don't delete if changed from neutral to abstrain return true; } $oldCommentVotes = CommentVote::where('vote_id', $vote->id)->onCommentsOfPosition($original['position'])->notUser($vote->user_id)->delete(); // Comment Votes Cast by this user the original way $newCommentVotes = CommentVote::where('vote_id', $vote->id)->onCommentsOfPosition($vote['position'])->restore(); //Comment Votes Cast by this user the new way if ($vote->comment) { //echo $original['position']; Can not figure this out, just want to delete the // DB::enableQueryLog(); //$commentsToDelete = CommentVote::where('comment_id',$vote->comment->id)->onCommentsOfPosition($original['position'])->notUser($vote->user_id)->delete(); // Delete the comment votes of this User // return $commentsToDelete; CommentVote::where('comment_id', $vote->comment->id)->forceDelete(); // Delete the comment votes of this User // print_r(DB::getQueryLog()); } return true; }
/** * Display a listing of the comment votes for this user * * @return Response */ public function index() { if (Auth::user()->can('view-comment_votes')) { //Administrator able to see any comment vote return CommentVote::all(); } return CommentVote::where('user_id', Auth::user()->id)->select('comment_id', 'position')->get(); //Get standard users comment votes }
/** * Display a listing of the motion's comments, this code could almost certainly be done better * * @return Response */ public function index($motion) { $comments = array(); if (Auth::user()->can('view-comments')) { //A full admin who can see whatever $comments['agreeComments'] = Comment::with('vote.user', 'commentVotes')->where('motion_id', $motion->id)->agree()->get()->sortByDesc('commentRank')->toArray(); $comments['disagreeComments'] = Comment::with('vote.user', 'commentVotes')->where('motion_id', $motion->id)->disagree()->get()->sortByDesc('commentRank')->toArray(); } else { //Load the standard cached comments for the page $comments = Cache::remember('motion' . $motion->id . '_comments', Setting::get('comments.cachetime', 60), function () use($motion) { $comments['agreeComments'] = Comment::with('vote.user', 'commentVotes')->where('motion_id', $motion->id)->agree()->get()->sortByDesc('commentRank')->toArray(); $comments['disagreeComments'] = Comment::with('vote.user', 'commentVotes')->where('motion_id', $motion->id)->disagree()->get()->sortByDesc('commentRank')->toArray(); return $comments; }); } $comments['thisUsersComment'] = Comment::where('motion_id', $motion->id)->with('vote')->where('user_id', Auth::user()->id)->first(); $comments['thisUsersCommentVotes'] = CommentVote::where('motion_id', $motion->id)->where('user_id', Auth::user()->id)->get(); return $comments; }
/** * Get the votes for this comment * * @param Comment $comment * @return Integer */ public function forComment(Comment $comment) { return CommentVote::where('comment_id', $comment->id)->get(); }