Advertisement
Guest User

Untitled

a guest
Mar 18th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1.     public function flagComment() {
  2.         if (!$this->request->is('ajax')) {
  3.             $this->redirect('/');
  4.         } else {
  5.             $userId = $this->Session->read('Auth.User.id');
  6.             $this->autoRender = $this->layout = false;
  7.  
  8.             if (!empty($this->request->data)) {
  9.                 $commentId = $this->request->data['commentId'];
  10.  
  11.                 $this->CommentsFlag->set($this->data);
  12.                 $this->CommentsFlag->set('user_id', $userId);
  13.                 $this->CommentsFlag->set('comment_id', $commentId);
  14.  
  15.                 if (!$this->CommentsFlag->userAlreadyFlagged($userId, $commentId)) {
  16.                     if ($this->CommentsFlag->save($this->request->data)) {
  17.                         $message = array('response' => 'success');
  18.                     }
  19.                 } else {
  20.                     $message = array('response' => 'alreadyFlagged');
  21.                 }
  22.  
  23.                 return json_encode($message);
  24.             }
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement