summaryrefslogtreecommitdiff
path: root/includes/model
diff options
context:
space:
mode:
Diffstat (limited to 'includes/model')
-rwxr-xr-xincludes/model/Post.php29
-rw-r--r--includes/model/Thread.php24
-rwxr-xr-xincludes/model/User.php6
3 files changed, 40 insertions, 19 deletions
diff --git a/includes/model/Post.php b/includes/model/Post.php
index eae3d3e..ab3602b 100755
--- a/includes/model/Post.php
+++ b/includes/model/Post.php
@@ -53,8 +53,8 @@ class Post
public $id;
public $content;
public $date_created;
- public $thread;
- public $author;
+ public $thread_id;
+ public $author_id;
private $has_value = false;
@@ -70,10 +70,8 @@ class Post
$this->id = $id;
$this->content = $result[0]['post_content'];
$this->date_created = $result[0]['post_date_created'];
- $this->thread = new Thread($result[0]['post_thread']);
-
- $this->author = new User();
- $this->author->get_by_id($result[0]['post_author']);
+ $this->thread_id = $result[0]['post_thread'];
+ $this->author_id = $result[0]['post_author'];
$this->has_value = true;
}
@@ -83,14 +81,27 @@ class Post
return $this->has_value;
}
+ public function get_parent_thread(): ?Thread
+ {
+ return new Thread($this->thread_id);
+ }
+
+ public function get_author(): ?User
+ {
+ $result = new User();
+ $result->get_by_id($this->author_id);
+ return $result;
+ }
+
/**
* Get the post content from the database and return it as a string ready for HTML display
*/
function get_content(): string
{
// Build the header
+ $author = $this->get_author();
$result = '<p class="header" id="p' . $this->id . '"><b>#' . $this->id . '</b>';
- $result .= ' Posted by <a href="viewuser.php?id=' . $this->author->id . '">' . $this->author->name . '</a>';
+ $result .= ' Posted by <a href="viewuser.php?id=' . $author->id . '">' . $author->name . '</a>';
$result .= ' on ' . date('m/d/Y g:ia', strtotime($this->date_created));
if (Session::get()->is_signed_in() && Session::get()->get_current_user()->level == USER_LEVEL_MODERATOR) {
$result .= '<a href="moderate.php?type=post&id=' . $this->id . '" style="float:right;">[Options]</a>';
@@ -113,7 +124,7 @@ class Post
// User must have permission to edit the post
$current_user = Session::get()->get_current_user();
- if ($current_user->id != $this->author->id) {
+ if ($current_user->id != $this->author_id) {
trigger_error("You don't have sufficient permissions to edit this post.");
return;
}
@@ -141,7 +152,7 @@ class Post
Database::get()->query("DELETE FROM posts WHERE post_id = ?", "i", $this->id);
// Decrement the post count of the category
- Database::get()->query("UPDATE categories SET `category_post_count` = `category_post_count` - '1' WHERE category_id = ?", "i", $this->thread->category->id);
+ Database::get()->query("UPDATE categories SET `category_post_count` = `category_post_count` - '1' WHERE category_id = ?", "i", $this->get_parent_thread()->category_id);
}
public static function create($post_content, $post_thread, $post_category)
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";
diff --git a/includes/model/User.php b/includes/model/User.php
index 17d40cb..e489edf 100755
--- a/includes/model/User.php
+++ b/includes/model/User.php
@@ -8,7 +8,7 @@ class User
public $id;
public $name;
public $password;
- public $date;
+ public $date_registered;
public $level = 'user';
private $has_value = false;
@@ -27,7 +27,7 @@ class User
$this->id = $id;
$this->name = $result[0]['user_name'];
$this->password = $result[0]['user_password'];
- $this->date = $result[0]['user_date_registered'];
+ $this->date_registered = $result[0]['user_date_registered'];
$this->level = $result[0]['user_level'];
$this->has_value = true;
@@ -45,7 +45,7 @@ class User
$this->id = $result[0]['user_id'];
$this->name = $name;
$this->password = $result[0]['user_password'];
- $this->date = $result[0]['user_date_registered'];
+ $this->date_registered = $result[0]['user_date_registered'];
$this->level = $result[0]['user_level'];
$this->has_value = true;