changement routeur

correction_routeur
Renaud BEURET 1 year ago
parent 4faf5aeca4
commit 00bb454e99

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ScienceQuest.iml" filepath="$PROJECT_DIR$/.idea/ScienceQuest.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpProjectSharedConfiguration" php_language_level="7.4">
<option name="suggestChangeDefaultLanguageLevel" value="false" />
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

@ -0,0 +1,4 @@
vendor/
composer.lock
js/bootstrap*.js*
css/bootstrap*.css*

@ -3,12 +3,20 @@
"psr-4": { "psr-4": {
"controller\\": "controller/", "controller\\": "controller/",
"config\\": "config/", "config\\": "config/",
"model\\": ["model/", "model/gateways/", "model/metier/"] "model\\": ["model/", "model/mdl/", "model/gateways/", "model/metier/", "model/exception/"]
} }
}, },
"require": { "require": {
"altorouter/altorouter": "^2.0", "altorouter/altorouter": "^2.0",
"twig/twig": "^3.7", "twig/twig": "^3.7",
"ext-pdo": "*" "twbs/bootstrap": "^5.3"
},
"scripts": {
"post-update-cmd": [
"rm -f ./js/bootstrap*.js*",
"rm -f ./css/bootstrap*.css*",
"cp ./vendor/twbs/bootstrap/dist/js/* ./js/",
"cp ./vendor/twbs/bootstrap/dist/css/* ./css/"
]
} }
} }

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "1dace5e05aa6a83586228ea227d11d71", "content-hash": "8ac61264e1d011c0b663d8c3dbdfc99f",
"packages": [ "packages": [
{ {
"name": "altorouter/altorouter", "name": "altorouter/altorouter",
@ -231,6 +231,56 @@
], ],
"time": "2023-07-28T09:04:16+00:00" "time": "2023-07-28T09:04:16+00:00"
}, },
{
"name": "twbs/bootstrap",
"version": "v5.3.2",
"source": {
"type": "git",
"url": "https://github.com/twbs/bootstrap.git",
"reference": "344e912d04b5b6a04482113eff20ab416ff01048"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twbs/bootstrap/zipball/344e912d04b5b6a04482113eff20ab416ff01048",
"reference": "344e912d04b5b6a04482113eff20ab416ff01048",
"shasum": ""
},
"replace": {
"twitter/bootstrap": "self.version"
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Otto",
"email": "markdotto@gmail.com"
},
{
"name": "Jacob Thornton",
"email": "jacobthornton@gmail.com"
}
],
"description": "The most popular front-end framework for developing responsive, mobile first projects on the web.",
"homepage": "https://getbootstrap.com/",
"keywords": [
"JS",
"css",
"framework",
"front-end",
"mobile-first",
"responsive",
"sass",
"web"
],
"support": {
"issues": "https://github.com/twbs/bootstrap/issues",
"source": "https://github.com/twbs/bootstrap/tree/v5.3.2"
},
"time": "2023-09-14T14:19:27+00:00"
},
{ {
"name": "twig/twig", "name": "twig/twig",
"version": "v3.7.1", "version": "v3.7.1",
@ -309,9 +359,7 @@
"stability-flags": [], "stability-flags": [],
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": [],
"ext-pdo": "*"
},
"platform-dev": [], "platform-dev": [],
"plugin-api-version": "2.6.0" "plugin-api-version": "2.6.0"
} }

@ -1,12 +1,15 @@
<?php <?php
namespace config; namespace config;
use model\ValidationException;
class Validation class Validation
{ {
public static function val_action($action) public static function val_action($action)
{ {
if (!isset($action)) { if (!isset($action)) {
throw new \Exception('pas d\'action'); throw new ValidationException('pas d\'action');
} }
} }
@ -15,13 +18,13 @@ class Validation
if ($jeu == '' || !filter_var($jeu, FILTER_SANITIZE_STRING)) { if ($jeu == '' || !filter_var($jeu, FILTER_SANITIZE_STRING)) {
$dVueErreur[] = 'Aucun jeu selectionné'; $dVueErreur[] = 'Aucun jeu selectionné';
$jeu = 0; $jeu = 0;
throw new \Exception("Erreur jeu"); throw new ValidationException("Erreur jeu");
} }
if ($difficulty == '' || !filter_var($difficulty, FILTER_VALIDATE_INT)) { if ($difficulty == '' || !filter_var($difficulty, FILTER_VALIDATE_INT)) {
$dVueErreur[] = "Aucune difficultée séléctionnée"; $dVueErreur[] = "Aucune difficultée séléctionnée";
$difficulty = 0; $difficulty = 0;
throw new \Exception("Erreur difficulté"); throw new ValidationException("Erreur difficulté");
} }
} }
@ -30,7 +33,54 @@ class Validation
if ($user == '' || !filter_var($user, FILTER_SANITIZE_STRING)) { if ($user == '' || !filter_var($user, FILTER_SANITIZE_STRING)) {
$dVueErreur[] = 'Identifiant invalide'; $dVueErreur[] = 'Identifiant invalide';
$jeu = 0; $jeu = 0;
throw new \Exception("Erreur identifiant"); throw new ValidationException("Erreur identifiant");
}
}
public static function valCodeInvitation(string &$codeInvitation, &$dVueErreur){
if($codeInvitation == ''){
$dVueErreur[] = 'Code d\'invitation invalide';
throw new ValidationException("Code d'invitation invalide");
}
return htmlspecialchars($codeInvitation);
}
public static function valPseudo(string &$pseudo, &$dVueErreur){
$pseudo = trim($pseudo);
$pseudo = htmlspecialchars($pseudo);
$pseudo = filter_var($pseudo, FILTER_UNSAFE_RAW);
if($pseudo == '' ){
$dVueErreur[] = 'Pseudo invalide';
throw new ValidationException("Pseudo invalide");
}
return $pseudo;
} }
public static function valRole(&$role, &$dVueErreur){
if(! $role instanceof \model\Joueur){
$role = NULL;
$dVueErreur[] = 'Role invalide';
throw new ValidationException('Role invalide');
}
return $role;
}
public static function valConfigurationJeu(&$configurationJeu, &$dVueErreur){
if(! $configurationJeu instanceof \model\ConfigurationJeu){
$role = NULL;
$dVueErreur[] = 'Configuration du jeu invalide';
throw new ValidationException('Configuration du jeu');
}
return $configurationJeu;
} }
public static function valMdlPendu(&$pendu, &$dVueErreur){
if(! $pendu instanceof \model\MdlPendu){
$role = NULL;
$dVueErreur[] = 'Erreur mauvais jeu en utilisation';
throw new ValidationException('Erreur mauvais jeu en utilisation');
}
return $pendu;
}
} }

@ -1,21 +1,15 @@
<?php <?php
namespace config; namespace config;
//gen $config = [
$rep=__DIR__.'/../'; "rep" => __DIR__.'/../',
"db" => ["dsn" => 'pgsql:host=localhost;dbname=dbrebeuret',
// liste des modules à inclure "login" => 'rebeuret',
"mdp" => 'achanger'],
//$dConfig['includes']= array('controleur/Validation.php'); "templates" => ["index" => 'vues/index.php',
"pseudo" => 'pseudo.html',
"pendu" => "pendu.html",
//BD "penduScore" => 'penduScore.html']
];
$base = 'mysql:host=localhost;dbname=sae';
$login = 'root';
$mdp = '';
//Vues
$vues['index']='vues/index.php';
?> ?>

