| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?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.
- */
- public function __construct($id){
- $statement = get_context()->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"];
- // Get all accounts
- $statement = get_context()->get_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"]));
- }
- }
- }
- }
- ?>
|