From 2458ca6964401c0bd2cd809d303dfbcaea3ead90 Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Wed, 11 Aug 2021 15:14:18 -0600 Subject: Add getters for nested objects --- includes/model/Thread.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'includes/model/Thread.php') diff --git a/includes/model/Thread.php b/includes/model/Thread.php index c939738..2a74a0e 100644 --- a/includes/model/Thread.php +++ b/includes/model/Thread.php @@ -11,8 +11,8 @@ class Thread public $subject; public $date_created = 0; public $last_post_date = 0; - public $category; - public $author; + public $category_id; + public $author_id; private $has_value = false; @@ -29,10 +29,8 @@ class Thread $this->subject = $result[0]['thread_subject']; $this->date_created = $result[0]['thread_date_created']; $this->last_post_date = $result[0]['thread_last_post_date']; - $this->category = new Category($result[0]['thread_category']); - - $this->author = new User(); - $this->author->get_by_id($result[0]['thread_author']); + $this->category_id = $result[0]['thread_category']; + $this->author_id = $result[0]['thread_author']; $this->has_value = true; } @@ -79,7 +77,7 @@ class Thread Database::get()->query("DELETE FROM threads WHERE thread_id = ?", "i", $thread->id); // Decrement the thread count of the category - Database::get()->query("UPDATE categories SET `category_thread_count` = `category_thread_count` - '1' WHERE category_id = ?", "i", $thread->category->id); + Database::get()->query("UPDATE categories SET `category_thread_count` = `category_thread_count` - '1' WHERE category_id = ?", "i", $thread->category_id); } public function has_value(): bool @@ -87,6 +85,18 @@ class Thread return $this->has_value; } + public function get_parent_category(): ?Category + { + return new Category($this->category_id); + } + + public function get_author(): ?User + { + $result = new User(); + $result->get_by_id($this->author_id); + return $result; + } + public static function get_all(): array { $sql = "SELECT thread_id FROM threads"; -- cgit v1.2.3