id = $id; $this->author_id = $author_id; $this->video_id = $video_id; $this->reply_id = $reply_id; $this->content = $content; } /** * Creates the table for the object type in the database. */ public static function CreateTable(): void { throw new SecurityFaultException("Attempt to create table on comment object."); } /** * Drops the table for the object type from the database. */ public static function DropTable(): void { throw new SecurityFaultException("Attempt to drop table on comment object."); } /** * Saves the object to the database. */ public function Save() { Hajeebtok::$Database->Query("INSERT INTO comments (author_id, video_id, reply_id, content) VALUES (:author_id, :video_id, :reply_id, :content)", [ "author_id" => $this->author_id, "video_id" => $this->video_id, "reply_id" => $this->reply_id, "content" => $this->content ]); $id = Hajeebtok::$Database->LastInsertId(); Logger::Debug("Saved comment id ($id)."); } /** * Deletes the object from the database. */ public function Delete() { Hajeebtok::$Database->Query("DELETE FROM comments WHERE id = :id", ["id" => $this->id]); } /** * Loads the object from the database. */ public function Load() { if($this->id === null) throw new CommentNotFoundException(0, 404); $data = Hajeebtok::$Database->Row("SELECT * FROM comments WHERE id = :id", ["id" => $this->id]); if(empty($data)) throw new CommentNotFoundException($this->id, 404); $this->author_id = $data["author_id"]; $this->video_id = $data["video_id"]; $this->reply_id = $data["reply_id"]; $this->content = $data["content"]; } public function LoadMany(): array { if($this->video_id === null) throw new CommentNotFoundException(0, 404); $data = Hajeebtok::$Database->Query("SELECT * FROM comments WHERE video_id = :video_id", ["video_id" => $this->video_id]); if(empty($data)) throw new CommentNotFoundException($this->video_id, 404); return $data; } }