コード例 #1
0
 /**
  * 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());
 }
コード例 #2
0
 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());
 }
コード例 #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));
 }
コード例 #4
0
ファイル: thread.php プロジェクト: rdaitan/dc-board
 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);
 }
コード例 #5
0
 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);
 }
コード例 #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());
 }
コード例 #7
0
 /**
  * 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());
 }
コード例 #8
0
ファイル: comment.php プロジェクト: rdaitan/dc-board
 public function isThreadBody()
 {
     $thread = Thread::get($this->thread_id);
     $first_comment = Comment::getFirstInThread($thread);
     return $first_comment->id == $this->id;
 }
コード例 #9
0
ファイル: user_controller.php プロジェクト: rdaitan/dc-board
 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());
 }