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.
74 lines
2.6 KiB
74 lines
2.6 KiB
<?php
|
|
|
|
namespace API\Gateway;
|
|
|
|
use FORM_BusinessClass\BoxQuestion;
|
|
use FORM_BusinessClass\Question;
|
|
use PDO;
|
|
|
|
class GatewayQuestion
|
|
{
|
|
private Connection $connection;
|
|
|
|
public function __construct(Connection $connection)
|
|
{
|
|
$this->connection = $connection;
|
|
}
|
|
|
|
public function insertQuestion(Question $question, string $idForm)
|
|
{
|
|
$query = "INSERT INTO Question(content, type, form) VALUES(:content, :type, :form)";
|
|
$this->connection->executeQuery($query, array(
|
|
':content' => array($question->getContent(), PDO::PARAM_STR),
|
|
':type' => array(get_class($question), PDO::PARAM_STR),
|
|
':form' => array($idForm, PDO::PARAM_STR)
|
|
));
|
|
|
|
$this->connection->executeQuery();
|
|
|
|
$idQuestion = $this->connection->lastInsertId();
|
|
|
|
if(get_class($question) == BoxQuestion::class){
|
|
$listPossibleResponse = $question->getPossibleResponses();
|
|
|
|
for($i = 0; $i < count($listPossibleResponse); $i++){
|
|
|
|
$query = "INSERT INTO PossibleResponse(content) VALUES(:content)";
|
|
$this->connection->executeQuery($query, array(
|
|
':content' => array($listPossibleResponse[$i], PDO::PARAM_STR)
|
|
));
|
|
|
|
$this->connection->executeQuery();
|
|
|
|
$idPossibleReponse = $this->connection->lastInsertId();
|
|
|
|
$query = "INSERT INTO Propose(question, possibleResponse) VALUES(:question, :possibleResponse)";
|
|
$this->connection->executeQuery($query, array(
|
|
':question' => array($idQuestion, PDO::PARAM_INT),
|
|
':possibleResponse' => array($idPossibleReponse, PDO::PARAM_INT)
|
|
));
|
|
|
|
$this->connection->executeQuery();
|
|
|
|
|
|
foreach ($question->getCategories()[$i] as $keyword){
|
|
$gatewayForm = new GatewayForm($this->connection);
|
|
$gatewayForm->assignKeywordToQuestion($keyword, $idQuestion);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function updateQuestion(Question $question){
|
|
$query = "UPDATE Question SET content = :content, type = :type, form = :form WHERE id = :id";
|
|
$this->connection->executeQuery($query, array(
|
|
':content' => array($question->getContent(), PDO::PARAM_STR),
|
|
':type' => array(get_class($question), PDO::PARAM_STR),
|
|
':form' => array($question->getForm(), PDO::PARAM_STR),
|
|
':id' => array($question->getId(), PDO::PARAM_STR)
|
|
));
|
|
|
|
$this->connection->executeQuery();
|
|
}
|
|
|
|
} |