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

php
Tom 1 year ago
commit c6d1570ea7

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

@ -67,29 +67,34 @@ class UserController {
public function login() {
global $twig;
if($_SERVER['REQUEST_METHOD'] === 'POST'){
Validation::valUserLogin($_REQUEST['login'], $dVueErreur);
$ug = new MdlUser();
if($ug->login($_REQUEST['login'], $_REQUEST['password'])) {
$_SESSION['pseudo'] = $_REQUEST['login'];
$_SESSION['isLogged'] = true;
header("Location: .");
} else {
//voir si c'est un admin
$ug = new MdlAdmin();
if($ug->login($_REQUEST['login'], $_REQUEST['password'])) {
$_SESSION['pseudo'] = $_REQUEST['login'];
$_SESSION['isAdmin'] = true;
$_SESSION['isLogged'] = true;
header("Location: .");
} else {
$dVueErreur[] = "Connexion échouée";
throw new LoginException("Connexion err");
}
}
} else {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Validation::valUserLogin($_REQUEST['login'], $dVueErreur);
$ug = new MdlUser();
if ($ug->login($_REQUEST['login'], $_REQUEST['password'])) {
$_SESSION['pseudo'] = $_REQUEST['login'];
$_SESSION['isLogged'] = true;
header("Location: .");
} else {
//voir si c'est un admin
$ug = new MdlAdmin();
if ($ug->login($_REQUEST['login'], $_REQUEST['password'])) {
$_SESSION['pseudo'] = $_REQUEST['login'];
$_SESSION['isAdmin'] = true;
$_SESSION['isLogged'] = true;
header("Location: .");
} else {
$dVueErreur[] = "Connexion échouée";
throw new LoginException("Connexion err");
}
}
} else {
echo $twig->render('login.html');
}
}
}
public function logout(){
$_SESSION=[];
header("Location: .");
}
public function createParty(array $params) : void

@ -41,4 +41,36 @@ class ScientifiqueGateway
":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){
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">
<head>
<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">
<style>
p,
@ -21,34 +21,45 @@
<h1>ajouterScientifiques</h1>
<br><br><br>
<center>
<form action="" method="post">
<div>
<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>
<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>
<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>
<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>
<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>
<fieldset>
<legend>Sexe :</legend>
{% for se in sexe %}
<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>
</div>
{% endfor %}
@ -57,7 +68,14 @@
<legend>Thematique :</legend>
{% for se in themes %}
<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>
</div>
{% endfor %}
@ -66,7 +84,14 @@
<legend>Difficulté :</legend>
{% for se in difficultes %}
<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>
</div>
{% endfor %}

Loading…
Cancel
Save