/** * Unlike a comment * * @return string */ public function deleteUnlikeComment() { try { //Must be an ajax request if (!$this->input->is_ajax_request()) { //Raise error throw new Exception('The request is not allowed', 422); } //User must be logged in if (!$this->auth->check()) { //Raise error throw new Exception('You must be logged in to proceed', 422); } //Set validation $this->form_validation->set_rules('comment_id', 'Comment Identifier', 'required|xss_clean'); //Apply validation if ($this->form_validation->run() == false) { //Raise error throw new Exception('Missing comment identification', '422'); } //Get the comment to unlike $comment = $this->commentRepo->getComment($this->input->post('comment_id')); //Like the post $this->likeRepo->unlikeResource($comment, $this->auth->user()); //Echo like grid back echo json_encode(['error' => false, 'commentLikes' => Html::showCommentLikes($comment)]); } catch (Exception $e) { //Unexpected error echo json_encode(['error' => true, 'message' => $e->getMessage()]); } }