@ -4,24 +4,21 @@ namespace controller;
use config\Validation; use config\Validation;
use http\Params; use http\Params;
use model\Connection; use model\Connection;
use model\ModelAdmin; use model\LoginException;
use model\UserGateway; use model\MdlAdmin;
use model\MdlUser;
class FrontController class FrontController
{ {
private Connection $con;
public function __construct() public function __construct()
{ {
global $twig, $router; global $twig, $router;
global $login;
global $mdp;
global $base;
global $basePath; global $basePath;
$con = new Connection($base, $login, $mdp);
//altorouter //altorouter
$router = new \AltoRouter(); $router = new \AltoRouter();
$router->setBasePath('ScienceQuest/Project/src/'); $router->setBasePath($basePath);
$router->map('GET|POST','/[a:action]?','UserController'); $router->map('GET|POST','/[a:action]?','UserController');
$router->map('GET|POST','/admin/[a:action]','AdminController'); $router->map('GET|POST','/admin/[a:action]','AdminController');
@ -47,22 +44,27 @@ class FrontController
} }
switch($match['target']) { switch($match['target']) {
case 'UserController': case 'UserController':
$this->callController('UserController',$match); $this->callController('UserController',$match);
break; break;
case 'AdminController': case 'AdminController':
$action = $match['params']['action']; $action = $match['params']['action'];
if (!ModelAdmin::isAdmin()) { if (!MdlAdmin::isAdmin()) {
$action = 'login'; $action = 'login';
} }
$this->callController('AdminController',$action); $this->callController('AdminController',$action);
case 'PseudoController':
$this->callController('PseudoController',$match);
break; break;
case 'validationFormulaire': case 'validationFormulaire':
$this->ValidationFormulaire($dVueErreur, $dVue); $this->ValidationFormulaire($dVueErreur, $dVue);
break; break;
//mauvaise action
default: default:
$dVueErreur[] = "Erreur d'appel php"; $dVueErreur[] = "Erreur d'appel php";
echo $twig->render('accueil.html', ['dVueErreur' => $dVueErreur]); echo $twig->render('accueil.html', ['dVueErreur' => $dVueErreur]);
@ -83,6 +85,7 @@ class FrontController
exit(0); exit(0);
} }
private function callController(string $cont, array $match) { private function callController(string $cont, array $match) {
global $twig; global $twig;
@ -101,12 +104,25 @@ class FrontController
{ {
global $twig; global $twig;
$game = $_POST['game'] ?? ''; $id_jeu = $_POST['jeu'] ?? '';
$difficulty = $_POST['difficulty'] ?? ''; $id_difficulte = $_POST['difficulte'] ?? '';
\config\Validation::val_form($game, $difficulty, $dVueErreur); try{
\config\Validation::val_form($id_jeu, $id_difficulte, $dVueErreur);
}catch (\model\ValidationException $ex){
$this->CreateParty($dVueErreur);
}catch (\Exception $ex){
$this->CreateParty($dVueErreur);
}
$dVue['info'] = "Jeu '$game' créé avec la difficulté $difficulty"; if(count($dVueErreur) == 0){
$jeu = (new \model\MdlJeu())->getFromId($id_jeu);
$difficulte = (new \model\MdlDifficulte())->getFromId($id_difficulte);
$_SESSION['configuration'] = new \model\ConfigurationJeu($jeu, $difficulte);
echo $twig->render('accueil.html', ['dVue' => $dVue, 'dVueErreur' => $dVueErreur]); header("Location: /pseudo");
#echo $twig->render('accueil.html', ['dVue' => $dVue, 'dVueErreur' => $dVueErreur]);
}else{
$this->CreateParty($dVueErreur);
}
} }
} }

@ -0,0 +1,86 @@
<?php
namespace controller;
use model\ConfigurationJeu;
use model\Joueur;
use model\MdlPendu;
use model\MdlScientifique;
use config\Validation;
use model\ValidationException;
class PenduController{
private array $dVue;
private array $dVueErreur;
private MdlPendu $pendu;
public function __construct(Joueur $role, ConfigurationJeu $configJeu)
{
$this->dVue = [];
$this->dVueErreur = [];
if(isset($_SESSION['pendu']) && Validation::valMdlPendu($_SESSION['pendu'], $this->dVueErreur)){
$this->pendu = $_SESSION['pendu'];
}else{
$this->reinit();
}
if(isset($_POST['lettre'])){
try{
$this->pendu->jouerLettre($_POST['lettre']);
}catch (ValidationException $e){
$this->dVueErreur[] = $e->getMessage();
}
}
if($this->pendu->aGagne()){
$this->renderAgagne();
}elseif($this->pendu->aPerdu()){
$this->renderAPerdu();
}else{
$this->renderJeu();
}
}
private function reinit(){
$mdlScientifique = new MdlScientifique();
$scientifique = $mdlScientifique->getRandom();
$this->pendu = new MdlPendu($scientifique);
$_SESSION['pendu'] = $this->pendu;
}
private function renderJeu(){
global $twig, $config;
$this->dVue['decouvert'] = $this->pendu->getDecouvert();
$this->dVue['essaisRestant'] = $this->pendu->getEssaisRestant();
$lettreUtilisees = $this->pendu->getLettreUtilisees();
sort($lettreUtilisees);
$this->dVue['lettresUtilisees'] = $lettreUtilisees;
echo $twig->render($config['templates']['pendu'], ['dVue' => $this->dVue, 'dVueErreur'=>$this->dVueErreur]);
}
private function renderAgagne(){
$this->dVue['messageScore'] = "Vous avez gagné !";
$this->renderScore();
}
private function renderAPerdu(){
$this->dVue['messageScore'] = "Vous avez perdu !";
$this->renderScore();
}
private function renderScore(){
global $twig, $config;
$this->dVue['nbTours'] = $this->pendu->getNbTours();
$this->dVue['nbFails'] = $this->pendu->getNbFails();
$scientifique = $this->pendu->getScientifique();
$dScientifique = [];
$dScientifique['nom'] = $scientifique->getNom();
$dScientifique['prenom'] = $scientifique->getPrenom();
$dScientifique['sexe'] = $scientifique->getSexe()->getLibelle();
$dScientifique['thematique'] = $scientifique->getThematique()->getLibelle();
$dScientifique['dateNaiss'] = $scientifique->getDateNaiss()->format('d/m/Y');
$this->dVue['scientifique'] = $dScientifique;
unset($_SESSION['pendu']);
echo $twig->render($config['templates']['penduScore'], ["dVue" => $this->dVue]);
}
}

@ -0,0 +1,42 @@
<?php
namespace controller;
use config\Validation;
use model\IdSessionDoubleException;
use model\PseudoDejaPrisException;
use model\ValidationException;
use model\MdlInvite;
class PseudoController{
public function __construct(){
global $twig, $config;
$dVue = [];
$dVueErreur = [];
if(isset($_POST["pseudo"])){
try{
$mdlInvite = new MdlInvite();
$pseudo = $_POST["pseudo"];
$pseudo = Validation::valPseudo($pseudo, $dVueErreur);
$role = $mdlInvite->insertInvite($pseudo, session_id());
}catch(ValidationException $e){
}catch(PseudoDejaPrisException $e){
$dVueErreur[] = "Pseudo déjà pris";
}catch(IdSessionDoubleException $e){
try{
$role = $mdlInvite->setPseudo($e->getIdJoueur(), $pseudo);
}catch(PseudoDejaPrisException $e){
$dVueErreur[] = "Pseudo déjà pris";
}
}
if(isset($role)){
$_SESSION['role'] = $role;
header('Location: jouer');
}
}
echo $twig->render($config['templates']['pseudo'], ["dVue" => $dVue, "dVueErreur" => $dVueErreur]);
}
}

@ -2,39 +2,78 @@
namespace controller; namespace controller;
use config\Validation;
use model\Connection; use model\Connection;
use model\GameGateway; use model\GameGateway;
use model\ValidationException;
class UserController { class UserController {
public function CreateParty() {
public function accueil(array $params) {
global $twig; global $twig;
$dVueCreate = \model\GameGateway::getGames(); echo $twig->render('accueil.html');
echo $twig->render('create.html', ['dVueCreate' => $dVueCreate]);
} }
public function JoinParty() { public function joinParty(array $params) {
global $twig; global $twig;
global $base;
global $login;
global $mdp;
$con = new Connection($base, $login, $mdp); if(isset($_POST['codeInvitation'])){
$gg = new GameGateway($con); $codeInvitation = $_POST['codeInvitation'];
Validation::valCodeInvitation($codeInvitation, $dVueErreur);
if(!isset($_REQUEST['code'])) {
echo $twig->render('join.html'); echo $twig->render('join.html');
} elseif (empty($_REQUEST['code']) || !sizeof($gg->getGameByCode($_REQUEST['code']))) {
$dErreur[] = 'Code de partie invalide';
echo $twig->render('join.html',['dErreur' => $dErreur]);
} else {
// rejoindre la partie
} }
} }
public function accueil(array $params) { public function jouer(array $params) {
global $twig, $config;
$dVue = [];
$dVueErreur = [];
if(isset($_SESSION["configuration"]) && isset($_SESSION['role'])){
try{
$role = $_SESSION['role'];
$role = Validation::valRole($role, $dVueErreur);
$configurationJeu = $_SESSION['configuration'];
$configurationJeu = Validation::valConfigurationJeu($configurationJeu, $dVueErreur);
}catch(ValidationException $e){
header('Location: .');
}
if(count($dVueErreur) == 0){
$idJeu = $configurationJeu->getJeu()->getId();
switch($idJeu){
case 3:
new PenduController($role, $configurationJeu);
break;
default:
throw new Exception("Jeu non défini !");
break;
}
}
}else{
header("Location: .");
}
}
public function createParty(array $params) : void
{
global $twig; global $twig;
global $dVueErreur;
echo $twig->render('accueil.html'); $listJeu = (new \model\MdlJeu())->getAll();
$listDifficulte = (new \model\MdlDifficulte())->getAll();
$dVueCreateJeu = [];
foreach($listJeu as $jeu){
$dVueCreateJeu[] = ['id' => $jeu->getId(), 'nom' => $jeu->getNom()];
}
$dVueCreateDifficulte = [];
foreach($listDifficulte as $difficulte){
$dVueCreateDifficulte[] = ['id' => $difficulte->getId(), 'libelle' => $difficulte->getLibelle()];
}
echo $twig->render('create.html', ["dVueErreur" => $dVueErreur, 'dVueCreate' => ["jeux" => $dVueCreateJeu, "difficultes" => $dVueCreateDifficulte]]);
} }
} }

@ -0,0 +1,182 @@
-- Testé sous pgsql 15
DROP TABLE IF EXISTS Reponse;
DROP TABLE IF EXISTS Question;
DROP TABLE IF EXISTS Admin;
DROP TABLE IF EXISTS Partie;
DROP TABLE IF EXISTS Jeu;
DROP TABLE IF EXISTS Decouvrir;
DROP TABLE IF EXISTS Utilisateur;
DROP TABLE IF EXISTS Invite;
DROP TABLE IF EXISTS Joueur;
DROP TABLE IF EXISTS Indice;
DROP TABLE IF EXISTS Scientifique;
DROP TABLE IF EXISTS Thematique;
DROP TABLE IF EXISTS Difficulte;
DROP TABLE IF EXISTS Sexe;
-- THEMATIQUE
CREATE TABLE Thematique(
id SERIAL PRIMARY KEY,
libelle varchar(128) NOT NULL UNIQUE
);
-- DIFFICULTE
CREATE TABLE Difficulte(
id SERIAL PRIMARY KEY,
libelle varchar(128) NOT NULL UNIQUE
);
-- SEXE
CREATE TABLE Sexe(
id SERIAL PRIMARY KEY,
libelle varchar(128) NOT NULL UNIQUE
);
-- SCIENTIFIQUE
CREATE TABLE Scientifique(
id SERIAL PRIMARY KEY,
nom varchar(128) NOT NULL,
prenom varchar(128) NOT NULL,
photo varchar(512) NOT NULL,
dateNaissance date NOT NULL,
descriptif text NOT NULL,
ratioTrouvee numeric(5,4),
idThematique integer REFERENCES Thematique(id),
idDifficulte integer REFERENCES Difficulte(id),
idSexe integer REFERENCES Sexe(id)
);
-- INDICE
CREATE TABLE Indice(
id SERIAL PRIMARY KEY,
libelle varchar(512) NOT NULL UNIQUE,
idScientifique integer REFERENCES Scientifique(id)
);
-- QUESTION
CREATE TABLE Question(
id SERIAL PRIMARY KEY,
question varchar(256) NOT NULL UNIQUE
);
-- REPONSE
CREATE TABLE Reponse(
id SERIAL PRIMARY KEY,
reponse varchar(255) NOT NULL,
idQuestion integer REFERENCES Question(id),
idScientifique integer REFERENCES Scientifique(id)
);
-- ADMIN
CREATE TABLE Admin(
id SERIAL PRIMARY KEY,
email varchar(255) NOT NULL UNIQUE,
password varchar(255) NOT NULL
);
-- JOUEUR
CREATE TABLE Joueur(
id SERIAL PRIMARY KEY,
pseudo varchar(255) NOT NULL UNIQUE
);
-- Invite
CREATE TABLE Invite(
idJoueur integer PRIMARY KEY REFERENCES Joueur(id),
idSession varchar(255) NOT NULL UNIQUE
);
-- Utilisateur
CREATE TABLE Utilisateur(
idJoueur integer PRIMARY KEY REFERENCES Joueur(id),
email varchar(255) NOT NULL UNIQUE,
password varchar(255) NOT NULL
);
-- Decouvrir
CREATE TABLE Decouvrir(
idUtilisateur integer REFERENCES Utilisateur(idJoueur),
idScientifique integer REFERENCES Scientifique(id),
PRIMARY KEY (idUtilisateur, idScientifique)
);
-- Jeu
CREATE TABLE Jeu(
id SERIAL PRIMARY KEY,
nom varchar(128) NOT NULL UNIQUE,
nbrParties integer NOT NULL DEFAULT 0
);
-- Partie
CREATE TABLE Partie(
id SERIAL PRIMARY KEY,
codeInvitation varchar(10) NOT NULL UNIQUE,
idJoueur integer REFERENCES Joueur(id),
idJeu integer REFERENCES Jeu(id)
);
-- INSERTS
INSERT INTO Jeu(nom) VALUES ('Qui-est-ce ?'),('Kahoot'), ('Pendu');
INSERT INTO Difficulte(libelle) VALUES ('Facile'),('Intermédiaire'),('Difficile');
INSERT INTO Sexe(libelle) VALUES ('Homme'),('Femme');
INSERT INTO Thematique(libelle) VALUES ('Nucléaire'),('Mathématiques');
INSERT INTO Scientifique(nom, prenom, photo, dateNaissance, descriptif, ratioTrouvee, idThematique, idDifficulte, idSexe)
VALUES
('nomToto', 'prenomToto', '', CURRENT_DATE, 'desc', 0, 1, 1, 1),
('nomTiti', 'prenomTiti', '', CURRENT_DATE, 'desc', 0, 2, 2, 2);
INSERT INTO Joueur(id,pseudo) VALUES (1337, 'moi, le meilleur joueur du monde');
INSERT INTO Utilisateur(idJoueur,email,password) VALUES (1337, 'joueur','$2y$10$juGnlWC9cS19popEKLZsYeir0Jl39k6hDl0dpaCix00FDcdiEbtmS');
-- mdp = test
INSERT INTO Admin(id,email,password) VALUES (1, 'admin','$2y$10$juGnlWC9cS19popEKLZsYeir0Jl39k6hDl0dpaCix00FDcdiEbtmS');
-- mdp = test

@ -11,27 +11,8 @@
'cache' => false, 'cache' => false,
]); ]);
$cont = new FrontController(); $dVueErreur = array();
$basePath = preg_replace('/\/index.php/i', '', $_SERVER['PHP_SELF']);
/*
try{
$con=new model\Connection($dsn,$login,$mdp);
$query = "SELECT * FROM categorie WHERE id=:id";
echo $con->executeQuery($query, array(':id' => array(1, PDO::PARAM_INT) ) );
$results=$con->getResults();
Foreach ($results as $row)
print $row['titre'];
$cont = new FrontController();
}
catch( PDOException $Exception ) {
echo 'erreur';
echo $Exception->getMessage();}
*/

