id = $id; $this->sender_id = $sender_id; $this->recipient_id = $recipient_id; $this->reply_id = $reply_id; $this->video_id = $video_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 message object."); } /** * Drops the table for the object type from the database. */ public static function DropTable(): void { throw new SecurityFaultException("Attempt to drop table on message object."); } /** * Saves the object to the database. */ public function Save() { Hajeebtok::$Database->Query("INSERT INTO messages (sender_id, recipient_id, reply_id, video_id, content) VALUES (:sender_id, :recipient_id, :reply_id, :video_id,:content);", [ "sender_id" => $this->sender_id, "recipient_id" => $this->recipient_id, "reply_id" => $this->reply_id, "video_id" => $this->video_id, "content" => $this->content, ]); $id = Hajeebtok::$Database->LastInsertId(); Logger::Debug("Saved message id ($id)."); } /** * Deletes the object from the database. */ public function Delete() { Hajeebtok::$Database->Query("DELETE FROM messages WHERE id = :id", ["id" => $this->id]); } /** * Loads the object from the database. */ public function Load() { if ($this->id === null) throw new MessageNotFoundException(0, 404); $data = Hajeebtok::$Database->Row("SELECT * FROM messages WHERE id = :id", ["id" => $this->id]); if (empty($data)) throw new MessageNotFoundException($this->id, 404); $this->recipient_id = $data["recipient_id"]; $this->sender_id = $data["sender_id"]; $this->reply_id = $data["reply_id"]; $this->video_id = $data["video_id"]; $this->content = $data["content"]; } public function LoadMany(): array { if($this->recipient_id === null) throw new MessageNotFoundException(0, 404); $data = Hajeebtok::$Database->Query("SELECT * FROM messages WHERE recipient_id = :recipient_id", ["recipient_id" => $this->recipient_id]); if(empty($data)) throw new MessageNotFoundException($this->recipient_id, 404); return $data; } }