Merge pull request #159 from ThomasRubini/fix

fixed particularities
This commit is contained in:
Djalim Simaila 2023-01-26 23:45:05 +01:00 committed by GitHub
commit 91cdb68363
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 14 deletions

View File

@ -8,12 +8,10 @@ final class RecipeController
if(count($A_urlParams)!=1){
throw new HTTPSpecialCaseException(404);
}
$O_recipe = RecipeModel::getByID($A_urlParams[0]);
if ($O_recipe === null) {
throw new HTTPSpecialCaseException(404);
}
View::show("recipe/view", array(
"ADMIN" => Session::is_admin(),
"USER_ID" => Session::is_login() ? $_SESSION["ID"] : null,
@ -93,6 +91,27 @@ final class RecipeController
$A_ingredientNames = Utils::getOrDie($A_postParams, "recipeIngredientNames");
$A_ingredientQuantities = Utils::getOrDie($A_postParams, "recipeIngredientQuantities");
// handle particularities
if(isset($A_postParams["recipeVegan"])){
$O_part = new ParticularityModel($O_recipe->I_ID, "végan");
$O_part->insert();
}
if(isset($A_postParams["recipeVegetarian"])){
$O_part = new ParticularityModel($O_recipe->I_ID, "végétarien");
$O_part->insert();
}
if(isset($A_postParams["recipeLactoseFree"])){
$O_part = new ParticularityModel($O_recipe->I_ID, "sans lactose");
$O_part->insert();
}
if(isset($A_postParams["recipeGlutenFree"])){
$O_part = new ParticularityModel($O_recipe->I_ID, "sans gluten");
$O_part->insert();
}
$A_ingredients = array();
for($i=0; $i<count($A_ingredientNames); $i++) {
$O_ingr = new IngredientModel(
@ -127,6 +146,27 @@ final class RecipeController
self::fillRecipeFromPostParams($O_recipe, $A_postParams);
$O_recipe->update();
ParticularityModel::removeByRecipe($O_recipe->I_ID);
// handle particularities
if(isset($A_postParams["part_Vegan"])){
$O_part = new ParticularityModel($O_recipe->I_ID, "végan");
$O_part->insert();
}
if(isset($A_postParams["part_Vegeta"])){
$O_part = new ParticularityModel($O_recipe->I_ID, "végétarien");
$O_part->insert();
}
if(isset($A_postParams["part_LactoseFree"])){
$O_part = new ParticularityModel($O_recipe->I_ID, "sans lactose");
$O_part->insert();
}
if(isset($A_postParams["part_GlutenFree"])){
$O_part = new ParticularityModel($O_recipe->I_ID, "sans gluten");
$O_part->insert();
}
// update img if necessary
$fp = Utils::tryProcessImg("recipeImage");
if($fp !== null) {

View File

@ -21,15 +21,10 @@ final class ParticularityModel
public function insert(){
$O_model = Model::get();
$stmt = $O_model->prepare("SELECT 1 FROM PARTICULARITY WHERE :name=name");
$stmt = $O_model->prepare("SELECT ID FROM PARTICULARITY WHERE :name=name");
$stmt->bindParam("name", $this->S_NAME);
$stmt->execute();
if($stmt->rowCount() === 0){
$stmt = $O_model->prepare("INSERT INTO PARTICULARITY (NAME) VALUES(:name)");
$stmt->bindParam("name", $this->S_NAME);
$stmt->execute();
$this->I_PARTICULARITY_ID = Model::get()->lastInsertId();
}
$this->I_PARTICULARITY_ID = $stmt->fetch()["ID"];
$stmt = $O_model->prepare("INSERT INTO RECIPE_PARTICULARITY VALUES(:recipe_id, :particularity_id)");
$stmt->bindParam("recipe_id", $this->I_RECIPE_ID);
$stmt->bindParam("particularity_id", $this->I_PARTICULARITY_ID);
@ -67,11 +62,18 @@ final class ParticularityModel
$stmt->bindParam("id", $this->I_PARTICULARITY_ID);
$stmt->execute();
$stmt = $O_model->prepare("DELETE FROM RECIPE_PARTICULARITY WHERE PARTICULARITY_ID=:id");
$stmt->execute();
$stmt->bindParam("id", $this->I_PARTICULARITY_ID);
$stmt->execute();
}
public static function removeByRecipe($I_recipe_id){
$O_model = Model::get();
$stmt = $O_model->prepare("DELETE FROM RECIPE_PARTICULARITY WHERE RECIPE_ID=:id");
$stmt->bindParam("id",$I_recipe_id);
$stmt->execute();
}
public static function searchByRecipe($I_recipe_id)
{
$O_model = Model::get();

View File

@ -15,7 +15,10 @@ if ($O_recipe === null) {
$S_descr = $O_recipe->S_DESCR;
$A_instructions = $O_recipe->getSplitInstructions();
$S_difficultyName = $O_recipe->getDifficulty()->S_NAME;
$A_parts = array(); // TODO
$A_parts = array();
foreach(ParticularityModel::searchByRecipe($O_recipe->I_ID) as $O_part){
array_push($A_parts, $O_part->S_NAME);
}
$A_ingredients = $O_recipe->getIngredients();
}
?>
@ -51,11 +54,13 @@ if ($O_recipe === null) {
<legend>Particularités du plat&nbsp;:</legend>
<input type="checkbox" name="part_Vegan" id="recipeVegan" <?= in_array("Végan", $A_parts)? "checked":"" ?> >
<input type="checkbox" name="part_Vegan" id="recipeVegan" <?= in_array("végan", $A_parts)? "checked":"" ?> >
<label for="recipeVegan" class="labelParticularite">Végan</label>
<input type="checkbox" name="part_LactoseFree" id="recipeLactoseFree" <?= in_array("Sans lactose", $A_parts)? "checked":"" ?> >
<input type="checkbox" name="part_Vegeta" id="recipeVegetarian" <?= in_array("végétarien", $A_parts)? "checked":"" ?> >
<label for="recipeVegetarian" class="labelParticularite">Végétarien</label>
<input type="checkbox" name="part_LactoseFree" id="recipeLactoseFree" <?= in_array("sans lactose", $A_parts)? "checked":"" ?> >
<label for="recipeLactoseFree" class="labelParticularite">Sans lactose</label>
<input type="checkbox" name="part_GlutenFree" id="recipeGlutenFree" <?= in_array("Sans gluten", $A_parts)? "checked":"" ?> >
<input type="checkbox" name="part_GlutenFree" id="recipeGlutenFree" <?= in_array("sans gluten", $A_parts)? "checked":"" ?> >
<label for="recipeGlutenFree" class="labelParticularite">Sans gluten</label>
</br>