summaryrefslogtreecommitdiff
path: root/includes/model/Post.php
blob: 67c7e4a2e3f1914cdbae0c6d8614eda128d0452e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;
	}
}