diff --git a/Project/php/gateway/TranslationGateway.php b/Project/php/gateway/TranslationGateway.php index a8489a6..51ef1c8 100755 --- a/Project/php/gateway/TranslationGateway.php +++ b/Project/php/gateway/TranslationGateway.php @@ -12,7 +12,7 @@ class TranslationGateway extends AbsGateway private function addWord(string $word): void { try { - $query = "INSERT INTO Vocabulary VALUES (:word) ON DUPLICATE KEY UPDATE word=:word"; + $query = "INSERT INTO Vocabulary (word) VALUES (:word) ON DUPLICATE KEY UPDATE word=:word"; $args = array(':word' => array($word, PDO::PARAM_STR)); $this->con->executeQuery($query, $args); } catch (PDOException $e) { @@ -25,9 +25,10 @@ class TranslationGateway extends AbsGateway try { $this->addWord($parameters[0]); $this->addWord($parameters[1]); + $lastInsert = $this->con->lastInsertId("Vocabulary"); $query = "INSERT INTO Translate VALUES(null, :word1, :word2, :idVoc)"; - $args = array(':word1' => array($parameters[0], PDO::PARAM_STR), - ':word2' => array($parameters[1], PDO::PARAM_STR), + $args = array(':word1' => array($lastInsert-1, PDO::PARAM_INT), + ':word2' => array($lastInsert, PDO::PARAM_INT), ':idVoc' => array($parameters[2], PDO::PARAM_INT)); $this->con->executeQuery($query, $args); return $this->con->lastInsertId(); @@ -86,11 +87,25 @@ class TranslationGateway extends AbsGateway $tab = array(); foreach ($results as $row) { - $tab[] = new Translation($row['id'], $row['firstWord'], $row['secondWord'], $row['listVoc']); + $firstWord = $this->findWordById($row['firstWordID']); + $secondWord = $this->findWordById($row['secondWordID']); + $tab[] = new Translation($row['id'], $firstWord, $secondWord, $row['listVoc']); } return $tab; } catch (PDOException $e) { throw new Exception($e->getMessage()); } } + + private function findWordById(int $id): String + { + try{ + $query = "SELECT word FROM Vocabulary WHERE id=:id"; + $args = array('id' => array($id, PDO::PARAM_INT)); + $this->con->executeQuery($query, $args); + return $this->con->getResults()[0]['word']; + } catch (PDOException $e){ + throw new Exception(($e->getMessage())); + } + } } diff --git a/Project/php/js/quiz.js b/Project/php/js/quiz.js index 68df957..32b0bf4 100755 --- a/Project/php/js/quiz.js +++ b/Project/php/js/quiz.js @@ -18,7 +18,6 @@ function nextQuestion() { nextQuestionDiv.style.display = "block"; } else{ - alert() let form = document.createElement('form'); form.method = 'post'; form.action = 'resultatsQuiz'; diff --git a/Project/php/templates/home.html b/Project/php/templates/home.html index 1e00cc7..72093f6 100755 --- a/Project/php/templates/home.html +++ b/Project/php/templates/home.html @@ -113,9 +113,6 @@
-
@@ -149,11 +146,6 @@
-
- - - -