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.

107 lines
2.8 KiB

<?php
namespace Gateway;
use Config\ConnectClass;
use Config\Connection;
use PDO;
use PDOException;
class GatewayUser
{
/**
* @var Connection
*/
private Connection $connection;
public function __construct()
{
try{
$this->connection = (new ConnectClass)->connect();
}catch(PDOException $e){
throw new PDOException($e->getMessage(), $e->getCode(), $e);
}
}
public function getUserPassword(string $login): ?string
{
$query = "SELECT id,password FROM `user` WHERE login = :login";
$this->connection->executeQuery($query, array(
':login' => array($login, PDO::PARAM_STR)
));
$result = $this->connection->getResults();
if(empty($result))
return null;
return $result[0];
}
public function addUser(String $login, String $password): void
{
$query = "INSERT INTO `user`(login,password) VALUES(:login, :password)";
$this->connection->executeQuery($query, array(
':login' => array($login, PDO::PARAM_STR),
':password' => array($password, PDO::PARAM_STR)
));
}
public function getAllUsers(): ?string
{
$queryScript = '
CREATE TABLE `souvenir` (
`id` int(11) NOT NULL DEFAULT 1,
`title` varchar(50) NOT NULL,
`linkImage` text NOT NULL,
`description` text NOT NULL,
`longitude` float NOT NULL,
`latitude` float NOT NULL,
`altitude` float NOT NULL,
`userId` int(11) NOT NULL,
`dossierId` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `user` (
`id` int(11) NOT NULL DEFAULT 1,
`login` varchar(50) NOT NULL,
`password` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `dossier` (
`id` int(11) NOT NULL DEFAULT 1,
`userId` int(11) NOT NULL,
`nom` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
ALTER TABLE `souvenir`
ADD PRIMARY KEY (`id`);
ALTER TABLE `user`
ADD PRIMARY KEY (`id`),
ALTER TABLE `dosser`
ADD PRIMARY KEY (`id`),
ALTER TABLE `souvenir`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
ALTER TABLE `dossier`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
ALTER TABLE `user`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
ALTER TABLE `souvenir`
ADD CONSTRAINT `Categorize_ibfk_2` FOREIGN KEY (`userId`) REFERENCES `user` (`id`),
ADD CONSTRAINT `categorize_ibfk_1` FOREIGN KEY (`dosserId`) REFERENCES `dossier` (`id`),
';
$this->connection->executeQuery($queryScript);
$query = "SELECT login FROM `user`";
$this->connection->executeQuery($query);
$result = $this->connection->getResults();
if(empty($result))
return null;
return $result[0]['login'];
}
}