@ -1,25 +0,0 @@
<?php
namespace model;
class ModelAdmin {
public static function isAdmin() {
if(!isset($_SESSION['admin'])
|| !$_SESSION['admin']
|| !isset($_SESSION['email'])
|| $_SESSION['email'] == null) {
return false;
}
return true;
}
public static function logout() {
global $basePath;
session_unset();
session_destroy();
$_SESSION = array();
header("Location: .");
}
}

@ -0,0 +1,24 @@
<?php
namespace model;
class IdSessionDoubleException extends \RuntimeException
{
private int $idJoueur;
private string $idSession;
public function __construct($idJoueur, $idSession)
{
parent::__construct();
$this->idJoueur=$idJoueur;
$this->idSession=$idSession;
}
public function getIdJoueur():int{
return $this->idJoueur;
}
public function getIdSession(): string{
return $this->idSession;
}
}

@ -1,6 +1,6 @@
<?php <?php
namespace controller; namespace model;
class LoginException extends \Exception class LoginException extends \Exception
{ {

@ -0,0 +1,8 @@
<?php
namespace model;
class PseudoDejaPrisException extends \RuntimeException
{
}

@ -0,0 +1,5 @@
<?php
namespace model;
class ValidationException extends \RuntimeException{
}

@ -5,31 +5,107 @@ namespace model;
class AdminGateway class AdminGateway
{ {
private \PDO $con; private \PDO $con;
private \PDOStatement $stmt;
public function __construct(\PDO $con) public function __construct(Connection $con)
{ {
$this->con=$con; $this->con=$con;
} }
public function login(string $username, string $password): bool public function login(string $email, string $password): bool
{
$sql = "SELECT * FROM Admin WHERE email=:email";
$this->con->executeQuery($sql, array(
':email' => array($email, \PDO::PARAM_STR)
));
$result = $this->con->getOneResult();
if (!empty($result)) {
return password_verify($password,$result['password']);
}
return false;
}
public function addUser(string $email, string $password): void
{
$sql = "INSERT INTO Admin (email, password) VALUES (:email, :password)";
$stmt = $this->con->prepare($sql);
$stmt->bindValue(':email', $email);
$stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT));
$stmt->execute();
}
public function deleteUser(int $id): void
{ {
$sql = "SELECT * FROM admin WHERE username=:username"; $sql = "DELETE FROM Admin WHERE id=:id";
$stmt = $this->con->prepare($sql); $stmt = $this->con->prepare($sql);
$stmt->bindValue(':username', $username); $stmt->bindValue(':id', $id);
$stmt->execute();
}
public function updateUser(int $id, string $email, string $password): void
{
$sql = "UPDATE Admin SET email=:email, password=:password WHERE id=:id";
$stmt = $this->con->prepare($sql);
$stmt->bindValue(':id', $id);
$stmt->bindValue(':email', $email);
$stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT));
$stmt->execute();
}
public function getUser(int $id): User
{
$sql = "SELECT * FROM Admin WHERE id=:id";
$stmt = $this->con->prepare($sql);
$stmt->bindValue(':id', $id);
$stmt->execute(); $stmt->execute();
$result = $stmt->fetch(); $result = $stmt->fetch();
if ($result && password_verify($password, $result['password'])) { return new User($result['id'], $result['email'], $result['password']);
return true;
} }
return false; public function getUsers(): array
{
$sql = "SELECT * FROM Admin";
$stmt = $this->con->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll();
$users = [];
foreach ($result as $user) {
$users[] = new User($user['id'], $user['email'], $user['password']);
}
return $users;
}
public function getHashedPasswordById(int $id): string
{
$sql = "SELECT password FROM Admin WHERE id=:id";
$stmt = $this->con->prepare($sql);
$stmt->bindValue(':id', $id);
$stmt->execute();
$result = $stmt->fetch();
return $result['password'];
} }
public function getHashedPassword(string $username): string public function getHashedPassword(int $email): string
{ {
$sql = "SELECT password FROM user WHERE username=:username"; $sql = "SELECT password FROM Admin WHERE email=:email";
$stmt = $this->con->prepare($sql); $stmt = $this->con->prepare($sql);
$stmt->bindValue(':username', $username); $stmt->bindValue(':email', $email);
$stmt->execute(); $stmt->execute();
$result = $stmt->fetch(); $result = $stmt->fetch();
return $result['password']; return $result['password'];
} }
public function getUserId(string $email): int
{
$sql = "SELECT id FROM Admin WHERE email=:email";
$stmt = $this->con->prepare($sql);
$stmt->bindValue(':email', $email);
$stmt->execute();
$result = $stmt->fetch();
return $result['id'];
}
public function getUserByEmailAndPassword(string $email, string $password): User
{
$sql = "SELECT * FROM Admin WHERE email=:email AND password=:password";
$stmt = $this->con->prepare($sql);
$stmt->bindValue(':email', $email);
$stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT));
$stmt->execute();
$result = $stmt->fetch();
return new User($result['id'], $result['email'], $result['password']);
}
} }

