public function getLastPostByTopicId($topicId) { $sql = 'SELECT `t`.`id`, `t`.`topic_id`, `p`.`read`, `p`.`id`, `p`.`topic_id`, `p`.`date_created`, `p`.`user_id` FROM `[prefix]_forum_topics` AS `t` LEFT JOIN `[prefix]_forum_posts` AS `p` ON `t`.`id` = `p`.`topic_id` WHERE `t`.`topic_id` = ' . $topicId . ' ORDER BY `p`.`id` DESC'; $fileRow = $this->db()->queryRow($sql); if (empty($fileRow)) { return null; } $entryModel = new PostModel(); $userMapper = new UserMapper(); $entryModel->setId($fileRow['id']); $entryModel->setAutor($userMapper->getUserById($fileRow['user_id'])); $entryModel->setDateCreated($fileRow['date_created']); $entryModel->setTopicId($fileRow['topic_id']); $entryModel->setRead($fileRow['read']); $posts = $this->getCountPostsByTopicId($fileRow['topic_id']) - 1; $page = floor($posts / 20) + 1; $entryModel->setPage($page); return $entryModel; }
public function getLastPostByTopicId($id) { $sql = 'SELECT p.id, p.topic_id, p.date_created, p.user_id, p.read FROM [prefix]_forum_posts as p WHERE p.topic_id = ' . $id . ' ORDER BY p.id DESC '; $fileRow = $this->db()->queryRow($sql); if (empty($fileRow)) { return null; } $entryModel = new PostModel(); $userMapper = new UserMapper(); $forumMapper = new ForumMapper(); $entryModel->setId($fileRow['id']); $entryModel->setAutor($userMapper->getUserById($fileRow['user_id'])); $entryModel->setDateCreated($fileRow['date_created']); $entryModel->setTopicId($fileRow['topic_id']); $entryModel->setRead($fileRow['read']); $posts = $forumMapper->getCountPostsByTopicId($fileRow['topic_id']) - 1; $page = floor($posts / 20) + 1; $entryModel->setPage($page); return $entryModel; }