Include meal plan recipes in the calendar (closes #368)

This commit is contained in:
Bernd Bestel 2019-09-24 09:40:56 +02:00
parent 2a9f927a13
commit 53c56cc1cb
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
3 changed files with 38 additions and 1 deletions

View File

@ -1,3 +1,4 @@
- It's now possible to display a recipe directly from the meal plan (new "eye button") (thanks @kriddles) - 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) - 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 - Some style/CSS detail-refinements

19
migrations/0091.sql Normal file
View File

@ -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;

View File

@ -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);
} }
} }