verifier les données #7

Merged
gwenael.planchon merged 3 commits from php_verifdonn into php 1 year ago

@ -40,6 +40,13 @@ class AdminController {
if(isset($_GET["id"])){ if(isset($_GET["id"])){
$id=intval($_GET["id"]); $id=intval($_GET["id"]);
} }
try{
$this->verifierDonnees();
} catch (Exception $ex){
$dVueErreur[] = 'Erreur : '.$ex;
echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]);
return;
}
$sci = new Scientifique( $sci = new Scientifique(
$id, $id,
$_POST["name"], $_POST["name"],
@ -92,6 +99,39 @@ class AdminController {
} }
private function verifierDonnees(){
$sexe = new MdlSexe();
$theme = new MdlThematique();
$diff = new MdlDifficulte();
$selectTheme=$theme->getFromId(intval($_POST["theme"]));
$selectDiff=$diff->getFromId(intval($_POST["difficulte"]));
$selectSexe=$sexe->getFromId(intval($_POST["sexe"]));
//todo : verifier les données, mettre dans une fonction et try catch
if(strlen($_POST["name"]) < 2){
throw new Exception("nom trop court");
}
if(strlen($_POST["prenom"]) < 2){
throw new Exception("prénom trop court");
}
if(empty($_POST["url"])){
throw new Exception("pas de photo");
}
if(strlen($_POST["name"]) < 2){
throw new Exception("nom trop court");
}
if(strlen($_POST["description"]) < 20){
throw new Exception("description trop courte ");
}
if($selectTheme==null){
throw new Exception("thematique inconnue");
}
if($selectSexe==null){
throw new Exception("sexe inconnu");
}
if($selectDiff==null){
throw new Exception("difficulté inconnue");
}
}
} }
?> ?>

@ -45,7 +45,7 @@ class ScientifiqueGateway
":idThematique"=>[$sci->getThematique()->getId(),$this->con::PARAM_STR], ":idThematique"=>[$sci->getThematique()->getId(),$this->con::PARAM_STR],
":idDifficulte"=>[$sci->getDifficulte()->getId(),$this->con::PARAM_STR], ":idDifficulte"=>[$sci->getDifficulte()->getId(),$this->con::PARAM_STR],
":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR] ":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR]
]); ]) ? true : false ;
} }
public function getScientifiquesParPages(int $currentPage, int $nbElemByPage) : array { public function getScientifiquesParPages(int $currentPage, int $nbElemByPage) : array {
@ -82,7 +82,7 @@ class ScientifiqueGateway
":idDifficulte"=>[$sci->getDifficulte()->getId(),$this->con::PARAM_STR], ":idDifficulte"=>[$sci->getDifficulte()->getId(),$this->con::PARAM_STR],
":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR], ":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR],
":id"=>[$sci->getId(),$this->con::PARAM_INT] ":id"=>[$sci->getId(),$this->con::PARAM_INT]
]); ]) ? true : false ;
} }
/** /**

Loading…
Cancel
Save