Implémentation de l'architecture MVC + le site affiche les questions mises sur sqlite + correction des réponses de l'utilisateur
parent
3d1d186e80
commit
73f8522837
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
//require_once ('Question.php');
|
||||
class QuestionsGateway {
|
||||
private $db;
|
||||
|
||||
|
||||
function __construct(SqliteDb $db) {
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
class Autoload
|
||||
{
|
||||
private static $_instance = null;
|
||||
public static $limite=3;
|
||||
|
||||
public static function setLimite($valeur){
|
||||
Autoload::$limite=$valeur;
|
||||
}
|
||||
public static function getLimite(){
|
||||
return Autoload::$limite;
|
||||
}
|
||||
public static function charger()
|
||||
{
|
||||
if(null !== self::$_instance) {
|
||||
throw new RuntimeException(sprintf('%s is already started', __CLASS__));
|
||||
}
|
||||
|
||||
self::$_instance = new self();
|
||||
|
||||
|
||||
if(!spl_autoload_register(array(self::$_instance, '_autoload'), false)) {
|
||||
throw RuntimeException(sprintf('%s : Could not start the autoload', __CLASS__));
|
||||
}
|
||||
}
|
||||
|
||||
public static function shutDown()
|
||||
{
|
||||
if(null !== self::$_instance) {
|
||||
|
||||
if(!spl_autoload_unregister(array(self::$_instance, '_autoload'))) {
|
||||
throw new RuntimeException('Could not stop the autoload');
|
||||
}
|
||||
|
||||
self::$_instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function _autoload($class)
|
||||
{
|
||||
global $rep;
|
||||
$filename = $class.'.php';
|
||||
$dir =array('modeles/','./','config/','controleur/','DAL/','metier/');
|
||||
foreach ($dir as $d){
|
||||
$file=$rep.$d.$filename;
|
||||
//echo $file;
|
||||
if (file_exists($file))
|
||||
{
|
||||
include $file;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
//gen
|
||||
$rep=__DIR__.'/../';
|
||||
|
||||
//Vues
|
||||
|
||||
$vues['vuePrincipale']='vues/vuePrincipale.php';
|
||||
|
||||
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
class Controleur {
|
||||
|
||||
function __construct() {
|
||||
global $rep,$vues;
|
||||
session_start();
|
||||
|
||||
$this->afficherQuestions();
|
||||
}
|
||||
|
||||
function afficherQuestions(){
|
||||
global $rep,$vues;
|
||||
|
||||
$model = new Modele();
|
||||
$dVueQuestions = $model->afficherQuestions();
|
||||
require ($rep.$vues['vuePrincipale']);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
class Question {
|
||||
|
||||
private $numQuestion;
|
||||
private $question;
|
||||
private $reponse;
|
||||
|
||||
function __construct($numQuestion,$question,$reponse){
|
||||
$this->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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Modele {
|
||||
|
||||
function afficherQuestions(){
|
||||
$db = new SqliteDb();
|
||||
$db->createTable();
|
||||
$qg = new QuestionsGateway($db);
|
||||
|
||||
$tabQuestions = $qg->afficherQuestions();
|
||||
return $tabQuestions;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group>
|
||||
<file>file:/C:/xampp/htdocs/BddCorrect/controleur/Controleur.php</file>
|
||||
<file>file:/C:/xampp/htdocs/BddCorrect/modeles/Modele.php</file>
|
||||
<file>file:/C:/xampp/htdocs/BddCorrect/vues/VuePrincipale.php</file>
|
||||
<file>file:/C:/xampp/htdocs/BddCorrect/SqliteDb.php</file>
|
||||
<file>file:/C:/xampp/htdocs/BddCorrect/DAL/QuestionsGateway.php</file>
|
||||
<file>file:/C:/xampp/htdocs/BddCorrect/Correcteur.php</file>
|
||||
</group>
|
||||
</open-files>
|
||||
</project-private>
|
Binary file not shown.
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<!--
|
||||
To change this license header, choose License Headers in Project Properties.
|
||||
To change this template file, choose Tools | Templates
|
||||
and open the template in the editor.
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
|
||||
/*$db = new SqliteDb();
|
||||
$result = $db->prepare('SELECT question FROM Correct');
|
||||
$result->execute(array());
|
||||
$listeQuestion = $result->fetchAll();*/
|
||||
|
||||
|
||||
//$Question1 = $db->querySingle('SELECT question FROM Correct');
|
||||
?>
|
||||
<form action="Correcteur.php" method="post">
|
||||
<?php foreach ($dVueQuestions as $q) { ?>
|
||||
<p><?php $i=0; $i++; echo $q->getQuestion(); ?> <br/> <input type="text" name="textbox[]" /></p><?php }?>
|
||||
<p><input type="submit" value="Valider"></p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue