video_id = $video_id; $this->account_id = $account_id; } /** * Creates the table for the object type in the database. */ public static function CreateTable(): void { throw new SecurityFaultException("Attempt to create table on view object."); } /** * Drops the table for the object type from the database. */ public static function DropTable(): void { throw new SecurityFaultException("Attempt to drop table on view object."); } /** * Saves the object to the database. */ public function Save() { Hajeebtok::$Database->Query("INSERT INTO views (account_id, video_id) VALUES (:account_id, :video_id)", [ "account_id" => $this->account_id, "video_id" => $this->video_id ]); Logger::Debug("Saved view."); } /** * Deletes the object from the database. */ public function Delete() { // TODO: make this thing speficifc //Hajeebtok::$Database->Query("DELETE FROM link WHERE account_id = :id", ["id" => $this->id]); } public function DeleteMany() { if(!empty($this->account_id)) return Hajeebtok::$Database->Query("DELETE FROM views WHERE account_id = :account_id", ["account_id" => $this->account_id]); if(!empty($this->video_id)) return Hajeebtok::$Database->Query("DELETE FROM views WHERE video_id = :video_id", ["video_id" => $this->video_id]); } /** * Loads the object from the database. */ public function Load() { // not implemented } public function LoadMany(): array { Logger::Debug("{$this->account_id}"); if(!empty($this->account_id)) { $array = ["account_id" => $this->account_id]; $query = "SELECT * FROM views WHERE account_id = :account_id"; } else if(!empty($this->video_id)) { $array = ["video_id" => $this->video_id]; $query = "SELECT * FROM views WHERE video_id = :video_id"; } else { throw new ViewNotFoundException(0, 404); } $data = Hajeebtok::$Database->Query($query, $array); if(empty($data)) throw new ViewNotFoundException(0, 404); return $data; } }