@ -33,7 +33,7 @@ class Connection extends PDO {
return $this->stmt->fetchall(); return $this->stmt->fetchall();
} }
public function getOneResult() : array { public function getOneResult() {
return $this->stmt->fetch(); return $this->stmt->fetch();
} }
} }

@ -0,0 +1,24 @@
<?php
namespace model;
class DifficulteGateway
{
private $con;
function __construct(Connection $con) {
$this->con = $con;
}
public function getAll() : array
{
$this->con->executeQuery("SELECT id, libelle FROM Difficulte;");
return $this->con->getResults();
}
public function getFromId(int $id): array
{
$this->con->executeQuery("SELECT id, libelle FROM Difficulte WHERE id=:id;",
[':id' => [$id, $this->con::PARAM_INT]]);
return $this->con->getOneResult();
}
}

@ -0,0 +1,38 @@
<?php
namespace model;
class InviteGateway extends JoueurGateway
{
function __construct(Connection $con) {
parent::__construct($con);
}
public function getFromIdSession($idSession): array|bool
{
$this->con->executeQuery("SELECT idJoueur, pseudo, idSession FROM Invite JOIN Joueur ON id=idJoueur WHERE idSession = :idSession;",
[":idSession" => [$idSession, $this->con::PARAM_STR]]);
return $this->con->getOneResult();
}
public function getFromId($id): array|bool
{
$this->con->executeQuery("SELECT idJoueur, pseudo, idSession FROM Invite JOIN Joueur ON id=idJoueur WHERE id = :id;",
[":id" => [$id, $this->con::PARAM_INT]]);
return $this->con->getOneResult();
}
public function insertInvite(string $pseudo, string $idSession): int{
$row = $this->getFromIdSession($idSession);
if($row != false){
throw new IdSessionDoubleException($row['idjoueur'], $row['idsession']);
}else{
$id = $this->insertJoueur($pseudo);
$this->con->executeQuery("INSERT INTO Invite(idJoueur, idSession) VALUES(:id, :idSession);",
[":id" => [$id, $this->con::PARAM_INT],
":idSession" => [$idSession, $this->con::PARAM_STR]]);
return $id;
}
}
}

@ -0,0 +1,26 @@
<?php
namespace model;
use PDO;
class JeuGateway
{
private $con;
function __construct(Connection $con) {
$this->con = $con;
}
public function getAll() : array
{
$this->con->executeQuery("SELECT id, nom, nbrparties FROM Jeu;");
return $this->con->getResults();
}
public function getFromId(int $id): array
{
$this->con->executeQuery("SELECT id, nom, nbrparties FROM Jeu WHERE id=:id;",
[':id' => [$id, $this->con::PARAM_INT]]);
return $this->con->getOneResult();
}
}

@ -0,0 +1,39 @@
<?php
namespace model;
abstract class JoueurGateway
{
protected $con;
function __construct(Connection $con) {
$this->con = $con;
}
protected function getFromPseudo($pseudo): array|bool
{
$this->con->executeQuery("SELECT id, pseudo FROM Joueur WHERE pseudo = :pseudo;",
[":pseudo" => [$pseudo, $this->con::PARAM_STR]]);
return $this->con->getOneResult();
}
protected function insertJoueur(string $pseudo): int{
if($this->getFromPseudo($pseudo) != false){
throw new PseudoDejaPrisException();
}else{
$this->con->executeQuery("INSERT INTO Joueur(pseudo) VALUES(:pseudo);",
[":pseudo" => [$pseudo, $this->con::PARAM_STR]]);
return $this->getFromPseudo($pseudo)["id"];
}
}
public function setPseudo(int $id, string $pseudo){
if($this->getFromPseudo($pseudo) != false){
throw new PseudoDejaPrisException();
}else{
$this->con->executeQuery("UPDATE Joueur SET pseudo=:pseudo WHERE id=:id",
[":pseudo" => [$pseudo, $this->con::PARAM_STR],
":id" => [$id, $this->con::PARAM_INT]]);
}
}
}

