Merge pull request #78 from ThomasRubini/new_recipe

This commit is contained in:
Thomas Rubini 2023-01-24 20:13:13 +01:00 committed by GitHub
commit 0ff447fe58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 20 deletions

View File

@ -35,16 +35,25 @@ final class RecipeController
} }
$O_recipeModel = new RecipeModel(); $O_recipeModel = new RecipeModel();
$A_returnArray = $O_recipeModel->getFullRecipe($A_urlParams[0]); $A_recipe = $O_recipeModel->getFullRecipe($A_urlParams[0]);
if ($A_returnArray === null) { if ($A_recipe === null) {
throw new HTTPSpecialCaseException(404); throw new HTTPSpecialCaseException(404);
} }
if ($A_returnArray["AUTHOR_ID"] !== $_SESSION["ID"]) { if ($A_recipe["AUTHOR_ID"] !== $_SESSION["ID"]) {
if(!Session::is_admin()){
throw new HTTPSpecialCaseException(400, "You are not the owner of this recipe"); throw new HTTPSpecialCaseException(400, "You are not the owner of this recipe");
} }
}
View::show("recipe/edit", $A_returnArray); View::show("recipe/edit", array("POST_URI" => "/recipe/update", "RECIPE" => $A_recipe));
}
public function newAction(Array $A_urlParams = null, Array $A_postParams = null)
{
Session::login_or_die();
View::show("recipe/edit", array("POST_URI" => "/recipe/create", "RECIPE" => array()));
} }
public function searchAction(Array $A_urlParams = null, Array $A_postParams = null, Array $A_getParams = null) public function searchAction(Array $A_urlParams = null, Array $A_postParams = null, Array $A_getParams = null)

View File

@ -2,7 +2,7 @@
$array_header = array( $array_header = array(
'<img src="/static/img/logo.png" alt="Logo">' => "/", '<img src="/static/img/logo.png" alt="Logo">' => "/",
"Recette" => "/Recipe/view/36", "Recette" => "/Recipe/view/36",
"+" => "/recipe/edit", "+" => "/recipe/new",
"Rechercher" => "rechercher", "Rechercher" => "rechercher",
'<img src="/static/img/default_user.svg" type="image/svg+xml">' => "/user/view" '<img src="/static/img/default_user.svg" type="image/svg+xml">' => "/user/view"
); );

View File

