PostModel.inc 871 B

123456789101112131415161718192021222324
  1. <?php
  2. class PostModel {
  3. public function getPostTopics($postId) {
  4. $sql = sprintf("SELECT t.topic_id, t.display_name, t.url_name
  5. FROM post_topic_associations a
  6. JOIN topics t ON a.topic_id = t.topic_id
  7. WHERE a.post_id = '%s'", $postId);
  8. $database = new Database();
  9. return $database->query($sql);
  10. }
  11. public function getPost($postId) {
  12. $sql = sprintf("SELECT p.post_id, u.user_id, p.timestamp, p.name as post_name, p.url_name as post_url_name, p.content, u.username, u.display_name as user_display_name, a.topic_id, t.display_name as topic_display_name
  13. FROM posts p
  14. JOIN post_topic_associations a ON p.post_id = a.post_id
  15. JOIN users u ON p.poster_user_id = u.user_id
  16. JOIN topics t ON a.topic_id = t.topic_id
  17. WHERE p.post_id = '%s'", $postId);
  18. $database = new Database();
  19. $postData = $database->query($sql);
  20. return $postData[0];
  21. }
  22. }