public function index() { $type = Param::get('type', self::TYPE_THREAD); $query = trim_collapse(Param::get('query')); $page = Param::get('page', 1); $pagination = new SimplePagination($page, self::RESULTS_PERPAGE); if (!$query) { redirect(APP_URL); } $results = new stdClass(); switch ($type) { case self::TYPE_THREAD: $results = Thread::search($query, $pagination->start_index - 1, $pagination->count + 1); // Get other info for each thread foreach ($results->result as $thread) { $thread->creator = User::getByID($thread->user_id); $thread->category = Category::getName($thread->category_id); $thread->replies_count = Comment::countAll($thread->id); } break; case self::TYPE_COMMENT: $results = Comment::search($query, $pagination->start_index - 1, $pagination->count + 1); break; case self::TYPE_USER: $results = User::search($query, $pagination->start_index - 1, $pagination->count + 1); break; default: throw new PageNotFoundException(); break; } $pagination->checkLastPage($results->result); $pages = ceil($results->total_result / self::RESULTS_PERPAGE); $title = "Search: '{$query}'"; $this->set(get_defined_vars()); }
public function test_checkLastPage() { $items = array('a', 'b', 'c', 'd'); $pagination = new SimplePagination(1, 3); $pagination->checkLastPage($items); $this->assertFalse($pagination->is_last_page); $items = array('e', 'f', 'g'); $pagination = new SimplePagination(2, 3); $pagination->checkLastPage($items); $this->assertTrue($pagination->is_last_page); }
public function view() { $thread = Thread::getById(Param::get('thread_id')); $page = Param::get('page', 1); $pagination = new SimplePagination($page, self::MAX_ITEM_PER_PAGE); $filter_username = htmlentities(Param::get('username')); $comments = Comment::getAll($pagination->start_index - 1, $pagination->count + 1, $thread->id, $filter_username); $pagination->checkLastPage($comments); Comment::getUserAttributes($comments, $_SESSION['userid']); Comment::sortByLikes($comments, Param::get('sort')); $total = Comment::countAll(); $pages = ceil($total / self::MAX_ITEM_PER_PAGE); $this->set(get_defined_vars()); }
public function index() { $page = Param::get('page', self::FIRST_PAGE); $sort_method = Param::get('sort', 'created'); $user_id = get_authenticated_user_id($_SESSION['userid']); $pagination = new SimplePagination($page, self::MAX_THREADS_PER_PAGE); $threads = Thread::getAll($pagination->start_index - 1, $pagination->count + 1, $sort_method); $pagination->checkLastPage($threads); Thread::getAttributes($threads, $user_id); $trending_threads = Comment::getTrending(); Thread::getTrendTitle($trending_threads); $total = Thread::countAll(); $pages = ceil($total / self::MAX_THREADS_PER_PAGE); $this->set(get_defined_vars()); }
public function view() { // get total number of pages $thread = Thread::get(Param::get('id')); $total = Comment::countAll($thread->id); $pages = ceil($total / self::COMMENTS_PERPAGE); $page = Param::get('page', 1); // go to last page if ($page == self::LAST_PAGE) { $page = $pages; } // paginate comments $pagination = new SimplePagination($page, self::COMMENTS_PERPAGE); $comments = Comment::getAll($thread->id, $pagination->start_index - 1, $pagination->count + 1); $pagination->checkLastPage($comments); // set other variables needed by the view $auth_user = User::getAuthenticated(); $title = $thread->title; $this->set(get_defined_vars()); }