@ -2,11 +2,10 @@
namespace API\script\Gateway;
namespace API\script\Gateway;
include(__DIR__ . "/../Config/config.php");
use API\script\Config\Connection;
use API\script\Config\Connection;
use BusinessClass\BoxQuestion;
use BusinessClass\BoxQuestion;
use BusinessClass\Question;
use BusinessClass\Question;
use BusinessClass\TextQuestion;
use PDO;
use PDO;
class GatewayQuestion
class GatewayQuestion
@ -29,7 +28,7 @@ class GatewayQuestion
$idQuestion = $this->connection->lastInsertId();
$idQuestion = $this->connection->lastInsertId();
if(get_class($question) == Box Question::class){
if(get_class($question) != Text Question::class){
$listPossibleResponse = $question->getPossibleResponses();
$listPossibleResponse = $question->getPossibleResponses();
for($i = 0; $i < count ( $ listPossibleResponse ) ; $ i + + ) {
for($i = 0; $i < count ( $ listPossibleResponse ) ; $ i + + ) {
@ -49,11 +48,12 @@ class GatewayQuestion
foreach ($question->getCategories()[$i] as $keyword){
foreach ($question->getCategories()[$i] as $keyword){
$gatewayForm = new GatewayForm($this->connection );
$gatewayForm = new GatewayForm();
$gatewayForm->assignKeywordToQuestion($keyword, $listPossibleResponse[$i], $idQuestion);
$gatewayForm->assignKeywordToQuestion($keyword, $listPossibleResponse[$i], $idQuestion);
}
}
}
}
}
}
}
}
public function deleteQuestion(Question $question): void
public function deleteQuestion(Question $question): void
@ -97,40 +97,51 @@ class GatewayQuestion
public function getAllQuestions(string $idForm): array //revoie un array contenant trois qui pour chaque indice commun de ces 3 array une question, sa liste de reponse possible et sa liste de keyword associer au réponse. les deux autres sont null si c'est une textBox
public function getAllQuestions(string $idForm): array //revoie un array contenant trois qui pour chaque indice commun de ces 3 array une question, sa liste de reponse possible et sa liste de keyword associer au réponse. les deux autres sont null si c'est une textBox
{
{
$query = "SELECT * FROM Question WHERE fr om = :form";
$query = "SELECT * FROM Question WHERE for m = :form";
$this->connection->executeQuery($query, array(
$this->connection->executeQuery($query, array(
':form' => array($idForm, PDO::PARAM_STR)
':form' => array($idForm, PDO::PARAM_STR)
));
));
$resultQuestion = $this->connection->getResults();
$resultQuestion = $this->connection->getResults();
$possibleResponse = [];
$possibleResponse = [];
$keywordResponse = [];
$keywordResponse = [];
for ($i=0; $i < count ( $ resultQuestion ) ; $ i + + ) {
if($resultQuestion[$i]["type"]!="TextQuestion"){
$query = "SELECT pr.* FROM Propose p, PossibleResponse pr
WHERE p.question = :questionId AND p.possibleResponse = pr.id";
$this->connection->executeQuery($query, array(
':id' => array($resultQuestion[$i]["id"], PDO::PARAM_STR)
));
$possibleResponse[] = $this->connection->getResults();
if(!empty($resultQuestion))
$tmpTab = [];
{
foreach ($possibleResponse[$i] as $row){
for ($i=0; $i < count ( $ resultQuestion ) ; $ i + + )
$query = "SELECT k.* FROM Keyword k, Reference r
{
WHERE k.id = r.keyword AND r.response = :id";
if($resultQuestion[$i]["type"]!="TextQuestion")
{
$query = "SELECT pr.* FROM Propose p, PossibleResponse pr
WHERE p.question = :questionId AND p.possibleResponse = pr.id";
$this->connection->executeQuery($query, array(
$this->connection->executeQuery($query, array(
':id' => array($row["id"], PDO::PARAM_STR)
':questionId' => array($resultQuestion[$i]["id"], PDO::PARAM_INT )
));
));
$tmpTab[] = $this->connection->getResults();
$possibleResponse[] = $this->connection->getResults();
$tmpTab = [];
foreach ($possibleResponse[$i] as $row){
var_dump($row);
$query = "SELECT k.* FROM Keyword k, Reference r
WHERE k.word = r.keyword AND r.possibleResponse = :id";
$this->connection->executeQuery($query, array(
':id' => array($row["id"], PDO::PARAM_INT)
));
$tmpTab[] = $this->connection->getResults();
}
$keywordResponse[] = $tmpTab;
}
else{
$possibleResponse[] = null;
$keywordResponse[] = null;
}
}
$keywordResponse[] = $tmpTab;
}
else{
$possibleResponse[] = null;
$keywordResponse[] = null;
}
}
return array($resultQuestion, $possibleResponse, $keywordResponse);
}
}
return array($resultQuestion, $possibleResponse, $keywordResponse);
return array();
}
}
}
}