Пример #1
0
 public function create()
 {
     redirect_guest_user(LOGIN_URL);
     $thread = Thread::get(Param::get('thread_id'));
     $page = Param::get('page_next');
     $auth_user = User::getAuthenticated();
     if (!$auth_user) {
         return;
     }
     if ($page == 'create_end') {
         $comment = new Comment();
         $comment->body = trim(Param::get('body'));
         $comment->user_id = $auth_user->id;
         try {
             $comment->create($thread);
             $follow = Follow::getByThreadAndUser($thread->id, $comment->user_id);
             if ($follow) {
                 $thread = Thread::get($thread->id);
                 $last_comment = Comment::getLastInThread($thread);
                 if ($last_comment) {
                     $follow->last_comment = $last_comment->id;
                     $follow->update();
                 }
             }
             redirect(VIEW_THREAD_URL, array('id' => $thread->id));
         } catch (ValidationException $e) {
             $page = 'create';
         }
     } else {
         throw new PageNotFoundException();
     }
     $title = 'Create Comment';
     $this->set(get_defined_vars());
     $this->render($page);
 }
Пример #2
0
 public function remove()
 {
     redirect_guest_user(LOGIN_URL);
     $thread = Thread::get(Param::get('id'));
     $auth_user = User::getAuthenticated();
     if (!$auth_user) {
         die;
     }
     $follow = Follow::getByThreadAndUser($thread->id, $auth_user->id);
     if ($follow) {
         $follow->remove();
     }
     redirect(VIEW_THREAD_URL, array('id' => $follow->thread_id));
 }
Пример #3
0
 public function isFollowedBy($user)
 {
     if (!$user) {
         return false;
     }
     return Follow::getByThreadAndUser($this->id, $user->id) ? true : false;
 }