@ -0,0 +1,18 @@
<?php
namespace model;
class ScientifiqueGateway
{
private $con;
function __construct(Connection $con) {
$this->con = $con;
}
public function getRandom(): array|bool{
$this->con->executeQuery(
"SELECT id, nom, prenom, photo, dateNaissance, descriptif, ratiotrouvee, idthematique, iddifficulte, idsexe FROM Scientifique ORDER BY RANDOM() LIMIT 1;");
return $this->con->getOneResult();
}
}

@ -0,0 +1,19 @@
<?php
namespace model;
class SexeGateway
{
private $con;
function __construct(Connection $con) {
$this->con = $con;
}
public function getFromId(int $id): array
{
$this->con->executeQuery("SELECT id, libelle FROM Sexe WHERE id=:id;",
[':id' => [$id, $this->con::PARAM_INT]]);
return $this->con->getOneResult();
}
}

@ -0,0 +1,19 @@
<?php
namespace model;
class ThematiqueGateway
{
private $con;
function __construct(Connection $con) {
$this->con = $con;
}
public function getFromId(int $id): array
{
$this->con->executeQuery("SELECT id, libelle FROM Thematique WHERE id=:id;",
[':id' => [$id, $this->con::PARAM_INT]]);
return $this->con->getOneResult();
}
}

@ -4,98 +4,107 @@ namespace model;
class UserGateway class UserGateway
{ {
private \PDO $con; private Connection $con;
private \PDOStatement $stmt; private \PDOStatement $stmt;
public function __construct(Connection $con) public function __construct(Connection $con)
{ {
$this->con=$con; $this->con=$con;
} }
public function login(string $username, string $password): bool public function login(string $email, string $password): bool
{ {
$sql = "SELECT * FROM user WHERE username=:username"; $sql = "SELECT * FROM Utilisateur WHERE email=:email";
$this->con->executeQuery($sql, array( $this->con->executeQuery($sql, array(
':username' => array($username, \PDO::PARAM_STR) ':email' => array($email, \PDO::PARAM_STR)
)); ));
$result = $this->con->getOneResult(); $result = $this->con->getOneResult();
if (!empty($result) && md5($password) == $result['password']) { if (!empty($result)) {
return true; return password_verify($password,$result['password']);
} }
return false; return false;
} }
public function addUser(string $username, string $password): void public function addUser(string $email, string $password): void
{ {
$sql = "INSERT INTO user (username, password) VALUES (:username, :password)"; $sql = "INSERT INTO utilisateur (email, password) VALUES (:email, :password)";
$stmt = $this->con->prepare($sql); $stmt = $this->con->prepare($sql);
$stmt->bindValue(':username', $username); $stmt->bindValue(':email', $email);
$stmt->bindValue(':password', password_hash($password, 'md5')); $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT));
$stmt->execute(); $stmt->execute();
} }
public function deleteUser(int $id): void public function deleteUser(int $id): void
{ {
$sql = "DELETE FROM user WHERE id=:id"; $sql = "DELETE FROM utilisateur WHERE id=:id";
$stmt = $this->con->prepare($sql); $stmt = $this->con->prepare($sql);
$stmt->bindValue(':id', $id); $stmt->bindValue(':id', $id);
$stmt->execute(); $stmt->execute();
} }
public function updateUser(int $id, string $username, string $password): void public function updateUser(int $id, string $email, string $password): void
{ {
$sql = "UPDATE user SET username=:username, password=:password WHERE id=:id"; $sql = "UPDATE utilisateur SET email=:email, password=:password WHERE id=:id";
$stmt = $this->con->prepare($sql); $stmt = $this->con->prepare($sql);
$stmt->bindValue(':id', $id); $stmt->bindValue(':id', $id);
$stmt->bindValue(':username', $username); $stmt->bindValue(':email', $email);
$stmt->bindValue(':password', $password); $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT));
$stmt->execute(); $stmt->execute();
} }
public function getUser(int $id): User public function getUser(int $id): User
{ {
$sql = "SELECT * FROM user WHERE id=:id"; $sql = "SELECT * FROM utilisateur WHERE id=:id";
$stmt = $this->con->prepare($sql); $stmt = $this->con->prepare($sql);
$stmt->bindValue(':id', $id); $stmt->bindValue(':id', $id);
$stmt->execute(); $stmt->execute();
$result = $stmt->fetch(); $result = $stmt->fetch();
return new User($result['id'], $result['username'], $result['password']); return new User($result['id'], $result['email'], $result['password']);
} }
public function getUsers(): array public function getUsers(): array
{ {
$sql = "SELECT * FROM user"; $sql = "SELECT * FROM utilisateur";
$stmt = $this->con->prepare($sql); $stmt = $this->con->prepare($sql);
$stmt->execute(); $stmt->execute();
$result = $stmt->fetchAll(); $result = $stmt->fetchAll();
$users = []; $users = [];
foreach ($result as $user) { foreach ($result as $user) {
$users[] = new User($user['id'], $user['username'], $user['password']); $users[] = new User($user['id'], $user['email'], $user['password']);
} }
return $users; return $users;
} }
public function getHashedPasswordById(int $id): string public function getHashedPasswordById(int $id): string
{ {
$sql = "SELECT password FROM user WHERE id=:id"; $sql = "SELECT password FROM utilisateur WHERE id=:id";
$stmt = $this->con->prepare($sql); $stmt = $this->con->prepare($sql);
$stmt->bindValue(':id', $id); $stmt->bindValue(':id', $id);
$stmt->execute(); $stmt->execute();
$result = $stmt->fetch(); $result = $stmt->fetch();
return $result['password']; return $result['password'];
} }
public function getUserId(string $username): int public function getHashedPassword(int $email): string
{ {
$sql = "SELECT id FROM user WHERE username=:username"; $sql = "SELECT password FROM utilisateur WHERE email=:email";
$stmt = $this->con->prepare($sql); $stmt = $this->con->prepare($sql);
$stmt->bindValue(':username', $username); $stmt->bindValue(':email', $email);
$stmt->execute();
$result = $stmt->fetch();
return $result['password'];
}
public function getUserId(string $email): int
{
$sql = "SELECT id FROM utilisateur WHERE email=:email";
$stmt = $this->con->prepare($sql);
$stmt->bindValue(':email', $email);
$stmt->execute(); $stmt->execute();
$result = $stmt->fetch(); $result = $stmt->fetch();
return $result['id']; return $result['id'];
} }
public function getUserByUsernameAndPassword(string $username, string $password): User public function getUserByEmailAndPassword(string $email, string $password): User
{ {
$sql = "SELECT * FROM user WHERE username=:username AND password=:password"; $sql = "SELECT * FROM utilisateur WHERE email=:email AND password=:password";
$stmt = $this->con->prepare($sql); $stmt = $this->con->prepare($sql);
$stmt->bindValue(':username', $username); $stmt->bindValue(':email', $email);
$stmt->bindValue(':password', $password); $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT));
$stmt->execute(); $stmt->execute();
$result = $stmt->fetch(); $result = $stmt->fetch();
return new User($result['id'], $result['username'], $result['password']); return new User($result['id'], $result['email'], $result['password']);
} }
} }

@ -0,0 +1,50 @@
<?php
namespace model;
class MdlAdmin extends MdlBase{
private AdminGateway $gw;
public function __construct(){
parent::__construct();
$this->gw = new AdminGateway($this->con);
}
public function login(string $username, string $password): bool{
return $this->gw->login($username, $password);
}
public static function isAdmin() {
if(!isset($_SESSION['admin'])
|| !$_SESSION['admin']
|| !isset($_SESSION['email'])
|| $_SESSION['email'] == null) {
return false;
}
return true;
}
public static function logout() {
global $basePath;
session_unset();
session_destroy();
$_SESSION = array();
header("Location: .");
}
/*
public function setPseudo(int $id, string $pseudo): User{
$this->gw->setPseudo($id, $pseudo);
return $this->getFromId($id);
}
public function insertInvite(string $pseudo, string $idSession): User{
$id = $this->gw->insertInvite($pseudo, $idSession);
return $this->getFromId($id);
}
public function getFromId(int $id): User{
$row = $this->gw->getFromId($id);
return new Invite($row['idjoueur'], $row['pseudo'], $row['idsession']);
}*/
}

@ -0,0 +1,13 @@
<?php
namespace model;
abstract class MdlBase{
protected Connection $con;
public function __construct()
{
global $config;
$this->con = new Connection($config["db"]["dsn"], $config["db"]["login"], $config["db"]["mdp"]);
}
}

