62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php
|
|
|
|
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;
|
|
|
|
class SingleRecipeController extends BaseController
|
|
{
|
|
protected $template_name = APPS_PATH . '/Recipes/Templates/single.php';
|
|
|
|
protected function get_model()
|
|
{
|
|
if (isset($this->__model))
|
|
return $this->__model;
|
|
|
|
$this->__model = RecipeModel::get(
|
|
array(
|
|
[
|
|
'name' => 'obj.id',
|
|
'type' => '=',
|
|
'value' => $this->url_context['url_1']
|
|
]
|
|
)
|
|
);
|
|
if (empty($this->__model))
|
|
throw new HttpExceptions\NotFound404('Recipe not found');
|
|
|
|
return $this->__model;
|
|
}
|
|
|
|
public function get_context_data()
|
|
{
|
|
$context = parent::get_context_data();
|
|
$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;
|
|
}
|
|
}
|