diff options
Diffstat (limited to 'includes/model/Post.php')
-rw-r--r-- | includes/model/Post.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/includes/model/Post.php b/includes/model/Post.php new file mode 100644 index 0000000..67c7e4a --- /dev/null +++ b/includes/model/Post.php @@ -0,0 +1,36 @@ +<?php + +include_once 'Thread.php'; + +class Post +{ + public $id; + public $content; + public $date_created; + public $date_edited; + public $thread; + public $author; + + function get_from_database($id): bool + { + $sql = "SELECT post_content, post_date_created, post_date_edited, post_thread, post_author FROM posts WHERE post_id = ?;"; + $result = Database::get()->query($sql, "i", $id); + + if (empty($result)) { + return false; + } + + $this->id = $id; + $this->content = $result[0]['post_content']; + $this->date_created = $result[0]['post_date_created']; + $this->date_edited = $result[0]['post_date_edited']; + + $this->thread = new Thread(); + $this->thread->get_from_database($result[0]['post_thread']); + + $this->author = new User(); + $this->author->get_by_id($result[0]['post_author']); + + return true; + } +} |