summaryrefslogtreecommitdiff
path: root/includes/model/Post.php
diff options
context:
space:
mode:
authorcflip <36554078+cflip@users.noreply.github.com>2021-05-08 17:30:08 -0600
committerGitHub <noreply@github.com>2021-05-08 17:30:08 -0600
commit87b1dfd1f77b08915ee5e905da45e316ba2c0e7d (patch)
treef6c0f8d09454b6e887df0f66ca37c1ce9efb30d0 /includes/model/Post.php
parent0b045d57b2164b5ce003955d79627ae506a153eb (diff)
parenta09d9f377f5c055e42e5f21b5cdea64c2e2ca896 (diff)
Merge pull request #14 from cflip/refactor
Huge refactor
Diffstat (limited to 'includes/model/Post.php')
-rw-r--r--includes/model/Post.php36
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;
+ }
+}