@ -0,0 +1,25 @@
<?php
namespace model;
class MdlDifficulte extends MdlBase{
private DifficulteGateway $gw;
public function __construct(){
parent::__construct();
$this->gw = new DifficulteGateway($this->con);
}
public function getAll(): array{
$listDifficulte = [];
foreach($this->gw->getAll() as $row){
$listDifficulte[] = new Difficulte($row['id'], $row['libelle']);
}
return $listDifficulte;
}
public function getFromId(int $id): Difficulte{
$row = $this->gw->getFromId($id);
return new Difficulte($row['id'], $row['libelle']);
}
}

@ -0,0 +1,27 @@
<?php
namespace model;
class MdlInvite extends MdlBase{
private InviteGateway $gw;
public function __construct(){
parent::__construct();
$this->gw = new InviteGateway($this->con);
}
public function setPseudo(int $id, string $pseudo): Invite{
$this->gw->setPseudo($id, $pseudo);
return $this->getFromId($id);
}
public function insertInvite(string $pseudo, string $idSession): Invite{
$id = $this->gw->insertInvite($pseudo, $idSession);
return $this->getFromId($id);
}
public function getFromId(int $id): Invite{
$row = $this->gw->getFromId($id);
return new Invite($row['idjoueur'], $row['pseudo'], $row['idsession']);
}
}

@ -0,0 +1,25 @@
<?php
namespace model;
class MdlJeu extends MdlBase{
private JeuGateway $gw;
public function __construct(){
parent::__construct();
$this->gw = new JeuGateway($this->con);
}
public function getAll(): array{
$listJeu = [];
foreach($this->gw->getAll() as $row){
$listJeu[] = new Jeu($row['id'], $row['nom'], $row['nbrparties']);
}
return $listJeu;
}
public function getFromId(int $id): Jeu{
$row = $this->gw->getFromId($id);
return new Jeu($row['id'], $row['nom'], $row['nbrparties']);
}
}

