From f5e972c030675f46cda543e13da1b787457e070b Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Wed, 23 Jun 2021 15:21:12 -0600 Subject: Add the rest of the changes --- includes/model/Category.php | 156 ++++++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 78 deletions(-) mode change 100644 => 100755 includes/model/Category.php (limited to 'includes/model/Category.php') diff --git a/includes/model/Category.php b/includes/model/Category.php old mode 100644 new mode 100755 index e8cbe60..37ad4f8 --- a/includes/model/Category.php +++ b/includes/model/Category.php @@ -1,78 +1,78 @@ -query($sql, "i", $id); - - if (empty($result)) { - return; - } - - $this->id = $id; - $this->name = $result[0]['cat_name']; - $this->description = $result[0]['cat_description']; - $this->thread_count = $result[0]['cat_thread_count']; - $this->post_count = $result[0]['cat_post_count']; - - $this->has_value = true; - } - - // Returns true if this object was successfully fetched from the database - public function has_value() - { - return $this->has_value; - } - - public static function get_all_categories(): array - { - $sql = "SELECT cat_id FROM categories ORDER BY cat_id;"; - $result = Database::get()->query($sql); - - $categories = array(); - - foreach ($result as $row) { - $category = new Category($row['cat_id']); - array_push($categories, $category); - } - - return $categories; - } - - public function get_threads(): array - { - $sql = "SELECT thread_id FROM threads WHERE thread_category = ? ORDER BY thread_date_lastpost DESC"; - $result = Database::get()->query($sql, "i", $this->id); - $threads = array(); - - foreach ($result as $row) { - $thread = new Thread($row['thread_id']); - if ($thread->has_value()) - array_push($threads, $thread); - } - - return $threads; - } - - public function get_latest_thread(): Thread - { - $sql = "SELECT thread_id FROM threads WHERE thread_category = ? ORDER BY thread_date_lastpost DESC LIMIT 1"; - $result = Database::get()->query($sql, "i", $this->id); - return new Thread($result[0]['thread_id']); - } -} +query($sql, "i", $id); + + if (empty($result)) { + return; + } + + $this->id = $id; + $this->name = $result[0]['cat_name']; + $this->description = $result[0]['cat_description']; + $this->thread_count = $result[0]['cat_thread_count']; + $this->post_count = $result[0]['cat_post_count']; + + $this->has_value = true; + } + + // Returns true if this object was successfully fetched from the database + public function has_value() + { + return $this->has_value; + } + + public static function get_all_categories(): array + { + $sql = "SELECT cat_id FROM categories ORDER BY cat_id;"; + $result = Database::get()->query($sql); + + $categories = array(); + + foreach ($result as $row) { + $category = new Category($row['cat_id']); + array_push($categories, $category); + } + + return $categories; + } + + public function get_threads(): array + { + $sql = "SELECT thread_id FROM threads WHERE thread_category = ? ORDER BY thread_date_lastpost DESC"; + $result = Database::get()->query($sql, "i", $this->id); + $threads = array(); + + foreach ($result as $row) { + $thread = new Thread($row['thread_id']); + if ($thread->has_value()) + array_push($threads, $thread); + } + + return $threads; + } + + public function get_latest_thread(): Thread + { + $sql = "SELECT thread_id FROM threads WHERE thread_category = ? ORDER BY thread_date_lastpost DESC LIMIT 1"; + $result = Database::get()->query($sql, "i", $this->id); + return new Thread($result[0]['thread_id']); + } +} -- cgit v1.2.3