You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.4 KiB
79 lines
2.4 KiB
<?php
|
|
|
|
class GatewayPlayer
|
|
{
|
|
private $con;
|
|
|
|
public function __construct($con)
|
|
{
|
|
$this->con = $con;
|
|
}
|
|
|
|
public function addPlayer($player)
|
|
{
|
|
$query = "insert into Players(id,nickname,hashedPassword) values (:id,:nickname,:hashedPassword);";
|
|
$this->con->executeQuery(
|
|
$query,
|
|
array(
|
|
':id' => array($player->getId(), PDO::PARAM_INT),
|
|
':nickname' => array($player->getNickname(), PDO::PARAM_STR),
|
|
':hashedPassword' => array($player->getHashedPassword(), PDO::PARAM_STR)
|
|
)
|
|
);
|
|
}
|
|
|
|
public function getPlayerByNickname(string $nickname)
|
|
{
|
|
$query = "SELECT * FROM Players WHERE nickname = :nickname;";
|
|
$this->con->executeQuery($query, array(':nickname' => array($nickname, PDO::PARAM_STR)));
|
|
$results = $this->con->getResults();
|
|
if ($results == NULL) {
|
|
return false;
|
|
}
|
|
return new Player($results[0]['id'], $results[0]['nickname'], $results[0]['hashedPassword']);
|
|
}
|
|
public function getPlayerByID(int $id)
|
|
{
|
|
$query = "SELECT * FROM Players WHERE id = :id;";
|
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
|
|
$results = $this->con->getResults();
|
|
if ($results == NULL) {
|
|
return false;
|
|
}
|
|
return new Player($results[0]['id'], $results[0]['nickname'], $results[0]['hashedPassword']);
|
|
}
|
|
public function getPlayers()
|
|
{
|
|
$query = "SELECT * FROM Players;";
|
|
$this->con->executeQuery($query);
|
|
$results = $this->con->getResults();
|
|
if ($results == NULL) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function updatePlayer($player)
|
|
{
|
|
$query = "UPDATE Players SET nickname = :nickname, hashedPassword = :hashedPassword WHERE id = :id;";
|
|
$this->con->executeQuery(
|
|
$query,
|
|
array(
|
|
':id' => array($player->getId(), PDO::PARAM_INT),
|
|
':nickname' => array($player->getNickname(), PDO::PARAM_STR),
|
|
':hashedPassword' => array($player->getHashedPassword(), PDO::PARAM_STR)
|
|
)
|
|
);
|
|
}
|
|
|
|
public function deletePlayerByID(int $id)
|
|
{
|
|
$query = "DELETE FROM Players WHERE id = :id;";
|
|
$this->con->executeQuery(
|
|
$query,
|
|
array(
|
|
':id' => array($id, PDO::PARAM_INT)
|
|
)
|
|
);
|
|
}
|
|
}
|