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/GatewayForm.php

75 lines
2.5 KiB

<?php
namespace API\script\Gateway;
use API\script\Config\Connection;
use BusinessClass\Form;
use BusinessClass\Keyword;
use BusinessClass\Question;
use PDO;
class GatewayForm
{
private Connection $connection;
public function __construct()
{
$this->connection = connect();
}
public function insertForm(Form $form): void
{
if(empty($this->getForm()))
{
$query = "INSERT INTO Form(title, description) VALUES(:title, :description)";
$this->connection->executeQuery($query, array(
':title' => array($form->getTitle(), PDO::PARAM_STR),
':description' => array($form->getDescription(), PDO::PARAM_STR)
));
}
}
public function getForm(): array
{
$query = "SELECT * FROM Form";
$this->connection->executeQuery($query);
return $this->connection->getResults();
}
public function assignKeywordToQuestion(string $keyword, string $response, int $idQuestion)
{
echo $keyword;
$query = "SELECT pr.id FROM Propose p, PossibleResponse pr 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)
));
$idPossibleResponse = $this->connection->getResults()[0][0];
$query = "INSERT INTO Reference(possibleResponse, keyword) VALUES(:possibleResponse, :keyword)";
$this->connection->executeQuery($query, array(
':possibleResponse' => array($idPossibleResponse, PDO::PARAM_INT),
':keyword' => array($keyword, PDO::PARAM_STR)
));
}
public function deleteKeywordFromQuestion(string $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)
));
$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)
));
}
}