parent
454e643825
commit
b1a0802524
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace API\Gateway;
|
||||||
|
|
||||||
|
use FORM_BusinessClass\Question;
|
||||||
|
use PDO;
|
||||||
|
|
||||||
|
class GatewayForm
|
||||||
|
{
|
||||||
|
private Connection $connection;
|
||||||
|
|
||||||
|
public function __construct(Connection $connection)
|
||||||
|
{
|
||||||
|
$this->connection = $connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function assignKeywordToQuestion(Keyword $keyword, string $response, int $idQuestion)
|
||||||
|
{
|
||||||
|
$query = "SELECT pr.id FROM Propose p, PossibleResponse r WHERE p.question = :id AND p.possibleResponse = pr.id AND pr.content = :response";
|
||||||
|
$this->connection->executeQuery($query, array(
|
||||||
|
':id' => array($idQuestion, PDO::PARAM_STR),
|
||||||
|
':response' => array($response, PDO::PARAM_STR)
|
||||||
|
));
|
||||||
|
$this->connection->executeQuery();
|
||||||
|
|
||||||
|
$idPossibleResponse = $this->connection->getResults()[0][0];
|
||||||
|
|
||||||
|
|
||||||
|
$query = "INSERT INTO Reference(id, word) VALUES(:id, :word)";
|
||||||
|
$this->connection->executeQuery($query, array(
|
||||||
|
':idResponse' => array($idPossibleResponse, PDO::PARAM_INT),
|
||||||
|
':idKeword' => array($keyword->getId(), PDO::PARAM_INT)
|
||||||
|
));
|
||||||
|
$this->connection->executeQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteKeywordFromQuestion(Keyword $keyword, string $response, Question $question)
|
||||||
|
{
|
||||||
|
$query = "SELECT pr.id FROM Propose p, PossibleResponse r WHERE p.question = :id AND p.possibleResponse = pr.id AND pr.content = :response";
|
||||||
|
$this->connection->executeQuery($query, array(
|
||||||
|
':id' => array($question->getId(), PDO::PARAM_STR),
|
||||||
|
':response' => array($response, PDO::PARAM_STR)
|
||||||
|
));
|
||||||
|
$this->connection->executeQuery();
|
||||||
|
|
||||||
|
$idPossibleResponse = $this->connection->getResults()[0][0];
|
||||||
|
|
||||||
|
$query = "DELETE FROM Reference WHERE response = :idResponse AND keyword = :idKeword";
|
||||||
|
$this->connection->executeQuery($query, array(
|
||||||
|
':idResponse' => array($idPossibleResponse, PDO::PARAM_INT),
|
||||||
|
':idKeword' => array($keyword->getId(), PDO::PARAM_INT)
|
||||||
|
));
|
||||||
|
$this->connection->executeQuery();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue