/** * Get $pageLimit topics. * * @param int $pageLimit How many pages per page? * @param int $currentPage On what page are we currently? (you should not set this manually!) * * @return array Array containing topics and pages. */ public function getTopics($pageLimit = 20, $currentPage = 1) { global $db, $user, $userManager; $resMeta = $db->query("SELECT * FROM " . TABLE_TOPICS . " WHERE forum_id = ?", array($this->id)); $page = isset($currentPage) ? max($currentPage, 1) : 1; $pages = ceil($db->numRows($resMeta) / $pageLimit); if ($userManager->loggedIn()) { $res = $db->query("\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM " . TABLE_TOPICS . " AS topics\n\t\t\t\t\tLEFT JOIN " . TABLE_TOPICS_TRACK . " AS t\n\t\t\t\t\t\tON t.topic_id = topics.id AND t.user_id = :uid\n\t\t\t\t\tWHERE topics.forum_id = :id\n\t\t\t\t\tORDER BY topics.topic_important DESC, last_post_time DESC\n\t\t\t\t\tLIMIT :pageCalc,:pageLimit\n\t\t\t\t", array($user->getID(), $this->id, $page * $pageLimit - $pageLimit, $pageLimit)); } else { $res = $db->query("\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM " . TABLE_TOPICS . " AS topics\n\t\t\t\t\tWHERE forum_id = :id\n\t\t\t\t\tORDER BY topics.topic_important DESC, last_post_time DESC\n\t\t\t\t\tLIMIT :pageCalc,:pageLimit\n\t\t\t\t", array($this->id, $page * $pageLimit - $pageLimit, $pageLimit)); } $topics = array(); while ($row = $db->fetchObject($res)) { $topics[] = ForumTopic::fromRow($row, $this); } return array('topics' => $topics, 'pages' => $pages); }