@ -1,9 +1,11 @@
<?php <?php
$A_recipe = $A_view["RECIPE"];
function getOrEmpty($A_Dict, $S_keyName) { function getOrEmpty($A_Dict, $S_keyName) {
if (isset($A_Dict[$S_keyName])) { if (isset($A_Dict[$S_keyName])) {
return $A_Dict[$S_keyName]; return $A_Dict[$S_keyName];
} else { } else {
echo "$S_keyName EMPTY";
if($S_keyName == "TYPE" || $S_keyName == "INGREDIENTS") if($S_keyName == "TYPE" || $S_keyName == "INGREDIENTS")
return array(); return array();
return ""; return "";
@ -13,42 +15,42 @@ function getOrEmpty($A_Dict, $S_keyName) {
<main> <main>
<form action="/recipe/save" method="post"> <form action="<?= $A_view["POST_URI"] ?>" method="post">
<label for="recipeImage">Entrez l'image de haut de page&nbsp;:</label> <label for="recipeImage">Entrez l'image de haut de page&nbsp;:</label>
<input type="file" name="recipeImage" id="recipeImage" required> <input type="file" name="recipeImage" id="recipeImage" required>
<label for="recipeName">Nom de la recette&nbsp;:</label> <label for="recipeName">Nom de la recette&nbsp;:</label>
<input type="text" name="recipeName" id="recipeName" placeholder="Nom du plat" value="<?= getOrEmpty($A_view, "NAME") ?>" required> <input type="text" name="recipeName" id="recipeName" placeholder="Nom du plat" value="<?= getOrEmpty($A_recipe, "NAME") ?>" required>
</br> </br>
<label for="recipeDescription">Description de la recette</label> <label for="recipeDescription">Description de la recette</label>
</br> </br>
<textarea name="recipeDescription" id="recipeDescription"><?= getOrEmpty($A_view, "DESC") ?></textarea> <textarea name="recipeDescription" id="recipeDescription"><?= getOrEmpty($A_recipe, "DESC") ?></textarea>
<section> <section>
<h1>Informations alimentaires</h1> <h1>Informations alimentaires</h1>
<label for="recipeFifficulte">Niveau de difficulé&nbsp;:</label> <label for="recipeFifficulte">Niveau de difficulé&nbsp;:</label>
<select name="recipeDifficulte" id="recipeDifficulte" required> <select name="recipeDifficulte" id="recipeDifficulte" required>
<option value="tresFacile" <?= getOrEmpty($A_view, "DIFFICULTY_NAME")=="Très facile"? 'selected="selected"' : "" ?> >Très facile</option> <option value="tresFacile" <?= getOrEmpty($A_recipe, "DIFFICULTY_NAME")=="Très facile"? 'selected="selected"' : "" ?> >Très facile</option>
<option value="facile" <?= getOrEmpty($A_view, "DIFFICULTY_NAME")=="Facile"? 'selected="selected"' : "" ?>>Facile</option> <option value="facile" <?= getOrEmpty($A_recipe, "DIFFICULTY_NAME")=="Facile"? 'selected="selected"' : "" ?>>Facile</option>
<option value="moyen" <?= getOrEmpty($A_view, "DIFFICULTY_NAME")=="Moyen"? 'selected="selected"' : "" ?>>Moyen</option> <option value="moyen" <?= getOrEmpty($A_recipe, "DIFFICULTY_NAME")=="Moyen"? 'selected="selected"' : "" ?>>Moyen</option>
<option value="difficile" <?= getOrEmpty($A_view, "DIFFICULTY_NAME")=="Difficle"? 'selected="selected"' : "" ?>>Difficile</option> <option value="difficile" <?= getOrEmpty($A_recipe, "DIFFICULTY_NAME")=="Difficle"? 'selected="selected"' : "" ?>>Difficile</option>
</select> </select>
<legend>Type de plat&nbsp;:</legend> <legend>Type de plat&nbsp;:</legend>
<input type="checkbox" name="recipeVegan" id="recipeVegan" <?= in_array("Végan", getOrEmpty($A_view, "TYPE"))? "checked":"" ?> > <input type="checkbox" name="recipeVegan" id="recipeVegan" <?= in_array("Végan", getOrEmpty($A_recipe, "TYPE"))? "checked":"" ?> >
<label for="recipeVegan">Végan</label> <label for="recipeVegan">Végan</label>
<input type="checkbox" name="recipeLactoseFree" id="recipeLactoseFree" <?= in_array("Sans lactose", getOrEmpty($A_view, "TYPE"))? "checked":"" ?> > <input type="checkbox" name="recipeLactoseFree" id="recipeLactoseFree" <?= in_array("Sans lactose", getOrEmpty($A_recipe, "TYPE"))? "checked":"" ?> >
<label for="recipeLactoseFree">Sans lactose</label> <label for="recipeLactoseFree">Sans lactose</label>
<input type="checkbox" name="recipeGlutenFree" id="recipeGlutenFree" <?= in_array("Sans gluten", getOrEmpty($A_view, "TYPE"))? "checked":"" ?> > <input type="checkbox" name="recipeGlutenFree" id="recipeGlutenFree" <?= in_array("Sans gluten", getOrEmpty($A_recipe, "TYPE"))? "checked":"" ?> >
<label for="recipeGlutenFree">Sans gluten</label> <label for="recipeGlutenFree">Sans gluten</label>
</br> </br>
<label for="recipeTime">Temps de préparation&nbsp;:</label> <label for="recipeTime">Temps de préparation&nbsp;:</label>
<input type="number" name="recipeTime" id="recipeTime" min="5" max="1500" step="5" placeholder="Temps de préparation" value="<?= getOrEmpty($A_view, "TIME") ?>" required> <input type="number" name="recipeTime" id="recipeTime" min="5" max="1500" step="5" placeholder="Temps de préparation" value="<?= getOrEmpty($A_recipe, "TIME") ?>" required>
<label for="recipeTime">minutes</label> <label for="recipeTime">minutes</label>
</section> </section>
@ -60,7 +62,7 @@ function getOrEmpty($A_Dict, $S_keyName) {
<ul class="recipeIngredients"> <ul class="recipeIngredients">
<?php <?php
$ingredients = getOrEmpty($A_view, "INGREDIENTS"); $ingredients = getOrEmpty($A_recipe, "INGREDIENTS");
if(sizeof($ingredients) > 0) { if(sizeof($ingredients) > 0) {
$i = 1; $i = 1;
foreach($ingredients as $ingredient) { foreach($ingredients as $ingredient) {
@ -98,7 +100,7 @@ function getOrEmpty($A_Dict, $S_keyName) {
<ol class="recipeInstructions"> <ol class="recipeInstructions">
<?php <?php
$preparation = getOrEmpty($A_view, "RECIPE"); $preparation = getOrEmpty($A_recipe, "RECIPE");
if(!empty($preparation)) { if(!empty($preparation)) {
$steps = explode("\n", $preparation); $steps = explode("\n", $preparation);
$i = 1; $i = 1;