diff --git a/apps/Index/Controllers/HomepageController.php b/apps/Index/Controllers/HomepageController.php index 2114f69..eb9111d 100644 --- a/apps/Index/Controllers/HomepageController.php +++ b/apps/Index/Controllers/HomepageController.php @@ -2,9 +2,40 @@ namespace Lycoreco\Apps\Index\Controllers; +use Lycoreco\Apps\Recipes\Models\CategoryModel; +use Lycoreco\Apps\Recipes\Models\RecipeModel; +use Lycoreco\Apps\Recipes\Models\RecipeUserMenu; use Lycoreco\Includes\BaseController; +require_once(INCLUDES_PATH . '/Const/recipes.php'); + class HomepageController extends BaseController { protected $template_name = APPS_PATH . '/Index/Templates/index.php'; + + public function get_context_data() { + $context = parent::get_context_data(); + + $context['latest_recipes'] = RecipeModel::filter(array( + [ + 'name' => 'obj.status', + 'type' => '=', + 'value' => 'publish' + ]), + ['-obj.created_at'], + 3 + ); + $context['categories'] = CategoryModel::filter(); + $dayNumber = date("w"); + $dayofweek = DAYS_OF_WEEK[$dayNumber]; + + if(CURRENT_USER) { + $context['usermenu_recipe_prefetch'] = RecipeUserMenu::get_prefetch_recipes(CURRENT_USER, $dayofweek); + } + else { + $context['usermenu_recipe_prefetch'] = [ ]; + } + + return $context; + } } diff --git a/apps/Index/Templates/index.php b/apps/Index/Templates/index.php index 1a6c246..9c03da4 100644 --- a/apps/Index/Templates/index.php +++ b/apps/Index/Templates/index.php @@ -1,4 +1,6 @@ -
-
-
-
-
-
-
-
-
-
-
-
-