From c58a94d23cc9cd2ed44806e979d96cc8b00afe6e Mon Sep 17 00:00:00 2001 From: David Katrinka Date: Sat, 28 Jun 2025 15:32:35 +0200 Subject: [PATCH 1/2] TIST-17: added single recipe page --- .../Controllers/SingleRecipeController.php | 22 +- .../Models/IngredientInRecipeModel.php | 13 +- apps/Recipes/Templates/catalog.php | 2 +- apps/Recipes/Templates/single.php | 142 ++++++- assets/css/style.css | 363 ++++++++++++++++-- assets/js/single.js | 71 ++++ components/templates/layout/footer.php | 2 +- media/chana-masala-recipe_684f4743a2a80.jpg | Bin 0 -> 210582 bytes 8 files changed, 578 insertions(+), 37 deletions(-) create mode 100644 assets/js/single.js create mode 100644 media/chana-masala-recipe_684f4743a2a80.jpg diff --git a/apps/Recipes/Controllers/SingleRecipeController.php b/apps/Recipes/Controllers/SingleRecipeController.php index aa883a2..e50a99e 100644 --- a/apps/Recipes/Controllers/SingleRecipeController.php +++ b/apps/Recipes/Controllers/SingleRecipeController.php @@ -2,7 +2,9 @@ namespace Lycoreco\Apps\Recipes\Controllers; +use Lycoreco\Apps\Recipes\Models\IngredientInRecipeModel; use Lycoreco\Apps\Recipes\Models\RecipeModel; +use Lycoreco\Apps\Users\Models\UserModel; use Lycoreco\Includes\BaseController; use Lycoreco\Includes\Routing\HttpExceptions; @@ -33,8 +35,26 @@ class SingleRecipeController extends BaseController public function get_context_data() { $context = parent::get_context_data(); + $recipe = $this->get_model(); - $context['recipe'] = $this->get_model(); + + $context['recipe'] = $recipe; + + $context['author'] = UserModel::get(array( + [ + 'name' => 'obj.id', + 'type' => '=', + 'value' => $recipe->field_author_id + ] + )); + + $context['ingredients'] = IngredientInRecipeModel::filter(array( + [ + 'name' => 'obj.recipe_id', + 'type' => '=', + 'value' => $recipe->get_id() + ] + )); return $context; } diff --git a/apps/Recipes/Models/IngredientInRecipeModel.php b/apps/Recipes/Models/IngredientInRecipeModel.php index 702b9e1..7ecc9ea 100644 --- a/apps/Recipes/Models/IngredientInRecipeModel.php +++ b/apps/Recipes/Models/IngredientInRecipeModel.php @@ -8,7 +8,7 @@ class IngredientInRecipeModel extends BaseModel public $field_ingredient_id; public $field_recipe_id; public $field_amount; - + static protected $search_fields = ['tb1.name']; public $ingredient_name; public $ingredient_unit; @@ -24,10 +24,10 @@ class IngredientInRecipeModel extends BaseModel static protected $table_name = 'recipe_ingredients'; static protected $table_fields = [ - 'id' => 'int', + 'id' => 'int', 'ingredient_id' => 'int', - 'recipe_id' => 'int', - 'amount' => 'int' + 'recipe_id' => 'int', + 'amount' => 'int' ]; public static function init_table() { @@ -47,4 +47,9 @@ class IngredientInRecipeModel extends BaseModel { return $this->field_amount . ' ' . $this->ingredient_unit; } + + public function __toString() + { + return $this->ingredient_name; + } } \ No newline at end of file diff --git a/apps/Recipes/Templates/catalog.php b/apps/Recipes/Templates/catalog.php index 1283094..2c2d6ec 100644 --- a/apps/Recipes/Templates/catalog.php +++ b/apps/Recipes/Templates/catalog.php @@ -31,7 +31,7 @@ the_header( - +
Time To Make: - field_estimated_time; ?> minutes + get_time(); ?>
Ingredients: @@ -49,13 +50,9 @@ the_header(
@@ -65,28 +62,27 @@ the_header(
- - - - - + + + + +