Merge remote-tracking branch 'origin/php' into php

pull/7/head
Tom 1 year ago
commit c6d1570ea7

@ -31,21 +31,37 @@ class AdminController {
$sexe = new MdlSexe(); $sexe = new MdlSexe();
$theme = new MdlThematique(); $theme = new MdlThematique();
$diff = new MdlDifficulte(); $diff = new MdlDifficulte();
$scient=null;
if(!empty($_POST)){ if(!empty($_POST)){
$sci=new MdlScientifique(); $id=0;
$sci->addScientifique(new Scientifique(0, if(isset($_GET["id"])){
$id=intval($_GET["id"]);
}
$sci = new Scientifique(
$id,
$_POST["name"], $_POST["name"],
$_POST["prenom"], $_POST["prenom"],
$_POST["url"], $_POST["url"],
\DateTime::createFromFormat("Y-m-d",$_POST["date"]), \DateTime::createFromFormat("Y-m-d", $_POST["date"]),
$_POST["description"], $_POST["description"],
0, 0,
$theme->getFromId(intval($_POST["theme"])), $theme->getFromId(intval($_POST["theme"])),
$diff->getFromId(intval($_POST["difficulte"])), $diff->getFromId(intval($_POST["difficulte"])),
$sexe->getFromId(intval($_POST["sexe"])) $sexe->getFromId(intval($_POST["sexe"]))
)); );
$mdlsci=new MdlScientifique();
if(isset($_GET["id"])){
$mdlsci->editScientifique($sci);
} else {
$mdlsci->addScientifique($sci);
}
} }
echo $twig->render('admin/ajouterScientifiques.html',['sexe' => $sexe->getAll(), 'themes' => $theme->getAll(), 'difficultes' => $diff->getAll()]); if(isset($_GET["id"])){
$scient=new MdlScientifique();
$scient=$scient->getScientifique($_GET["id"]);
}
echo $twig->render('admin/ajouterScientifiques.html',['sexe' => $sexe->getAll(), 'themes' => $theme->getAll(), 'difficultes' => $diff->getAll(), 'scientifique' => $scient]);
break; break;
//mauvaise action //mauvaise action
default: default:
@ -59,6 +75,9 @@ class AdminController {
} catch (\Exception $e2) { } catch (\Exception $e2) {
$dVueErreur[] = 'Erreur inattendue !'; $dVueErreur[] = 'Erreur inattendue !';
echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]);
} catch (\Throwable $e2) {
$dVueErreur[] = 'Erreur !';
echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]);
} }
} }
} }

@ -67,17 +67,17 @@ class UserController {
public function login() { public function login() {
global $twig; global $twig;
if($_SERVER['REQUEST_METHOD'] === 'POST'){ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Validation::valUserLogin($_REQUEST['login'], $dVueErreur); Validation::valUserLogin($_REQUEST['login'], $dVueErreur);
$ug = new MdlUser(); $ug = new MdlUser();
if($ug->login($_REQUEST['login'], $_REQUEST['password'])) { if ($ug->login($_REQUEST['login'], $_REQUEST['password'])) {
$_SESSION['pseudo'] = $_REQUEST['login']; $_SESSION['pseudo'] = $_REQUEST['login'];
$_SESSION['isLogged'] = true; $_SESSION['isLogged'] = true;
header("Location: ."); header("Location: .");
} else { } else {
//voir si c'est un admin //voir si c'est un admin
$ug = new MdlAdmin(); $ug = new MdlAdmin();
if($ug->login($_REQUEST['login'], $_REQUEST['password'])) { if ($ug->login($_REQUEST['login'], $_REQUEST['password'])) {
$_SESSION['pseudo'] = $_REQUEST['login']; $_SESSION['pseudo'] = $_REQUEST['login'];
$_SESSION['isAdmin'] = true; $_SESSION['isAdmin'] = true;
$_SESSION['isLogged'] = true; $_SESSION['isLogged'] = true;
@ -92,6 +92,11 @@ class UserController {
} }
} }
public function logout(){
$_SESSION=[];
header("Location: .");
}
public function createParty(array $params) : void public function createParty(array $params) : void
{ {
global $twig; global $twig;

@ -41,4 +41,36 @@ class ScientifiqueGateway
":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR] ":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR]
]); ]);
} }
public function editScientifique(Scientifique $sci): bool{
return $this->con->executeQuery(
"UPDATE Scientifique SET nom = :nom, prenom = :prenom, photo = :photo, dateNaissance = :dateNaissance, descriptif = :descriptif, ratioTrouvee = :ratioTrouvee, idThematique = :idThematique, idDifficulte = :idDifficulte, idSexe = :idSexe WHERE id=:id;"
,[
":nom"=>[$sci->getNom(),$this->con::PARAM_STR],
":prenom"=>[$sci->getPrenom(),$this->con::PARAM_STR],
":photo"=>[$sci->getPhoto(),$this->con::PARAM_STR],
":dateNaissance"=>[date("Y-m-d H:i:s", $sci->getDateNaiss()->getTimestamp()),$this->con::PARAM_STR],
":descriptif"=>[$sci->getDescriptif(),$this->con::PARAM_STR],
":ratioTrouvee"=>[$sci->getRatioTrouvee(),$this->con::PARAM_STR],
":idThematique"=>[$sci->getThematique()->getId(),$this->con::PARAM_STR],
":idDifficulte"=>[$sci->getDifficulte()->getId(),$this->con::PARAM_STR],
":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR],
":id"=>[$sci->getId(),$this->con::PARAM_INT]
]);
}
public function deleteScientifique(int $id): bool{
return $this->con->executeQuery(
"DELETE FROM Scientifique WHERE id=:id;"
,[
":id"=>[$id,$this->con::PARAM_INT]
]);
}
public function getScientifique(int $id) {
$this->con->executeQuery(
"SELECT id, nom, prenom, photo, dateNaissance, descriptif, ratioTrouvee, idThematique, idDifficulte, idSexe FROM Scientifique WHERE id=:id;"
,[
":id"=>[$id,$this->con::PARAM_INT]
]);
return $this->con->getOneResult();
}
} }

