get_db()->prepare(" SELECT id, name, mail, api_key, admin FROM user WHERE id = :id; "); $statement->bindValue(':id', $id, SQLITE3_TEXT); $r = $statement->execute()->fetchArray(SQLITE3_ASSOC); if ($r){ $this->id = $r["id"]; $this->name = $r["name"]; $this->mail = $r["mail"]; $this->api_key = $r["api_key"]; $this->admin = $r["admin"]; } } private function load_accounts(){ $statement = get_context()->get_db()->prepare(" SELECT id FROM player WHERE user = :user ORDER BY last_access DESC "); $statement->bindValue(':user', $this->id, SQLITE3_TEXT); $q = $statement->execute(); while ($r = $q->fetchArray(SQLITE3_ASSOC)){ array_push($this->account, new Player($r["id"])); } $this->flag_accounts = true; } /** * Retrieves the user identifier. * * @return number User ID. */ public function get_id(){ return $this->id; } /** * Retrieves the user name. * * @return string User name. */ public function get_name(){ return $this->name; } /** * Retrieves the user email address. * * @return string User mail. */ public function get_mail(){ return $this->mail; } /** * Retrieves the user's API key. * * @return string User's API key. */ public function get_api_key(){ return $this->api_key; } /** * Checks if the user is a site administrator. * * @return boolean True if the user is administrator, false otherwise. */ public function is_admin(){ return $this->admin; } /** * Retrieves the user's accounts, sorted by the last account date in descending order. * * @return Player[] The user's accounts. */ public function get_accounts(){ if (! $this->flag_accounts){ $this->load_accounts(); } return $this->account; } } ?>