From ee57bf07113c0356117895b40822c7bf4301d056 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Fri, 27 Jan 2023 07:12:40 +0100 Subject: [PATCH] fixed non shown category --- Controllers/CategoryController.php | 4 ++- Controllers/RecipeController.php | 58 ++++++++++++------------------ Models/RecipeModel.php | 13 +++++++ Views/category/view.php | 3 +- Views/common/category_list.php | 5 +-- 5 files changed, 43 insertions(+), 40 deletions(-) diff --git a/Controllers/CategoryController.php b/Controllers/CategoryController.php index eff76e8..edfef23 100644 --- a/Controllers/CategoryController.php +++ b/Controllers/CategoryController.php @@ -9,12 +9,14 @@ final class CategoryController $A_vegan = ParticularityModel::getByName("végan")->getRecipes(); $A_gluten = ParticularityModel::getByName("sans gluten")->getRecipes(); $A_lactose = ParticularityModel::getByName("sans lactose")->getRecipes(); + $A_recipes = RecipeModel::getUncategorizedRecipes(); $A_array_categories = array( "Végan" => $A_vegan, "Végétarien" => $A_vegeta, "Sans gluten" => $A_gluten, - "Sans lactose" => $A_lactose + "Sans lactose" => $A_lactose, + "Non Catégorisé" => $A_recipes ); View::show("category/view", $A_array_categories); diff --git a/Controllers/RecipeController.php b/Controllers/RecipeController.php index 231bb55..32aaa0e 100644 --- a/Controllers/RecipeController.php +++ b/Controllers/RecipeController.php @@ -71,6 +71,26 @@ final class RecipeController $O_recipe->S_INSTRUCTIONS = substr($S_instructions, 2); } + private function handleParticularities($O_recipe, $A_postParams){ + // 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(); + } + } + public function createAction(Array $A_urlParams = null, Array $A_postParams = null) { Session::login_or_die(); @@ -91,26 +111,8 @@ 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(); - } - + self::handleParticularities($O_recipe, $A_postParams); $A_ingredients = array(); for($i=0; $iI_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(); - } - + self::handleParticularities($O_recipe, $A_postParams); // update img if necessary $fp = Utils::tryProcessImg("recipeImage"); diff --git a/Models/RecipeModel.php b/Models/RecipeModel.php index c3ed11a..496ed90 100644 --- a/Models/RecipeModel.php +++ b/Models/RecipeModel.php @@ -210,6 +210,19 @@ final class RecipeModel return $A_recipes; } + public static function getUncategorizedRecipes(){ + $O_model = Model::get(); + $stmt = $O_model->prepare("SELECT * FROM RECIPE WHERE ID NOT IN (SELECT RECIPE_ID FROM RECIPE_PARTICULARITY)"); + $stmt->execute(); + + $A_recipes = array(); + foreach($stmt->fetchAll() as $row){ + array_push($A_recipes, self::createFromRow($row, $row["ID"])); + } + + return $A_recipes; + } + public static function getRandomRecipes($I_n) { $O_model = Model::get(); diff --git a/Views/category/view.php b/Views/category/view.php index c2e079b..a796b92 100644 --- a/Views/category/view.php +++ b/Views/category/view.php @@ -3,7 +3,8 @@ $allCategory = array( "Végan" => "vegan", "Végétarien" => "vegetarian", "Sans gluten" => "glutenLess", - "Sans lactose" => "lactoseLess"); + "Sans lactose" => "lactoseLess", + "Non Catégorisé" => "uncategorized"); ?>
diff --git a/Views/common/category_list.php b/Views/common/category_list.php index 7c5333e..a7e376e 100644 --- a/Views/common/category_list.php +++ b/Views/common/category_list.php @@ -1,9 +1,10 @@ "vegan", - "Végetarien" => "vegetarian", + "Végetérien" => "vegetarian", "Sans gluten" => "glutenLess", - "Sans lactose" => "lactoseLess"); + "Sans lactose" => "lactoseLess", + "Non Catégorisé" => "uncategorized"); ?>