Merge pull request 'TIST-11: Create filter with ManyToMany relation between Recipe and Ingredients' (#10) from TIST-11 into develop
Reviewed-on: #10 Reviewed-by: greendavid004 <davidkatrinka1995@gmail.com>
This commit is contained in:
commit
318a40c222
@ -2,9 +2,40 @@
|
|||||||
|
|
||||||
namespace Lycoreco\Apps\Recipes\Controllers;
|
namespace Lycoreco\Apps\Recipes\Controllers;
|
||||||
|
|
||||||
|
use Lycoreco\Apps\Recipes\Models\RecipeModel;
|
||||||
use Lycoreco\Includes\BaseController;
|
use Lycoreco\Includes\BaseController;
|
||||||
|
use Lycoreco\Includes\Routing\HttpExceptions;
|
||||||
|
|
||||||
class SingleRecipeController extends BaseController
|
class SingleRecipeController extends BaseController
|
||||||
{
|
{
|
||||||
protected $template_name = APPS_PATH . '/Recipes/Templates/single.php';
|
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();
|
||||||
|
|
||||||
|
$context['recipe'] = $this->get_model();
|
||||||
|
|
||||||
|
return $context;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -15,10 +15,27 @@ class RecipeModel extends BaseModel
|
|||||||
public $field_status;
|
public $field_status;
|
||||||
public $field_created_at;
|
public $field_created_at;
|
||||||
|
|
||||||
|
public $category_name;
|
||||||
|
|
||||||
const STATUS = [[ 'publish', 'Publish' ], [ 'pending', 'Pending' ]];
|
const STATUS = [[ 'publish', 'Publish' ], [ 'pending', 'Pending' ]];
|
||||||
|
|
||||||
static protected $search_fields = ['obj.title'];
|
static protected $search_fields = ['obj.title'];
|
||||||
static protected $table_name = 'recipes';
|
static protected $table_name = 'recipes';
|
||||||
|
|
||||||
|
static protected $additional_fields = array(
|
||||||
|
[
|
||||||
|
'field' => [
|
||||||
|
'tb1.name AS category_name'
|
||||||
|
],
|
||||||
|
'join_table' => 'ingredients tb1 ON tb1.id = obj.category_id'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'field' => [
|
||||||
|
|
||||||
|
],
|
||||||
|
'join_table' => 'recipe_ingredients tb2 ON tb2.recipe_id = obj.id'
|
||||||
|
]
|
||||||
|
);
|
||||||
static protected $table_fields = [
|
static protected $table_fields = [
|
||||||
'id' => 'int',
|
'id' => 'int',
|
||||||
'title' => 'string',
|
'title' => 'string',
|
||||||
|
|||||||
@ -1 +1,3 @@
|
|||||||
Single Recipe item
|
<pre>
|
||||||
|
<?php var_dump($context['recipe']); ?>
|
||||||
|
</pre>
|
||||||
@ -4,6 +4,6 @@ use Lycoreco\Apps\Recipes\Controllers;
|
|||||||
use Lycoreco\Includes\Routing\Path;
|
use Lycoreco\Includes\Routing\Path;
|
||||||
|
|
||||||
$recipes_urls = [
|
$recipes_urls = [
|
||||||
new Path('/recipe/[:string]', new Controllers\SingleRecipeController(), 'single'),
|
new Path('/recipe/[:int]', new Controllers\SingleRecipeController(), 'single'),
|
||||||
new Path('/catalog', new Controllers\CatalogController(), 'catalog'),
|
new Path('/catalog', new Controllers\CatalogController(), 'catalog'),
|
||||||
];
|
];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user