| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- /**
- * User entity file.
- *
- * Creates the entity and makes it available.
- *
- * @category Entity
- */
- /**
- * Require dependent entities if not present.
- */
- require_once(PATH::ENTITY . "Entity.php");
- require_once(PATH::ENTITY . "Player.php");
- /**
- * A User.
- *
- * Represents an object from the table 'user'.
- *
- * @category Entity
- */
- class User extends Entity{
- /**
- * @var int User ID.
- */
- public $id;
- /**
- * @var string User name.
- */
- public $name;
- /**
- * @var string User email.
- */
- public $mail;
- /**
- * @var string User API key.
- */
- public $api_key;
- /**
- * @var boolean Indicates if the user is an administrator.
- */
- public $admin = false;
- /**
- * @var \Player[] All of the players accounts.
- */
- public $account = [];
- /**
- * Constructor.
- *
- * Searches the database and retrieves the information about the
- * user, populating it and it's items.
- *
- * @param int $id User identifier.
- * @global resource Database connection.
- */
- public function __construct($id){
- global $db;
- $statement = $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"];
- // Get all accounts
- $statement = $db->prepare("
- SELECT id
- FROM player
- WHERE user = :user
- ");
- $statement->bindValue(':user', $this->id, SQLITE3_TEXT);
- $q = $statement->execute();
- while ($r = $q->fetchArray(SQLITE3_ASSOC)){
- array_push($this->account, new Player($r["id"]));
- }
- }
- }
- }
- ?>
|