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.

62 lines
1.6 KiB

<?php
namespace Gateway;
use Config\Connection;
use Config\ConnectClass;
use PDO;
use PDOException;
class GatewayKeyword
{
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 insertKeyword(string $keyword): void
{
$query = "INSERT INTO Keyword(word) VALUES(:word)";
$this->connection->executeQuery($query, array(
':word' => array($keyword, PDO::PARAM_STR)
));
}
public function deleteKeyword(string $keyword): void
{
$query = "DELETE FROM Keyword WHERE word = :word";
$this->connection->executeQuery($query, array(
':word' => array($keyword, PDO::PARAM_STR)
));
}
public function getAllKeyword(): array
{
$query = "SELECT * FROM Keyword";
$this->connection->executeQuery($query);
return $this->connection->getResults();
}
public function getKeywordsContentByReference(int $id): array
{
$query = "SELECT k.* FROM Keyword k, Reference r
WHERE k.word = r.keyword AND r.possibleResponse = :id";
$this->connection->executeQuery($query, array(
':id' => array($id, PDO::PARAM_STR)
));
$tab = [];
foreach ($this->connection->getResults() as $result)
{
$tab[] = $result["word"];
}
return $tab;
}
}