add recipe/create action

This commit is contained in:
Thomas Rubini 2023-01-25 21:49:22 +01:00
parent 4e033bfe37
commit cba3f90657
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
2 changed files with 22 additions and 6 deletions

View File

@ -47,10 +47,26 @@ final class RecipeController
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 createAction(Array $A_urlParams = null, Array $A_postParams = null)
{
Session::login_or_die();
$O_difficulty = DifficultyModel::getByName($A_postParams["recipeDifficulty"]);
if($O_difficulty === null){
throw new HTTPSpecialCaseException(400, "Invalid difficulty");
}
$O_recipe = new RecipeModel(
$A_postParams["recipeName"], $A_postParams["recipeTime"], $A_postParams["recipeDescription"],
null, $O_difficulty->I_ID, $_SESSION["ID"]
);
$O_recipe->insert();
}
public function searchAction(Array $A_urlParams = null, Array $A_postParams = null, Array $A_getParams = null)
{
if (isset($A_getParams["query"])) {

View File

@ -31,7 +31,7 @@ function getOrEmpty($A_Dict, $S_keyName) {
<h1>Informations alimentaires</h1>
<label for="recipeFifficulte">Niveau de difficulé&nbsp;:</label>
<select name="recipeDifficulte" id="recipeDifficulte" required>
<select name="recipeDifficulty" id="recipeDifficulte" required>
<option value="tresFacile" <?= getOrEmpty($A_recipe, "DIFFICULTY_NAME")=="Très facile"? 'selected="selected"' : "" ?> >Très facile</option>
<option value="facile" <?= getOrEmpty($A_recipe, "DIFFICULTY_NAME")=="Facile"? 'selected="selected"' : "" ?>>Facile</option>
<option value="moyen" <?= getOrEmpty($A_recipe, "DIFFICULTY_NAME")=="Moyen"? 'selected="selected"' : "" ?>>Moyen</option>
@ -39,12 +39,12 @@ function getOrEmpty($A_Dict, $S_keyName) {
</select>
<legend>Type de plat&nbsp;:</legend>
<input type="checkbox" name="recipeVegan" id="recipeVegan" <?= in_array("Végan", getOrEmpty($A_recipe, "TYPE"))? "checked":"" ?> >
<legend>Particularités du plat&nbsp;:</legend>
<input type="checkbox" name="part_Vegan" id="recipeVegan" <?= in_array("Végan", getOrEmpty($A_recipe, "TYPE"))? "checked":"" ?> >
<label for="recipeVegan">Végan</label>
<input type="checkbox" name="recipeLactoseFree" id="recipeLactoseFree" <?= in_array("Sans lactose", getOrEmpty($A_recipe, "TYPE"))? "checked":"" ?> >
<input type="checkbox" name="part_LactoseFree" id="recipeLactoseFree" <?= in_array("Sans lactose", getOrEmpty($A_recipe, "TYPE"))? "checked":"" ?> >
<label for="recipeLactoseFree">Sans lactose</label>
<input type="checkbox" name="recipeGlutenFree" id="recipeGlutenFree" <?= in_array("Sans gluten", getOrEmpty($A_recipe, "TYPE"))? "checked":"" ?> >
<input type="checkbox" name="part_GlutenFree" id="recipeGlutenFree" <?= in_array("Sans gluten", getOrEmpty($A_recipe, "TYPE"))? "checked":"" ?> >
<label for="recipeGlutenFree">Sans gluten</label>
</br>