follower_id = $follower_id; $this->followee_id = $followee_id; } /** * Creates the table for the object type in the database. */ public static function CreateTable(): void { throw new SecurityFaultException("Attempt to create table on follow object."); } /** * Drops the table for the object type from the database. */ public static function DropTable(): void { throw new SecurityFaultException("Attempt to drop table on follow object."); } /** * Saves the object to the database. */ public function Save() { Hajeebtok::$Database->Query("INSERT INTO follows (follower_id, followee_id) VALUES (:follower_id, :followee_id)", [ "follower_id" => $this->follower_id, "followee_id" => $this->followee_id ]); $id = Hajeebtok::$Database->LastInsertId(); Logger::Debug("Saved account id ($id)."); } /** * Deletes the object from the database. */ public function Delete() { if(empty($this->follower_id) || empty($this->followee_id)) throw new FollowNotFoundException(0, 404); Hajeebtok::$Database->Query("DELETE FROM follows WHERE follower_id = :follower_id AND followee_id = :followee_id", [ "follower_id" => $this->follower_id, "followee_id" => $this->followee_id ]); } /** * Loads the object from the database. */ public function Load() { // unimplemented } public function LoadMany(): array { if(!empty($this->follower_id) && empty($this->followee_id)) { $command = "SELECT * FROM follows WHERE follower_id = :follower_id"; $array = ["follower_id" => $this->follower_id]; } else if(empty($this->follower_id) && !empty($this->followee_id)) { $command = "SELECT * FROM follows WHERE followee_id = :followee_id"; $array = ["followee_id" => $this->followee_id]; } else { throw new FollowNotFoundException(0, 404); } return Hajeebtok::$Database->Query($command, $array); } }