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.
75 lines
2.5 KiB
75 lines
2.5 KiB
<?php
|
|
|
|
class GatewayAdministrator
|
|
{
|
|
private $con;
|
|
|
|
public function __construct($con)
|
|
{
|
|
$this->con = $con;
|
|
}
|
|
|
|
public function addAdministrator($administrator)
|
|
{
|
|
$query = "insert into Administrators(id,username,hashedPassword) values (:id,:username,:hashedPassword);";
|
|
$this->con->executeQuery(
|
|
$query,
|
|
array(
|
|
':id' => array($administrator->getId(), PDO::PARAM_INT),
|
|
':username' => array($administrator->getUsername(), PDO::PARAM_STR),
|
|
':hashedPassword' => array($administrator->getHashedPassword(), PDO::PARAM_STR)
|
|
)
|
|
);
|
|
}
|
|
|
|
public function getAdministratorByUsername(string $username)
|
|
{
|
|
$query = "SELECT * FROM Administrators WHERE username = :username;";
|
|
$this->con->executeQuery($query, array(':username' => array($username, PDO::PARAM_STR)));
|
|
$results = $this->con->getResults();
|
|
if ($results == NULL) {
|
|
return false;
|
|
}
|
|
return new Administrator($results[0]['id'], $results[0]['username'], $results[0]['hashedPassword']);
|
|
}
|
|
|
|
public function getAdministratorByID(int $id)
|
|
{
|
|
$query = "SELECT * FROM Administrators 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 Administrator($results[0]['id'], $results[0]['username'], $results[0]['hashedPassword']);
|
|
}
|
|
|
|
public function getAdministrators()
|
|
{
|
|
$query = "SELECT * FROM administrators";
|
|
$this->con->executeQuery($query);
|
|
$results = $this->con->getResults();
|
|
|
|
return $results;
|
|
}
|
|
|
|
public function updateAdministrator($administrator)
|
|
{
|
|
$query = "UPDATE Administrators SET username = :username, hashedPassword = :hashedPassword WHERE id = :id;";
|
|
$this->con->executeQuery(
|
|
$query,
|
|
array(
|
|
':id' => array($administrator->getId(), PDO::PARAM_INT),
|
|
':username' => array($administrator->getUsername(), PDO::PARAM_STR),
|
|
':hashedPassword' => array($administrator->getHashedPassword(), PDO::PARAM_STR)
|
|
)
|
|
);
|
|
}
|
|
|
|
public function deleteAdministratorByID($id)
|
|
{
|
|
$query = "DELETE FROM Administrators WHERE id = :id;";
|
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
|
|
}
|
|
}
|