Compare commits
No commits in common. "a2c2b31597c90ebb9572662ab69da5b81dd58895" and "783e9515706ceb18f390a4c49cec478dd4e4df44" have entirely different histories.
a2c2b31597
...
783e951570
@ -139,7 +139,7 @@ abstract class AdminSingleController extends AdminBaseController
|
|||||||
case 'image':
|
case 'image':
|
||||||
$file = $_FILES[$field['model_field']];
|
$file = $_FILES[$field['model_field']];
|
||||||
if (isset($file)) {
|
if (isset($file)) {
|
||||||
$path = upload_file($file, $this->model_сlass_name::get_table_name() . '/', 'image');
|
$path = upload_file($file, $this->model_сlass_name::$table_name . '/', 'image');
|
||||||
|
|
||||||
if (!empty($path)) {
|
if (!empty($path)) {
|
||||||
$field_value = $path;
|
$field_value = $path;
|
||||||
|
|||||||
@ -2,55 +2,9 @@
|
|||||||
|
|
||||||
namespace Lycoreco\Apps\Recipes\Controllers;
|
namespace Lycoreco\Apps\Recipes\Controllers;
|
||||||
|
|
||||||
use Lycoreco\Apps\Recipes\Models\{
|
|
||||||
CategoryModel,
|
|
||||||
IngredientModel,
|
|
||||||
RecipeModel
|
|
||||||
};
|
|
||||||
use Lycoreco\Includes\BaseController;
|
use Lycoreco\Includes\BaseController;
|
||||||
|
|
||||||
define('CATALOG_MAX_RECIPES', 20);
|
|
||||||
|
|
||||||
class CatalogController extends BaseController
|
class CatalogController extends BaseController
|
||||||
{
|
{
|
||||||
protected $template_name = APPS_PATH . '/Recipes/Templates/catalog.php';
|
protected $template_name = APPS_PATH . '/Recipes/Templates/catalog.php';
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,6 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once APPS_PATH . '/Recipes/components.php';
|
|
||||||
|
|
||||||
the_header(
|
the_header(
|
||||||
'Recipes',
|
'Recipes',
|
||||||
'Explore our delicious recipes and find your next favorite dish.',
|
'Explore our delicious recipes and find your next favorite dish.',
|
||||||
@ -14,16 +12,173 @@ the_header(
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="catalog">
|
<div class="catalog">
|
||||||
<div class="catalog-items">
|
<div class="catalog-items">
|
||||||
<?php
|
<a class="catalog-recipe hover-anim">
|
||||||
foreach ($context['recipes'] as $recipe) {
|
<div class="catalog-recipe__image">
|
||||||
the_product_item($recipe);
|
<img src="media/recipe1.png" alt="Recipe 1">
|
||||||
}
|
</div>
|
||||||
?>
|
<div class="catalog-recipe__info">
|
||||||
|
<div class="catalog-recipe__title">
|
||||||
|
<h3>Pizza</h3>
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__meta meta">
|
||||||
|
<div class="catalog-recipe__category">
|
||||||
|
Lunch
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__ingredients">
|
||||||
|
Tomatoes, Pepperoni
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a class="catalog-recipe hover-anim">
|
||||||
|
<div class="catalog-recipe__image">
|
||||||
|
<img src="media/recipe1.png" alt="Recipe 1">
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__info">
|
||||||
|
<div class="catalog-recipe__title">
|
||||||
|
<h3>Pizza</h3>
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__meta meta">
|
||||||
|
<div class="catalog-recipe__category">
|
||||||
|
Lunch
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__ingredients">
|
||||||
|
Tomatoes, Pepperoni
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a class="catalog-recipe hover-anim">
|
||||||
|
<div class="catalog-recipe__image">
|
||||||
|
<img src="media/recipe1.png" alt="Recipe 1">
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__info">
|
||||||
|
<div class="catalog-recipe__title">
|
||||||
|
<h3>Pizza</h3>
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__meta meta">
|
||||||
|
<div class="catalog-recipe__category">
|
||||||
|
Lunch
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__ingredients">
|
||||||
|
Tomatoes, Pepperoni
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a class="catalog-recipe hover-anim">
|
||||||
|
<div class="catalog-recipe__image">
|
||||||
|
<img src="media/recipe1.png" alt="Recipe 1">
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__info">
|
||||||
|
<div class="catalog-recipe__title">
|
||||||
|
<h3>Pizza</h3>
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__meta meta">
|
||||||
|
<div class="catalog-recipe__category">
|
||||||
|
Lunch
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__ingredients">
|
||||||
|
Tomatoes, Pepperoni
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a class="catalog-recipe hover-anim">
|
||||||
|
<div class="catalog-recipe__image">
|
||||||
|
<img src="media/recipe1.png" alt="Recipe 1">
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__info">
|
||||||
|
<div class="catalog-recipe__title">
|
||||||
|
<h3>Pizza</h3>
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__meta meta">
|
||||||
|
<div class="catalog-recipe__category">
|
||||||
|
Lunch
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__ingredients">
|
||||||
|
Tomatoes, Pepperoni
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a class="catalog-recipe hover-anim">
|
||||||
|
<div class="catalog-recipe__image">
|
||||||
|
<img src="media/recipe1.png" alt="Recipe 1">
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__info">
|
||||||
|
<div class="catalog-recipe__title">
|
||||||
|
<h3>Pizza</h3>
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__meta meta">
|
||||||
|
<div class="catalog-recipe__category">
|
||||||
|
Lunch
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__ingredients">
|
||||||
|
Tomatoes, Pepperoni
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a class="catalog-recipe hover-anim">
|
||||||
|
<div class="catalog-recipe__image">
|
||||||
|
<img src="media/recipe1.png" alt="Recipe 1">
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__info">
|
||||||
|
<div class="catalog-recipe__title">
|
||||||
|
<h3>Pizza</h3>
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__meta meta">
|
||||||
|
<div class="catalog-recipe__category">
|
||||||
|
Lunch
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__ingredients">
|
||||||
|
Tomatoes, Pepperoni
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a class="catalog-recipe hover-anim">
|
||||||
|
<div class="catalog-recipe__image">
|
||||||
|
<img src="media/recipe1.png" alt="Recipe 1">
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__info">
|
||||||
|
<div class="catalog-recipe__title">
|
||||||
|
<h3>Pizza</h3>
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__meta meta">
|
||||||
|
<div class="catalog-recipe__category">
|
||||||
|
Lunch
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__ingredients">
|
||||||
|
Tomatoes, Pepperoni
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a class="catalog-recipe hover-anim">
|
||||||
|
<div class="catalog-recipe__image">
|
||||||
|
<img src="media/recipe1.png" alt="Recipe 1">
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__info">
|
||||||
|
<div class="catalog-recipe__title">
|
||||||
|
<h3>Pizza</h3>
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__meta meta">
|
||||||
|
<div class="catalog-recipe__category">
|
||||||
|
Lunch
|
||||||
|
</div>
|
||||||
|
<div class="catalog-recipe__ingredients">
|
||||||
|
Tomatoes, Pepperoni
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="filters-container">
|
<div class="filters-container">
|
||||||
<div class="filters">
|
<div class="filters">
|
||||||
<div class="filters-inner">
|
<div class="filters-inner">
|
||||||
<form class="filters-form" method="get">
|
<form class="filters-form" action="" method="get">
|
||||||
<div class="categories-filter">
|
<div class="categories-filter">
|
||||||
<h3 class="filters__title">
|
<h3 class="filters__title">
|
||||||
Categories</h3>
|
Categories</h3>
|
||||||
@ -34,19 +189,42 @@ the_header(
|
|||||||
<!-- All labels and ids are the same for template design purposes (all labels point to same checkbox) -->
|
<!-- All labels and ids are the same for template design purposes (all labels point to same checkbox) -->
|
||||||
<div class="filters-checkboxes">
|
<div class="filters-checkboxes">
|
||||||
<ul>
|
<ul>
|
||||||
<?php foreach ($context['categories'] as $cat):
|
|
||||||
$field_id = 'cat_' . $cat->get_id();
|
|
||||||
|
|
||||||
$is_checked = false;
|
|
||||||
$category = $_GET['category'] ?? null;
|
|
||||||
if($category == $cat->get_id())
|
|
||||||
$is_checked = true;
|
|
||||||
?>
|
|
||||||
<li>
|
<li>
|
||||||
<input id="<?= $field_id ?>" type="radio" name="category" value="<?= $cat->get_id() ?>" <?= $is_checked ? 'checked' : '' ?>>
|
|
||||||
<label for="<?= $field_id ?>"><?= $cat->field_name ?></label>
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach; ?>
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -59,21 +237,42 @@ the_header(
|
|||||||
</div>
|
</div>
|
||||||
<div class="filters-checkboxes">
|
<div class="filters-checkboxes">
|
||||||
<ul>
|
<ul>
|
||||||
<?php foreach ($context['ingredients'] as $ing):
|
|
||||||
$field_id = 'ing_' . $ing->get_id();
|
|
||||||
|
|
||||||
$is_checked = false;
|
|
||||||
$ingredients = $_GET['ingredient'] ?? null;
|
|
||||||
if($ingredients) {
|
|
||||||
if (in_array($ing->get_id(), $ingredients))
|
|
||||||
$is_checked = true;
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<li>
|
<li>
|
||||||
<input id="<?= $field_id ?>" type="checkbox" name="ingredient[]" value="<?= $ing->get_id() ?>" <?= $is_checked ? 'checked' : '' ?>>
|
|
||||||
<label for="<?= $field_id ?>"><?= $ing->field_name ?></label>
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach; ?>
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
|
||||||
|
<input id="category" type="checkbox" name="category" id="category">
|
||||||
|
<label for="category">Category</label>
|
||||||
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
<a href="<?php the_permalink('recipes:single', [$recipe->get_id()]) ?>" class="catalog-recipe hover-anim">
|
|
||||||
<div class="catalog-recipe__image">
|
|
||||||
<img src="<?= $recipe->get_image_url() ?>" alt="<?= $recipe->field_title ?>">
|
|
||||||
</div>
|
|
||||||
<div class="catalog-recipe__info">
|
|
||||||
<div class="catalog-recipe__title">
|
|
||||||
<h3><?= $recipe->field_title ?></h3>
|
|
||||||
</div>
|
|
||||||
<div class="catalog-recipe__meta meta">
|
|
||||||
<div class="catalog-recipe__category">
|
|
||||||
<?= $recipe->category_name ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Lycoreco\Apps\Recipes\Models\RecipeModel;
|
|
||||||
|
|
||||||
function the_product_item(RecipeModel $recipe)
|
|
||||||
{
|
|
||||||
require_once APPS_PATH . '/Recipes/Templates/components/catalog-item.php';
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 385 KiB |
Loading…
x
Reference in New Issue
Block a user