@ -43,5 +43,39 @@ class MdlScientifique extends MdlBase{
} }
public function addScientifique(Scientifique $s){ public function addScientifique(Scientifique $s){
return $this->gw->addScientifique($s); return $this->gw->addScientifique($s);
}
public function editScientifique(Scientifique $s){
return $this->gw->editScientifique($s);
}
public function getScientifique(int $id){
$t=$this->gw->getScientifique($id);
if(gettype($t)!="array"){
throw new Exception("Scientifique non trouvé");
}
$sexe=new MdlSexe();
$sexe=$sexe->getFromId($t["idsexe"]);
$diff=new MdlDifficulte();
$diff=$diff->getFromId($t["iddifficulte"]);
$theme=new MdlThematique();
$theme=$theme->getFromId($t["idthematique"]);
return new Scientifique(
$id,
$t["nom"],
$t["prenom"],
$t["photo"],
DateTime::createFromFormat("Y-m-d", $t["datenaissance"]),
$t["descriptif"],
$t["ratiotrouvee"],
$theme,
$diff,
$sexe
);
} }
} }

@ -2,7 +2,7 @@
<html lang="fr"> <html lang="fr">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Créer une partie</title> <title>Créer un.e scientifique</title>
<link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet" href="css/bootstrap.min.css">
<style> <style>
p, p,
@ -21,34 +21,45 @@
<h1>ajouterScientifiques</h1> <h1>ajouterScientifiques</h1>
<br><br><br> <br><br><br>
<center> <center>
<form action="" method="post"> <form action="" method="post">
<div> <div>
<label for="name">Nom :</label> <label for="name">Nom :</label>
<input type="text" id="name" name="name" required minlength="1" maxlength="128"/> <input type="text" id="name" name="name" required minlength="1" maxlength="128"
value="{% if scientifique is not null %}{{ scientifique.nom }}{% endif %}"/>
</div> </div>
<div> <div>
<label for="name">Prénom :</label> <label for="name">Prénom :</label>
<input type="text" id="prenom" name="prenom" required minlength="1" maxlength="128"/> <input type="text" id="prenom" name="prenom" required minlength="1" maxlength="128"
value="{% if scientifique is not null %}{{ scientifique.prenom }}{% endif %}"/>
</div> </div>
<div> <div>
<label for="name">URL de la photo :</label> <label for="name">URL de la photo :</label>
<input type="text" id="url" name="url" required minlength="1" maxlength="512"/> <input type="text" id="url" name="url" required minlength="1" maxlength="512"
value="{% if scientifique is not null %}{{ scientifique.photo }}{% endif %}"/>
</div> </div>
<div> <div>
<label for="name">Date de naissance :</label> <label for="name">Date de naissance :</label>
<input type="date" id="date" name="date" required/> <input type="date" id="date" name="date" required
value="{% if scientifique is not null %}{{ scientifique.date|date('Y-m-d') }}{% endif %}"/>
</div> </div>
<div> <div>
<label for="name">Description (histoire, accomplissements...) :</label> <label for="name">Description (histoire, accomplissements...) :</label>
<textarea name="description" cols="40" rows="5"></textarea> <textarea name="description" cols="40" rows="5">{% if scientifique is not null %}{{ scientifique.descriptif }}{% endif %}</textarea>
</div> </div>
<fieldset> <fieldset>
<legend>Sexe :</legend> <legend>Sexe :</legend>
{% for se in sexe %} {% for se in sexe %}
<div> <div>
<input type="radio" id="sexe{{se.id}}" name="sexe" value="{{se.id}}" /> <input type="radio" id="sexe{{se.id}}" name="sexe" value="{{se.id}}"
{% if scientifique is not null %}
{% if scientifique.sexe.getId == se.id %}
checked
{% endif %}
{% endif %}
/>
<label for="{{se.id}}">{{se.libelle}}</label> <label for="{{se.id}}">{{se.libelle}}</label>
</div> </div>
{% endfor %} {% endfor %}
@ -57,7 +68,14 @@
<legend>Thematique :</legend> <legend>Thematique :</legend>
{% for se in themes %} {% for se in themes %}
<div> <div>
<input type="radio" id="theme{{se.id}}" name="theme" value="{{se.id}}" /> <input type="radio" id="theme{{se.id}}" name="theme" value="{{se.id}}"
{% if scientifique is not null %}
{% if scientifique.thematique.getId == se.id %}
checked
{% endif %}
{% endif %}
/>
<label for="{{se.id}}">{{se.libelle}}</label> <label for="{{se.id}}">{{se.libelle}}</label>
</div> </div>
{% endfor %} {% endfor %}
@ -66,7 +84,14 @@
<legend>Difficulté :</legend> <legend>Difficulté :</legend>
{% for se in difficultes %} {% for se in difficultes %}
<div> <div>
<input type="radio" id="diff{{se.id}}" name="difficulte" value="{{se.id}}" /> <input type="radio" id="diff{{se.id}}" name="difficulte" value="{{se.id}}"
{% if scientifique is not null %}
{% if scientifique.difficulte.getId == se.id %}
checked
{% endif %}
{% endif %}
/>
<label for="{{se.id}}">{{se.libelle}}</label> <label for="{{se.id}}">{{se.libelle}}</label>
</div> </div>
{% endfor %} {% endfor %}

Loading…
Cancel
Save