diff --git a/apps/Admin/Controllers/Abstract/AdminSingleController.php b/apps/Admin/Controllers/Abstract/AdminSingleController.php index b672b9a..ef4c618 100644 --- a/apps/Admin/Controllers/Abstract/AdminSingleController.php +++ b/apps/Admin/Controllers/Abstract/AdminSingleController.php @@ -139,7 +139,7 @@ abstract class AdminSingleController extends AdminBaseController case 'image': $file = $_FILES[$field['model_field']]; if (isset($file)) { - $path = upload_file($file, $this->model_сlass_name::$table_name . '/', 'image'); + $path = upload_file($file, $this->model_сlass_name::get_table_name() . '/', 'image'); if (!empty($path)) { $field_value = $path; diff --git a/apps/Recipes/Controllers/CatalogController.php b/apps/Recipes/Controllers/CatalogController.php index 4bcbc7b..5a63e84 100644 --- a/apps/Recipes/Controllers/CatalogController.php +++ b/apps/Recipes/Controllers/CatalogController.php @@ -2,9 +2,55 @@ namespace Lycoreco\Apps\Recipes\Controllers; +use Lycoreco\Apps\Recipes\Models\{ + CategoryModel, + IngredientModel, + RecipeModel +}; use Lycoreco\Includes\BaseController; +define('CATALOG_MAX_RECIPES', 20); + class CatalogController extends BaseController { protected $template_name = APPS_PATH . '/Recipes/Templates/catalog.php'; -} \ No newline at end of file + + public function get_context_data() + { + $context = parent::get_context_data(); + + $context["page"] = isset($_GET['page']) ? (int)$_GET['page'] : 1; + + $context['categories'] = CategoryModel::filter(sort_by: ['obj.name'], count: 200); + $context['ingredients'] = IngredientModel::filter(sort_by: ['obj.name'], count: 200); + + // GET request to filter catalog + $fields = array(); + + $category_id = isset($_GET['category']) ? $_GET['category'] : null; + if ($category_id) { + $fields[] = array( + 'name' => 'obj.category_id', + 'type' => '=', + 'value' => $category_id + ); + } + $ingredient_ids = isset($_GET['ingredient']) ? $_GET['ingredient'] : null; + if ($ingredient_ids) { + $fields[] = array( + 'name' => 'tb2.ingredient_id', + 'type' => 'IN', + 'value' => $ingredient_ids, + 'is_having' => true + ); + } + + $context['recipes'] = RecipeModel::filter( + $fields, + ['-obj.created_at'], + CATALOG_MAX_RECIPES + ); + + return $context; + } +} diff --git a/apps/Recipes/Templates/catalog.php b/apps/Recipes/Templates/catalog.php index 4674e78..1283094 100644 --- a/apps/Recipes/Templates/catalog.php +++ b/apps/Recipes/Templates/catalog.php @@ -1,4 +1,6 @@
-
-
-
-
-
-
-
-
-