link model controller and view to be able to post an appr

This commit is contained in:
Thomas Rubini 2023-01-24 18:39:47 +01:00
parent 899e6e0559
commit 6f57b5a189
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
3 changed files with 8 additions and 6 deletions

View File

@ -9,10 +9,10 @@ final class ApprController
$I_recipe_id = Utils::intOrDie(Utils::getOrDie($A_postParams, "recipe_id"));
$S_comment = Utils::getOrDie($A_postParams, "comment");
$I_score = Utils::intOrDie(Utils::getOrDie($A_postParams, "score"));
$I_note = Utils::intOrDie(Utils::getOrDie($A_postParams, "note"));
$O_apprModel = new ApprModel();
$O_apprModel->createAppr($_SESSION["ID"], $I_recipe_id, $S_comment, $I_score);
$O_apprModel->createAppr($_SESSION["ID"], $I_recipe_id, $S_comment, $I_note);
header("Location: ".$_SERVER['HTTP_REFERER']);
}

View File

@ -29,14 +29,14 @@ final class ApprModel {
return $stmt->fetchAll();
}
public function createAppr($I_user_id, $I_recipe_id, $S_Comment, $I_score)
public function createAppr($I_user_id, $I_recipe_id, $S_Comment, $I_note)
{
$O_model = Model::get();
$stmt = $O_model->prepare("
INSERT INTO APPRECIATION (COMMENT,SCORE,DATE,AUTHOR_ID,RECIPE_ID) VALUES (:comment, :score, :date, :author_id, :recipe_id)
INSERT INTO APPRECIATION (COMMENT,NOTE,DATE,AUTHOR_ID,RECIPE_ID) VALUES (:comment, :note, :date, :author_id, :recipe_id)
");
$stmt->bindParam("comment",$S_Comment);
$stmt->bindParam("score",$I_score);
$stmt->bindParam("note",$I_note);
$_date = date("Y-m-d");
$stmt->bindParam("date",$_date);
$stmt->bindParam("author_id",$I_user_id);

View File

@ -1,6 +1,6 @@
<section>
<h1> Appréciations: </h1>
<form method="POST" action="/">
<form method="POST" action="/appr/create">
<label for="comment">Entrez votre commentaire :</label>
<input type="text" name="comment" id="comment" placeholder="Commentaire">
@ -12,6 +12,8 @@
<input type="radio" name="note" id="note" value="4" title="4"> 4
<input type="radio" name="note" id="note" value="5" title="5"> 5
<input type="hidden" name="recipe_id" value="<?= $A_view["ID"] ?>">
<input type="submit" value="Envoyer">
</form>