コード例 #1
0
ファイル: ForumTopic.php プロジェクト: GIDIX/quicktalk
 public function getPosts($pageLimit = 0, $currentPage = 1)
 {
     global $db, $user, $userManager;
     if ($pageLimit == 0) {
         $pageLimit = Config::get('max_posts_perpage');
     }
     $resMeta = $db->query("SELECT * FROM " . TABLE_POSTS . " WHERE topic_id = '" . $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 posts.*, track.mark_time\n\t\t\t\t\tFROM " . TABLE_POSTS . " AS posts\n\t\t\t\t\tLEFT JOIN " . TABLE_TOPICS_TRACK . " AS track\n\t\t\t\t\t\tON posts.topic_id = track.topic_id AND track.user_id = :uid\n\t\t\t\t\tWHERE posts.topic_id = :tid\n\t\t\t\t\tORDER BY posts.id ASC\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 posts.*\n\t\t\t\t\tFROM " . TABLE_POSTS . " AS posts\n\t\t\t\t\tWHERE posts.topic_id = :tid\n\t\t\t\t\tORDER BY posts.id ASC\n\t\t\t\t\tLIMIT :pageCalc,:pageLimit\n\t\t\t\t", array($this->id, $page * $pageLimit - $pageLimit, $pageLimit));
     }
     $posts = array();
     while ($row = $db->fetchObject($res)) {
         $posts[] = ForumPost::fromRow($row, $this);
     }
     return array('posts' => $posts, 'pages' => $pages);
 }
コード例 #2
0
ファイル: Forum.php プロジェクト: GIDIX/quicktalk
 /**
  * Get last post of newest topic in this forum.
  * 
  * @return ForumPost
  */
 public function getLastPost()
 {
     global $db;
     $res = $db->query("SELECT * FROM " . TABLE_POSTS . " WHERE forum_id = ? ORDER BY post_time DESC LIMIT 1", array($this->id));
     $row = $db->fetchObject($res);
     if ($row) {
         return ForumPost::fromRow($row, null, $this);
     }
     return null;
 }