diff --git a/BddCorrect/Correcteur.php b/BddCorrect/Correcteur.php index 5459f58..163065d 100644 --- a/BddCorrect/Correcteur.php +++ b/BddCorrect/Correcteur.php @@ -4,19 +4,28 @@ require_once('SqliteDb.php'); +header('Content-type: text/plain'); $db = new SqliteDb(); -$db->exec('DROP TABLE Correct'); -$db->exec('CREATE TABLE Correct (question STRING, reponse STRING)'); -$db->exec("INSERT INTO Correct VALUES ('Ceci est la question 1 ', 'réponse 1')"); - -$reponseUser = $_POST['R1']; -$reponseDb = $db->querySingle('SELECT reponse FROM Correct'); - -if ($reponseDb == $reponseUser) { - echo 'Bonne réponse !'; -} else { - echo 'Mauvaise réponse !'; +$cmpt = 0; +$i = 0; +foreach ($_POST['textbox'] as $textbox) { + $i++; + //$reponseUser = $_POST['']; + $query = $db->prepare('SELECT reponse FROM Correct WHERE rowid= ? '); + $query->bindParam(1, $i); + $result = $query->execute(); + while($row = $result->fetchArray()){ + if ($row['reponse'] == $textbox) { + echo "La réponse à la question n° ".$i." est JUSTE\n"; + $cmpt++; + } + else echo 'La réponse à la question n° '.$i." est FAUSSE\n\n"; + } + + } +echo 'Résultat ' . $cmpt . '/' . $i; + diff --git a/BddCorrect/DAL/QuestionsGateway.php b/BddCorrect/DAL/QuestionsGateway.php new file mode 100644 index 0000000..961aa93 --- /dev/null +++ b/BddCorrect/DAL/QuestionsGateway.php @@ -0,0 +1,23 @@ +db=$db; + } + + public function afficherQuestions() { + $i = 0; + $query = 'SELECT * FROM Correct'; + $query = $this->db->prepare($query); + $result = $query->execute(); + //$resultats = $this->db->query('SELECT found_rows()'); + while($q = $result->fetchArray()){ + $i= $i+1; + $tabQuestions[] = new Question($i,$q['question'],$q['reponse']); + } + return $tabQuestions; + } +} diff --git a/BddCorrect/SqliteDb.php b/BddCorrect/SqliteDb.php index 5eee981..7e83b9b 100644 --- a/BddCorrect/SqliteDb.php +++ b/BddCorrect/SqliteDb.php @@ -2,9 +2,18 @@ class SqliteDb extends SQLite3 { - function __construct() + function __construct() { $this->open('test.db'); + //$this->createTable(); + } + + function createTable(){ + $this->exec('DROP TABLE Correct'); + $this->exec('CREATE TABLE Correct ( question STRING, reponse STRING)'); + $this->exec("INSERT INTO Correct VALUES ('Ceci est la question 1 ', 'r1')"); + $this->exec("INSERT INTO Correct VALUES ('Ceci est la question 2 ', 'r2')"); + $this->exec("INSERT INTO Correct VALUES ('Ceci est la question 3 ', 'r3')"); } } diff --git a/BddCorrect/config/Autoload.php b/BddCorrect/config/Autoload.php new file mode 100644 index 0000000..e338890 --- /dev/null +++ b/BddCorrect/config/Autoload.php @@ -0,0 +1,55 @@ +afficherQuestions(); + } + + function afficherQuestions(){ + global $rep,$vues; + + $model = new Modele(); + $dVueQuestions = $model->afficherQuestions(); + require ($rep.$vues['vuePrincipale']); + + + } +} + diff --git a/BddCorrect/index.php b/BddCorrect/index.php index c4c6003..9dc644b 100644 --- a/BddCorrect/index.php +++ b/BddCorrect/index.php @@ -10,15 +10,13 @@ and open the template in the editor. - querySingle('SELECT question FROM Correct'); - ?> -
-


-

-
+ //chargement autoloader pour autochargement des classes + require_once(__DIR__.'/config/Autoload.php'); + Autoload::charger(); + + $cont = new Controleur();?> diff --git a/BddCorrect/metier/Question.php b/BddCorrect/metier/Question.php new file mode 100644 index 0000000..b36a696 --- /dev/null +++ b/BddCorrect/metier/Question.php @@ -0,0 +1,44 @@ +numQuestion = $numQuestion; + $this->question = $question; + $this->reponse = $reponse; + } + + // Getters + function getNumQuestion() { + return $this->numQuestion; + } + + function getQuestion() { + return $this->question; + } + + function getReponse() { + return $this->reponse; + } + + // Setters + function setNumQuestion($numQuestion) { + $this->numQuestion = $numQuestion; + } + + function setQuestion($question) { + $this->question = $question; + } + + function setReponse($reponse) { + $this->reponse = $reponse; + } + + +} + + diff --git a/BddCorrect/modeles/Modele.php b/BddCorrect/modeles/Modele.php new file mode 100644 index 0000000..f91880f --- /dev/null +++ b/BddCorrect/modeles/Modele.php @@ -0,0 +1,16 @@ +createTable(); + $qg = new QuestionsGateway($db); + + $tabQuestions = $qg->afficherQuestions(); + return $tabQuestions; + } + + +} diff --git a/BddCorrect/nbproject/private/private.properties b/BddCorrect/nbproject/private/private.properties index b492277..440ba30 100644 --- a/BddCorrect/nbproject/private/private.properties +++ b/BddCorrect/nbproject/private/private.properties @@ -1,3 +1,6 @@ +auxiliary.org-netbeans-modules-php-editor.fluent_2e_setter_2e_project_2e_property=false +auxiliary.org-netbeans-modules-php-editor.getter_2e_setter_2e_method_2e_name_2e_generation=AS_JAVA +auxiliary.org-netbeans-modules-php-editor.public_2e_modifier_2e_project_2e_property=false copy.src.files=false copy.src.on.open=false copy.src.target=C:\\xampp\\htdocs\\PhpProject1 diff --git a/BddCorrect/nbproject/private/private.xml b/BddCorrect/nbproject/private/private.xml new file mode 100644 index 0000000..b72aa6c --- /dev/null +++ b/BddCorrect/nbproject/private/private.xml @@ -0,0 +1,14 @@ + + + + + + file:/C:/xampp/htdocs/BddCorrect/controleur/Controleur.php + file:/C:/xampp/htdocs/BddCorrect/modeles/Modele.php + file:/C:/xampp/htdocs/BddCorrect/vues/VuePrincipale.php + file:/C:/xampp/htdocs/BddCorrect/SqliteDb.php + file:/C:/xampp/htdocs/BddCorrect/DAL/QuestionsGateway.php + file:/C:/xampp/htdocs/BddCorrect/Correcteur.php + + + diff --git a/BddCorrect/test.db b/BddCorrect/test.db index 67e9aa1..10bf2a3 100644 Binary files a/BddCorrect/test.db and b/BddCorrect/test.db differ diff --git a/BddCorrect/vues/VuePrincipale.php b/BddCorrect/vues/VuePrincipale.php new file mode 100644 index 0000000..5202352 --- /dev/null +++ b/BddCorrect/vues/VuePrincipale.php @@ -0,0 +1,29 @@ + + + + + + + + + prepare('SELECT question FROM Correct'); + $result->execute(array()); + $listeQuestion = $result->fetchAll();*/ + + + //$Question1 = $db->querySingle('SELECT question FROM Correct'); + ?> +
+ +

getQuestion(); ?>

+

+
+ +