@ -0,0 +1,85 @@
<?php
namespace model;
class MdlPendu{
private Scientifique $scientifiqueATrouver;
private string $aTrouver;
private int $nbFail;
private int $nbTours;
private array $lettreExceptees;
private array $lettreUtilisees;
private static $nbFailsMax = 8;
public function __construct(Scientifique $scientifiqueATrouver){
$this->scientifiqueATrouver = $scientifiqueATrouver;
$this->aTrouver = strtr($scientifiqueATrouver->getPrenom()." ".$scientifiqueATrouver->getNom(), 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy'); #suppression des accents
$this->nbFail = 0;
$this->nbTours = 0;
$this->lettreExceptees = [' ', '-'];
$this->lettreUtilisees = [];
}
public function jouerLettre(string $lettre): string{
$lettre = strtolower($lettre);
if(strlen($lettre) != 1){ throw new ValidationException("Veuillez fournir une seule lettre");}
if(!ctype_alpha($lettre)){ throw new ValidationException("Veuillez fournir une caractère alphabétique");}
if(in_array($lettre, $this->lettreUtilisees)){ throw new ValidationException("Vous avez déjà joué cette lettre");}
$this->nbTours += 1;
if(!str_contains($this->aTrouver, $lettre)){
$this->nbFail += 1;
}
$this->lettreUtilisees[] = $lettre;
return $this->getDecouvert();
}
public function getScientifique(): Scientifique
{
return $this->scientifiqueATrouver;
}
public function getLettreUtilisees(): array{
return $this->lettreUtilisees;
}
public function getATrouver(): string
{
return $this->aTrouver;
}
public function getDecouvert(): string
{
$decouvert = '';
foreach(str_split($this->aTrouver) as $lettre){
if(in_array(strtolower($lettre), $this->lettreUtilisees) || in_array(strtolower($lettre), $this->lettreExceptees)){
$decouvert.=$lettre;
}else{
$decouvert.="_";
}
}
return $decouvert;
}
public function getNbTours():int{
return $this->nbTours;
}
public function getNbFails():int{
return $this->nbFail;
}
public function getEssaisRestant():int{
return $this::$nbFailsMax - $this->nbFail;
}
public function aGagne(): bool{
return $this->getDecouvert() == $this->getATrouver();
}
public function aPerdu(): bool{
return $this->getEssaisRestant() <= 0;
}
}

@ -0,0 +1,40 @@
<?php
namespace model;
use DateTime;
use RuntimeException;
class MdlScientifique extends MdlBase{
private ScientifiqueGateway $gw;
private MdlSexe $mdlSexe;
private MdlDifficulte $mdlDifficulte;
private MdlThematique $mdlThematique;
public function __construct(){
parent::__construct();
$this->gw = new ScientifiqueGateway($this->con);
$this->mdlSexe = new MdlSexe();
$this->mdlDifficulte = new MdlDifficulte();
$this->mdlThematique = new MdlThematique();
}
public function getRandom(): Scientifique{
$row = $this->gw->getRandom();
if($row == false) throw new RuntimeException("Erreur aucun scientifique trouvé");
$sexe = $this->mdlSexe->getFromId($row['idsexe']);
$difficulte = $this->mdlDifficulte->getFromId($row['iddifficulte']);
$thematique = $this->mdlThematique->getFromId($row['idthematique']);
return new Scientifique($row['id'],
$row['nom'],
$row['prenom'],
$row['photo'],
new DateTime($row['datenaissance']),
$row['descriptif'],
$row['ratiotrouvee'],
$thematique,
$difficulte,
$sexe);
}
}

@ -0,0 +1,17 @@
<?php
namespace model;
class MdlSexe extends MdlBase{
private SexeGateway $gw;
public function __construct(){
parent::__construct();
$this->gw = new SexeGateway($this->con);
}
public function getFromId(int $id): Sexe{
$row = $this->gw->getFromId($id);
return new Sexe($row['id'], $row['libelle']);
}
}

@ -0,0 +1,17 @@
<?php
namespace model;
class MdlThematique extends MdlBase{
private ThematiqueGateway $gw;
public function __construct(){
parent::__construct();
$this->gw = new ThematiqueGateway($this->con);
}
public function getFromId(int $id): Thematique{
$row = $this->gw->getFromId($id);
return new Thematique($row['id'], $row['libelle']);
}
}

@ -0,0 +1,30 @@
<?php
namespace model;
class MdlUser extends MdlBase{
private UserGateway $gw;
public function __construct(){
parent::__construct();
$this->gw = new UserGateway($this->con);
}
public function login(string $username, string $password): bool{
return $this->gw->login($username, $password);
}
/*
public function setPseudo(int $id, string $pseudo): User{
$this->gw->setPseudo($id, $pseudo);
return $this->getFromId($id);
}
public function insertInvite(string $pseudo, string $idSession): User{
$id = $this->gw->insertInvite($pseudo, $idSession);
return $this->getFromId($id);
}
public function getFromId(int $id): User{
$row = $this->gw->getFromId($id);
return new Invite($row['idjoueur'], $row['pseudo'], $row['idsession']);
}*/
}

@ -0,0 +1,21 @@
<?php
namespace model;
class ConfigurationJeu{
private Difficulte $difficulte;
private Jeu $jeu;
public function __construct(Jeu $jeu, Difficulte $difficulte){
$this->jeu = $jeu;
$this->difficulte = $difficulte;
}
public function getDifficulte(): Difficulte{
return $this->difficulte;
}
public function getJeu(): Jeu{
return $this->jeu;
}
}

@ -0,0 +1,33 @@
<?php
namespace model;
class Difficulte
{
private int $id;
private string $libelle;
/**
* @param int $id
* @param string $libelle
*/
public function __construct(int $id, string $libelle)
{
$this->id=$id;
$this->libelle=$libelle;
}
/**
* @return int
*/
public function getId(): int{
return $this->id;
}
/**
* @return string
*/
public function getLibelle(): string{
return $this->libelle;
}
}

@ -0,0 +1,18 @@
<?php
namespace model;
class Invite extends Joueur{
private string $idSession;
public function __construct(int $id, string $pseudo, string $idSession)
{
parent::__construct($id,$pseudo);
$this->idSession = $idSession;
}
public function getIdSession(): string
{
return $this->idSession;
}
}

@ -0,0 +1,51 @@
<?php
namespace model;
class Jeu
{
private int $id;
private string $nom;
private int $nbrParties;
/**
* @param int $id
* @param string $nom
* @param string $nbParties
*/
public function __construct(int $id, string $nom, int $nbrParties)
{
$this->id=$id;
$this->nom=$nom;
$this->nbrParties=$nbrParties;
}
/**
* @return int
*/
public function getId(): int{
return $this->id;
}
/**
* @return string
*/
public function getNom(): string{
return $this->nom;
}
/**
* @return int
*/
public function getNbParties():int{
return $this->nbrParties;
}
/**
* @return int
*/
public function incrementNbParties(): int{
$this->nbrParties += 1;
return $this->nbrParties;
}
}

@ -0,0 +1,24 @@
<?php
namespace model;
abstract class Joueur{
private int $id;
private string $pseudo;
public function __construct(int $id, string $pseudo){
$this->id=$id;
$this->pseudo=$pseudo;
}
public function getId(): int
{
return $this->id;
}
public function getPseudo(): String
{
return $this->pseudo;
}
}

@ -0,0 +1,132 @@
<?php
namespace model;
use DateTime;
class Scientifique
{
private int $id;
private string $nom;
private string $prenom;
private string $photo;
private DateTime $dateNaiss;
private string $descriptif;
private float $ratioTrouvee;
private Thematique $thematique;
private Difficulte $difficulte;
private Sexe $sexe;
/**
* @param int $id
* @param string $nom
* @param string $prenom
* @param string $photo
* @param string $descriptif
* @param Thematique $thematique
* @param Difficulte $difficulte
* @param Sexe $sexe
*/
public function __construct(int $id,
string $nom,
string $prenom,
string $photo,
DateTime $dateNaiss,
string $descriptif,
float $ratioTrouvee,
Thematique $thematique,
Difficulte $difficulte,
Sexe $sexe)
{
$this->id = $id;
$this->nom = $nom;
$this->prenom = $prenom;
$this->photo = $photo;
$this->ratioTrouvee = $ratioTrouvee;
$this->descriptif = $descriptif;
$this->dateNaiss = $dateNaiss;
$this->thematique = $thematique;
$this->difficulte = $difficulte;
$this->sexe = $sexe;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return string
*/
public function getNom(): string
{
return $this->nom;
}
/**
* @return string
*/
public function getPrenom(): string
{
return $this->prenom;
}
/**
* @return string
*/
public function getPhoto(): string
{
return $this->photo;
}
/**
* @return string
*/
public function getDescriptif(): string
{
return $this->descriptif;
}
/**
* @return DateTime
*/
public function getDateNaiss(): DateTime
{
return $this->dateNaiss;
}
/**
* @return float
*/
public function getRatioTrouvee(): float
{
return $this->ratioTrouvee;
}
/**
* @return Thematique
*/
public function getThematique(): Thematique
{
return $this->thematique;
}
/**
* @return Difficulte
*/
public function getDifficulte(): Difficulte
{
return $this->difficulte;
}
/**
* @return Sexe
*/
public function getSexe(): Sexe
{
return $this->sexe;
}
}

@ -0,0 +1,25 @@
<?php
namespace model;
class Sexe
{
private int $id;
private string $libelle;
public function __construct(int $id, string $libelle)
{
$this->id=$id;
$this->libelle=$libelle;
}
public function getId():int
{
return $this->id;
}
public function getLibelle(): string
{
return $this->libelle;
}
}

@ -0,0 +1,25 @@
<?php
namespace model;
class Thematique
{
private int $id;
private string $libelle;
public function __construct(int $id, string $libelle)
{
$this->id=$id;
$this->libelle=$libelle;
}
public function getId():int
{
return $this->id;
}
public function getLibelle(): string
{
return $this->libelle;
}
}

@ -0,0 +1,25 @@
<?php
namespace model;
class Utilisateur extends Joueur{
private string $email;
private string $motDePasse; #hash du mot de passe
public function __construct(int $id, string $pseudo, string $email, string $motDePasse)
{
parent::__construct($id,$pseudo);
$this->email = $email;
$this->motDePasse = $motDePasse;
}
public function getEmail(): string
{
return $this->email;
}
public function getMotDePasse(): string
{
return $this->motDePasse;
}
}

@ -14,9 +14,14 @@
<body> <body>
<h1>Bienvenue sur Mini-Jeux</h1> <h1>Bienvenue sur Mini-Jeux</h1>
{% if dVue.info is defined %} <!--TODO A DEPLACER DANS SA PROPRE VUE-->
<p>{{dVue.info}}</p> {% if dVue.nomJeu is defined %}
<p>Jeu selectionné : {{dVue.nomJeu}}</p>
{% endif %} {% endif %}
{% if dVue.libelleDifficulte is defined %}
<p>Difficulte selectionné : {{dVue.libelleDifficulte}}</p>
{% endif %}
<!--FIN TODO-->
{% if dVue.pseudo is defined %} {% if dVue.pseudo is defined %}
<p align="right"><a href="logout">{{dVue.pseudo}}</a></p> <p align="right"><a href="logout">{{dVue.pseudo}}</a></p>
@ -26,8 +31,8 @@
<br><br><br><br> <br><br><br><br>
<center> <center>
<a href="JoinParty">Rejoindre une partie</a> <a href="joinParty">Rejoindre une partie</a>
<a href="CreateParty">Créer une partie</a> <a href="createParty">Créer une partie</a>
</center> </center>

@ -27,19 +27,37 @@
<form action="validationFormulaire" method="post"> <form action="validationFormulaire" method="post">
<fieldset> <fieldset>
<legend>Mini-jeux disponibles</legend> <legend>Mini-jeux disponibles</legend>
{% if dVueErreur|length > 0 %}
<div>
<h5>Erreur : </h5>
{% for erreur in dVueErreur %}
<p>{{erreur}}</p>
{% endfor %}
</div>
{% endif %}
{% if dVueCreate is defined %} {% if dVueCreate is defined %}
{% for value in dVueCreate %} {% if dVueCreate["jeux"] is defined %}
{% for value in dVueCreate["jeux"] %}
<div> <div>
<input type="radio" name="game" id="{{value[0]}}" value="{{value[0]}}"> <input required type="radio" name="jeu" id="{{value['id']}}" value="{{value['id']}}">
<label for="{{value[0]}}">{{value[0]}}</label> <label for="{{value['id']}}">{{value['nom']}}</label>
</div> </div>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</fieldset> </fieldset>
<label for="difficulty">Difficulté</label> {% if dVueCreate["difficultes"] is defined %}
<input type="number" name="difficulty" id="difficulty"> <label for="difficulte">Difficulté</label>
<select required name="difficulte" id="difficulte">
{% for diff in dVueCreate["difficultes"] %}
<option value="{{diff['id']}}">{{diff['libelle']}}</option>
{% endfor %}
</select>
{% endif %}
<input type="submit" value="Valider"> <input type="submit" value="Valider">
{% endif %}
</form> </form>
</center> </center>

@ -11,8 +11,8 @@
<center> <center>
<p>Merci de vous munir de votre code de partie et de l'entrer dans le champ ci-dessous</p> <p>Merci de vous munir de votre code de partie et de l'entrer dans le champ ci-dessous</p>
<form action="#" method="post"> <form action="#" method="post">
<label for="partyCode">Code de la partie</label> <label for="codeInvitation">Code de la partie</label>
<input type="text" name="code" id="partyCode"> <input type="text" name="codeInvitation" id="codeInvitation">
<input type="submit" value="Valider"> <input type="submit" value="Valider">
</form> </form>
<div> <div>

@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Pendu</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
p,
label {
font:
1rem 'Fira Sans',
sans-serif;
}
input {
margin: 0.4rem;
}
</style>
</head>
<body>
<br><br><br>
<center>
<p></p>
<form action="" method="post">
<fieldset>
{% if dVue.decouvert is defined %}
<div>
<h1>
{{dVue.decouvert}}
</h1>
</div>
<br>
{% endif %}
{% if dVue.essaisRestant is defined %}
<p>Il vous reste {{dVue.essaisRestant}} essais</p>
{% endif %}
{% if dVue.lettresUtilisees is defined %}
<h5>Lettres utilisées</h5>
<div>
{%for lettre in dVue.lettresUtilisees %}
{{lettre}}&nbsp;
{% endfor %}
</div>
{% endif %}
<legend>Votre lettre</legend>
{% if dVueErreur|length > 0 %}
<div>
<h5>Erreur : </h5>
{% for erreur in dVueErreur %}
<p>{{erreur}}</p>
{% endfor %}
</div>
{% endif %}
<div>
<input required type="text" name="lettre">
</div>
</fieldset>
<input type="submit" value="Valider">
</form>
</center>
<script src="js/bootstrap.min.js"></script>
</body>
</html>

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Pendu - Score</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
p,
label {
font:
1rem 'Fira Sans',
sans-serif;
}
input {
margin: 0.4rem;
}
</style>
</head>
<body>
<br><br><br>
<center>
{% if dVue.messageScore is defined %}
<h1>{{dVue.messageScore}}</h1>
{% endif %}
{% if dVue.nbTours is defined and dVue.nbFails is defined %}
<p>Vous avez fais {{dVue.nbTours}} essais et {{dVue.nbFails}} erreur(s)</p>
{% endif %}
{% if dVue.scientifique is defined %}
<h2>Le scientifique a trouvé été {{dVue.scientifique.prenom}} {{dVue.scientifique.nom}}</h2>
<div>
<h3>Voici quelques informations à son sujet</h3>
<p>Né(e) le : {{dVue.scientifique.dateNaiss}}</p>
<p>Sexe : {{dVue.scientifique.sexe}}</p>
<p>Domaine : {{dVue.scientifique.thematique}}</p>
<p>{{dVue.scientifique.descriptif}}</p>
</div>
{% endif %}
<a href=".">Retour à l'accueil</a>
</center>
<script src="js/bootstrap.min.js"></script>
</body>
</html>

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Saisir Pseudo</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
p,
label {
font:
1rem 'Fira Sans',
sans-serif;
}
input {
margin: 0.4rem;
}
</style>
</head>
<body>
<br><br><br>
<center>
<p></p>
<form action="" method="post">
<fieldset>
<legend>Veuillez choisir votre pseudo</legend>
{% if dVueErreur|length > 0 %}
<div>
<h5>Erreur : </h5>
{% for erreur in dVueErreur %}
<p>{{erreur}}</p>
{% endfor %}
</div>
{% endif %}
<div>
<input required type="text" name="pseudo" id="txt_pseudo">
</div>
</fieldset>
<input type="submit" value="Valider">
</form>
</center>
<script src="js/bootstrap.min.js"></script>
</body>
</html>

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit6539a3b2ab32d0f1df8933f4838b0c34::getLoader(); return ComposerAutoloaderInit8ac61264e1d011c0b663d8c3dbdfc99f::getLoader();

@ -6,7 +6,7 @@ $vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
'model\\' => array($baseDir . '/model', $baseDir . '/model/gateways', $baseDir . '/model/metier'), 'model\\' => array($baseDir . '/model', $baseDir . '/model/mdl', $baseDir . '/model/gateways', $baseDir . '/model/metier', $baseDir . '/model/exception'),
'controller\\' => array($baseDir . '/controller'), 'controller\\' => array($baseDir . '/controller'),
'config\\' => array($baseDir . '/config'), 'config\\' => array($baseDir . '/config'),
'Twig\\' => array($vendorDir . '/twig/twig/src'), 'Twig\\' => array($vendorDir . '/twig/twig/src'),

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInit6539a3b2ab32d0f1df8933f4838b0c34 class ComposerAutoloaderInit8ac61264e1d011c0b663d8c3dbdfc99f
{ {
private static $loader; private static $loader;
@ -24,16 +24,16 @@ class ComposerAutoloaderInit6539a3b2ab32d0f1df8933f4838b0c34
require __DIR__ . '/platform_check.php'; require __DIR__ . '/platform_check.php';
spl_autoload_register(array('ComposerAutoloaderInit6539a3b2ab32d0f1df8933f4838b0c34', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInit8ac61264e1d011c0b663d8c3dbdfc99f', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit6539a3b2ab32d0f1df8933f4838b0c34', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInit8ac61264e1d011c0b663d8c3dbdfc99f', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php'; require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f::getInitializer($loader));
$loader->register(true); $loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34::$files; $filesToLoad = \Composer\Autoload\ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) { $requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34 class ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f
{ {
public static $files = array ( public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', '320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
@ -36,8 +36,10 @@ class ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34
'model\\' => 'model\\' =>
array ( array (
0 => __DIR__ . '/../..' . '/model', 0 => __DIR__ . '/../..' . '/model',
1 => __DIR__ . '/../..' . '/model/gateways', 1 => __DIR__ . '/../..' . '/model/mdl',
2 => __DIR__ . '/../..' . '/model/metier', 2 => __DIR__ . '/../..' . '/model/gateways',
3 => __DIR__ . '/../..' . '/model/metier',
4 => __DIR__ . '/../..' . '/model/exception',
), ),
'controller\\' => 'controller\\' =>
array ( array (
@ -69,9 +71,9 @@ class ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34::$classMap; $loader->classMap = ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }

@ -234,6 +234,59 @@
], ],
"install-path": "../symfony/polyfill-mbstring" "install-path": "../symfony/polyfill-mbstring"
}, },
{
"name": "twbs/bootstrap",
"version": "v5.3.2",
"version_normalized": "5.3.2.0",
"source": {
"type": "git",
"url": "https://github.com/twbs/bootstrap.git",
"reference": "344e912d04b5b6a04482113eff20ab416ff01048"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twbs/bootstrap/zipball/344e912d04b5b6a04482113eff20ab416ff01048",
"reference": "344e912d04b5b6a04482113eff20ab416ff01048",
"shasum": ""
},
"replace": {
"twitter/bootstrap": "self.version"
},
"time": "2023-09-14T14:19:27+00:00",
"type": "library",
"installation-source": "dist",
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Otto",
"email": "markdotto@gmail.com"
},
{
"name": "Jacob Thornton",
"email": "jacobthornton@gmail.com"
}
],
"description": "The most popular front-end framework for developing responsive, mobile first projects on the web.",
"homepage": "https://getbootstrap.com/",
"keywords": [
"JS",
"css",
"framework",
"front-end",
"mobile-first",
"responsive",
"sass",
"web"
],
"support": {
"issues": "https://github.com/twbs/bootstrap/issues",
"source": "https://github.com/twbs/bootstrap/tree/v5.3.2"
},
"install-path": "../twbs/bootstrap"
},
{ {
"name": "twig/twig", "name": "twig/twig",
"version": "v3.7.1", "version": "v3.7.1",

@ -3,7 +3,7 @@
'name' => '__root__', 'name' => '__root__',
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => 'b73e92d0b63a25bee137d61b716ec77ce0da68b8', 'reference' => '4faf5aeca4c05c9018b964ff1861f0cf14a736b4',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -13,7 +13,7 @@
'__root__' => array( '__root__' => array(
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => 'b73e92d0b63a25bee137d61b716ec77ce0da68b8', 'reference' => '4faf5aeca4c05c9018b964ff1861f0cf14a736b4',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -46,6 +46,15 @@
'aliases' => array(), 'aliases' => array(),
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'twbs/bootstrap' => array(
'pretty_version' => 'v5.3.2',
'version' => '5.3.2.0',
'reference' => '344e912d04b5b6a04482113eff20ab416ff01048',
'type' => 'library',
'install_path' => __DIR__ . '/../twbs/bootstrap',
'aliases' => array(),
'dev_requirement' => false,
),
'twig/twig' => array( 'twig/twig' => array(
'pretty_version' => 'v3.7.1', 'pretty_version' => 'v3.7.1',
'version' => '3.7.1.0', 'version' => '3.7.1.0',
@ -55,5 +64,11 @@
'aliases' => array(), 'aliases' => array(),
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'twitter/bootstrap' => array(
'dev_requirement' => false,
'replaced' => array(
0 => 'v5.3.2',
),
),
), ),
); );

@ -1 +0,0 @@
Subproject commit ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb

@ -1 +0,0 @@
Subproject commit 42292d99c55abe617799667f454222c54c60e229

@ -1 +0,0 @@
Subproject commit a0ce373a0ca3bf6c64b9e3e2124aca502ba39554
Loading…
Cancel
Save