From dcfd9d848d683b52f631cf1f452413d07f19fb8b Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 22 Mar 2020 09:27:49 +0100 Subject: [PATCH] Added changelog for #637 / #638 --- changelog/57_UNRELEASED_2020-xx-xx.md | 3 +++ controllers/RecipesController.php | 34 ++++++++++++++------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/changelog/57_UNRELEASED_2020-xx-xx.md b/changelog/57_UNRELEASED_2020-xx-xx.md index 4d51acb9..a1e9d657 100644 --- a/changelog/57_UNRELEASED_2020-xx-xx.md +++ b/changelog/57_UNRELEASED_2020-xx-xx.md @@ -1,2 +1,5 @@ +### Recipe fixes +- Fixed a PHP notice on the recipes page when there are no recipes (thanks @mrunkel) + ### General & other improvements - Improved the the overview pages on mobile devices (main column was hidden) (thanks @Mik-) diff --git a/controllers/RecipesController.php b/controllers/RecipesController.php index fbb846ab..8e0709f1 100644 --- a/controllers/RecipesController.php +++ b/controllers/RecipesController.php @@ -33,20 +33,8 @@ class RecipesController extends BaseController } } - $renderArray = [ - 'recipes' => $recipes, - 'recipesResolved' => $recipesResolved, - 'recipePositionsResolved' => $this->getDatabase()->recipes_pos_resolved()->where('recipe_type', RecipesService::RECIPE_TYPE_NORMAL), - 'selectedRecipe' => $selectedRecipe, - 'selectedRecipePositionsResolved' => $selectedRecipePositionsResolved, - 'products' => $this->getDatabase()->products(), - 'quantityUnits' => $this->getDatabase()->quantity_units(), - 'userfields' => $this->getUserfieldsService()->GetFields('recipes'), - 'userfieldValues' => $this->getUserfieldsService()->GetAllValues('recipes'), - 'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved() - ]; - - if ($selectedRecipe) { + if ($selectedRecipe) + { $selectedRecipeSubRecipes = $this->getDatabase()->recipes()->where('id IN (SELECT includes_recipe_id FROM recipes_nestings_resolved WHERE recipe_id = :1 AND includes_recipe_id != :1)', $selectedRecipe->id)->orderBy('name')->fetchAll(); $selectedRecipeSubRecipesPositions = $this->getDatabase()->recipes_pos_resolved()->where('recipe_id = :1', $selectedRecipe->id)->orderBy('ingredient_group', 'ASC', 'product_group', 'ASC')->fetchAll(); @@ -56,6 +44,7 @@ class RecipesController extends BaseController { $includedRecipeIdsAbsolute[] = $subRecipe->id; } + $renderArray = [ 'recipes' => $recipes, 'recipesResolved' => $recipesResolved, @@ -73,9 +62,22 @@ class RecipesController extends BaseController 'userfieldValues' => $this->getUserfieldsService()->GetAllValues('recipes'), 'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved() ]; - } - + else + { + $renderArray = [ + 'recipes' => $recipes, + 'recipesResolved' => $recipesResolved, + 'recipePositionsResolved' => $this->getDatabase()->recipes_pos_resolved()->where('recipe_type', RecipesService::RECIPE_TYPE_NORMAL), + 'selectedRecipe' => $selectedRecipe, + 'selectedRecipePositionsResolved' => $selectedRecipePositionsResolved, + 'products' => $this->getDatabase()->products(), + 'quantityUnits' => $this->getDatabase()->quantity_units(), + 'userfields' => $this->getUserfieldsService()->GetFields('recipes'), + 'userfieldValues' => $this->getUserfieldsService()->GetAllValues('recipes'), + 'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved() + ]; + } return $this->renderPage($response, 'recipes', $renderArray); }