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( - +
| Name | +Count | +
|---|---|
| = $ing; ?> | += $ing->get_count(); ?> | +