/**
  * To view all comments on a particular thread.
  **/
 public function view()
 {
     $thread = Thread::get(Param::get('thread_id'));
     $comments = $thread->getComments();
     $user_name = $_SESSION['username'];
     $this->set(get_defined_vars());
 }
 public function view()
 {
     $comment = Comment::get(Param::get('id'));
     $auth_user = User::getAuthenticated();
     $thread = Thread::get($comment->thread_id);
     $title = "#{$comment->id}";
     $this->set(get_defined_vars());
 }
Beispiel #3
0
 public function redirect()
 {
     $follow = Follow::getOrFail(Param::get('id'));
     $thread = Thread::get($follow->thread_id);
     $last_comment_id = Comment::getLastIdInThread($thread);
     $follow->last_comment = $last_comment_id;
     $follow->update();
     redirect(VIEW_THREAD_URL, array('id' => $thread->id, 'page' => ThreadController::LAST_PAGE));
 }
Beispiel #4
0
 public static function getTrending($limit)
 {
     $trends = Comment::countToday();
     $threads = array();
     foreach ($trends as $trend) {
         $thread = Thread::get($trend['thread_id']);
         $thread->count = $trend['count'];
         $threads[] = $thread;
     }
     usort($threads, function ($thread_a, $thread_b) {
         $diff = $thread_b->count - $thread_a->count;
         if ($diff != 0) {
             return $diff;
         } else {
             return $thread_b->id - $thread_a->id;
         }
     });
     return array_slice($threads, 0, $limit);
 }
 public function write()
 {
     $thread = Thread::get(Param::get('thread_id'));
     $comment = new Comment();
     $page = Param::get('page_next');
     switch ($page) {
         case 'write_end':
             $comment->username = Param::get('username');
             $comment->body = Param::get('body');
             try {
                 $thread->write($comment);
             } catch (ValidationException $e) {
                 $page = 'write';
             }
             break;
         default:
             throw new NotFoundException("{$page} is not found");
             break;
     }
     $this->set(get_defined_vars());
     $this->render($page);
 }
Beispiel #6
0
 public function delete()
 {
     redirect_guest_user(LOGIN_URL);
     $page = Param::get('page_next', 'delete');
     $thread = Thread::get(Param::get('id'));
     $auth_user = User::getAuthenticated();
     if (!$thread->isAuthor($auth_user)) {
         throw new PermissionException();
     }
     switch ($page) {
         case 'delete':
             break;
         case 'delete_end':
             $thread->delete();
             redirect(LIST_THREADS_URL);
             break;
         default:
             break;
     }
     $title = 'Delete thread';
     $this->set(get_defined_vars());
 }
 /**
  * Edit title of thread by owner
  */
 public function update()
 {
     $thread = Thread::get(Param::get('thread_id'));
     $thread->title = Param::get('title');
     $status = "";
     if ($thread->title) {
         try {
             $thread->update(User::getId($_SESSION['username']));
             $status = notify("Update Success");
         } catch (AppException $e) {
             $status = notify($e->getMessage(), 'error');
         }
     }
     $this->set(get_defined_vars());
 }
Beispiel #8
0
 public function isThreadBody()
 {
     $thread = Thread::get($this->thread_id);
     $first_comment = Comment::getFirstInThread($thread);
     return $first_comment->id == $this->id;
 }
Beispiel #9
0
 public function view()
 {
     $id = Param::get('id');
     $auth_user = User::getAuthenticated();
     if ($id) {
         $user = User::getOrFail($id);
     } elseif ($auth_user) {
         $user = $auth_user;
     } else {
         redirect(LOGIN_URL);
     }
     $threads = Thread::getAllByUser($user);
     $comments = Comment::getAllByUser($user);
     $follows = Follow::getAll($user);
     foreach ($follows as $follow_key => $follow_element) {
         $thread = Thread::get($follow_element->thread_id);
         $follow_element->thread_title = $thread->title;
     }
     $title = $user->username;
     $this->set(get_defined_vars());
 }