diff --git a/changelog/53_UNRELEASED_2019-xx-xx.md b/changelog/53_UNRELEASED_2019-xx-xx.md index 67256088..3b8904f1 100644 --- a/changelog/53_UNRELEASED_2019-xx-xx.md +++ b/changelog/53_UNRELEASED_2019-xx-xx.md @@ -1,3 +1,4 @@ - It's now possible to display a recipe directly from the meal plan (new "eye button") (thanks @kriddles) - Improved the responsiveness of the meal plan and calendar page by automatically switching to a day calendar view on smaller screens (thanks for the idea @kriddles) +- The calendar now also contains all planned recipes from the meal plan on the corresponding day - Some style/CSS detail-refinements diff --git a/migrations/0091.sql b/migrations/0091.sql new file mode 100644 index 00000000..59c5d5da --- /dev/null +++ b/migrations/0091.sql @@ -0,0 +1,19 @@ +DROP VIEW recipes_nestings_resolved; +CREATE VIEW recipes_nestings_resolved +AS +WITH RECURSIVE r1(recipe_id, includes_recipe_id, includes_servings) +AS ( + SELECT id, id, 1 + FROM recipes + + UNION ALL + + SELECT rn.recipe_id, r1.includes_recipe_id, rn.servings + FROM recipes_nestings rn, r1 r1 + WHERE rn.includes_recipe_id = r1.recipe_id + LIMIT 100 -- This is just a safety limit to prevent infinite loops due to infinite nested recipes +) +SELECT + *, + 1 AS id -- Dummy, LessQL needs an id column +FROM r1; diff --git a/services/CalendarService.php b/services/CalendarService.php index 80f35ea4..8f05e2eb 100644 --- a/services/CalendarService.php +++ b/services/CalendarService.php @@ -87,6 +87,23 @@ class CalendarService extends BaseService ); } - return array_merge($stockEvents, $taskEvents, $choreEvents, $batteryEvents); + $recipes = $this->Database->recipes(); + $mealPlanDayRecipes = $this->Database->recipes()->where('type', 'mealplan-day'); + $titlePrefix = $this->LocalizationService->__t('Meal plan') . ': '; + $mealPlanRecipeEvents = array(); + foreach($mealPlanDayRecipes as $mealPlanDayRecipe) + { + $recipesOfCurrentDay = $this->Database->recipes_nestings_resolved()->where('recipe_id = :1 AND includes_recipe_id != :1', $mealPlanDayRecipe->id); + foreach ($recipesOfCurrentDay as $recipeOfCurrentDay) + { + $mealPlanRecipeEvents[] = array( + 'title' => $titlePrefix . FindObjectInArrayByPropertyValue($recipes, 'id', $recipeOfCurrentDay->includes_recipe_id)->name, + 'start' => FindObjectInArrayByPropertyValue($recipes, 'id', $recipeOfCurrentDay->recipe_id)->name, + 'date_format' => 'date' + ); + } + } + + return array_merge($stockEvents, $taskEvents, $choreEvents, $batteryEvents, $mealPlanRecipeEvents); } }