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