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.
SAE4.01_FORMULAIRE/Source/API/script/Gateway/GatewayKeyword.php

73 lines
2.0 KiB

<?php
namespace API\script\Gateway;
use API\script\Config\Connection;
use BusinessClass\Keyword;
use PDO;
class GatewayKeyword
{
private Connection $connection;
public function __construct()
{
$this->connection = connect();
}
public function insertKeyword(Keyword $keyword): void
{
$query = "INSERT INTO Keyword(id, word) VALUES(:id, :word)";
$this->connection->executeQuery($query, array(
':id' => array($keyword->getId(), PDO::PARAM_INT),
':word' => array($keyword->getWord(), PDO::PARAM_INT)
));
}
public function deleteKeyword(Keyword $keyword): void
{
$query = "DELETE FROM Keyword WHERE id = :id";
$this->connection->executeQuery($query, array(
':id' => array($keyword->getId(), PDO::PARAM_INT)
));
}
public function getAllKeyword(): array
{
$query = "SELECT * FROM Keyword";
$this->connection->executeQuery($query);
return $this->connection->getResults();
}
public function getKeywordsContentByReference(string $possibleResponseId): array
{
$query = "SELECT k.* FROM Keyword k, Reference r
WHERE k.word = r.keyword AND r.possibleResponse = :id";
return $this->getKeywordsContentByIdJonction($possibleResponseId, $query);
}
public function getKeywordsContentByCategorieze(string $responseId): array
{
$query = "SELECT k.* FROM Keyword k, Categorize r
WHERE k.word = r.keyword AND r.reponse = :id";
return $this->getKeywordsContentByIdJonction($responseId, $query);
}
private function getKeywordsContentByIdJonction(string $id, string $query): array
{
$this->connection->executeQuery($query, array(
':id' => array($id, PDO::PARAM_INT)
));
$tabTmp = [];
foreach ($this->connection->getResults() as $keywords)
{
$tabTmp[] = $keywords["word"];
}
return $tabTmp;
}
}