Merge pull request #160 from ThomasRubini/fix

fixed non shown category
This commit is contained in:
Djalim Simaila 2023-01-27 07:14:13 +01:00 committed by GitHub
commit 250c618005
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 40 deletions

View File

@ -9,12 +9,14 @@ final class CategoryController
$A_vegan = ParticularityModel::getByName("végan")->getRecipes(); $A_vegan = ParticularityModel::getByName("végan")->getRecipes();
$A_gluten = ParticularityModel::getByName("sans gluten")->getRecipes(); $A_gluten = ParticularityModel::getByName("sans gluten")->getRecipes();
$A_lactose = ParticularityModel::getByName("sans lactose")->getRecipes(); $A_lactose = ParticularityModel::getByName("sans lactose")->getRecipes();
$A_recipes = RecipeModel::getUncategorizedRecipes();
$A_array_categories = array( $A_array_categories = array(
"Végan" => $A_vegan, "Végan" => $A_vegan,
"Végétarien" => $A_vegeta, "Végétarien" => $A_vegeta,
"Sans gluten" => $A_gluten, "Sans gluten" => $A_gluten,
"Sans lactose" => $A_lactose "Sans lactose" => $A_lactose,
"Non Catégorisé" => $A_recipes
); );
View::show("category/view", $A_array_categories); View::show("category/view", $A_array_categories);

View File

@ -71,6 +71,26 @@ final class RecipeController
$O_recipe->S_INSTRUCTIONS = substr($S_instructions, 2); $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) public function createAction(Array $A_urlParams = null, Array $A_postParams = null)
{ {
Session::login_or_die(); Session::login_or_die();
@ -91,26 +111,8 @@ final class RecipeController
$A_ingredientNames = Utils::getOrDie($A_postParams, "recipeIngredientNames"); $A_ingredientNames = Utils::getOrDie($A_postParams, "recipeIngredientNames");
$A_ingredientQuantities = Utils::getOrDie($A_postParams, "recipeIngredientQuantities"); $A_ingredientQuantities = Utils::getOrDie($A_postParams, "recipeIngredientQuantities");
// handle particularities // handle particularities
if(isset($A_postParams["recipeVegan"])){ self::handleParticularities($O_recipe, $A_postParams);
$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(); $A_ingredients = array();
for($i=0; $i<count($A_ingredientNames); $i++) { for($i=0; $i<count($A_ingredientNames); $i++) {
@ -149,23 +151,7 @@ final class RecipeController
ParticularityModel::removeByRecipe($O_recipe->I_ID); ParticularityModel::removeByRecipe($O_recipe->I_ID);
// handle particularities // handle particularities
if(isset($A_postParams["part_Vegan"])){ self::handleParticularities($O_recipe, $A_postParams);
$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 // update img if necessary
$fp = Utils::tryProcessImg("recipeImage"); $fp = Utils::tryProcessImg("recipeImage");

View File

@ -210,6 +210,19 @@ final class RecipeModel
return $A_recipes; 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) public static function getRandomRecipes($I_n)
{ {
$O_model = Model::get(); $O_model = Model::get();

View File

@ -3,7 +3,8 @@ $allCategory = array(
"Végan" => "vegan", "Végan" => "vegan",
"Végétarien" => "vegetarian", "Végétarien" => "vegetarian",
"Sans gluten" => "glutenLess", "Sans gluten" => "glutenLess",
"Sans lactose" => "lactoseLess"); "Sans lactose" => "lactoseLess",
"Non Catégorisé" => "uncategorized");
?> ?>
<main class="hasAside"> <main class="hasAside">

View File

@ -1,9 +1,10 @@
<?php <?php
$allCategory = array( $allCategory = array(
"Végan" => "vegan", "Végan" => "vegan",
"Végetarien" => "vegetarian", "Végetérien" => "vegetarian",
"Sans gluten" => "glutenLess", "Sans gluten" => "glutenLess",
"Sans lactose" => "lactoseLess"); "Sans lactose" => "lactoseLess",
"Non Catégorisé" => "uncategorized");
?> ?>
<aside> <aside>