TIST-25: filter form on catalog page #13
@ -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::$table_name . '/', 'image');
|
$path = upload_file($file, $this->model_сlass_name::get_table_name() . '/', 'image');
|
||||||
|
|
||||||
if (!empty($path)) {
|
if (!empty($path)) {
|
||||||
$field_value = $path;
|
$field_value = $path;
|
||||||
|
|||||||
@ -2,9 +2,55 @@
|
|||||||
|
|
||||||
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,4 +1,6 @@
|
|||||||
<?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.',
|
||||||
@ -12,173 +14,16 @@ the_header(
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="catalog">
|
<div class="catalog">
|
||||||
<div class="catalog-items">
|
<div class="catalog-items">
|
||||||
<a class="catalog-recipe hover-anim">
|
<?php
|
||||||
<div class="catalog-recipe__image">
|
foreach ($context['recipes'] as $recipe) {
|
||||||
<img src="media/recipe1.png" alt="Recipe 1">
|
the_product_item($recipe);
|
||||||
</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" action="" method="get">
|
<form class="filters-form" method="get">
|
||||||
<div class="categories-filter">
|
<div class="categories-filter">
|
||||||
<h3 class="filters__title">
|
<h3 class="filters__title">
|
||||||
Categories</h3>
|
Categories</h3>
|
||||||
@ -189,42 +34,19 @@ 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' : '' ?>>
|
||||||
<input id="category" type="checkbox" name="category" id="category">
|
<label for="<?= $field_id ?>"><?= $cat->field_name ?></label>
|
||||||
<label for="category">Category</label>
|
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
<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>
|
||||||
@ -237,42 +59,21 @@ 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' : '' ?>>
|
||||||
<input id="category" type="checkbox" name="category" id="category">
|
<label for="<?= $field_id ?>"><?= $ing->field_name ?></label>
|
||||||
<label for="category">Category</label>
|
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
<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>
|
||||||
|
|||||||
15
apps/Recipes/Templates/components/catalog-item.php
Normal file
15
apps/Recipes/Templates/components/catalog-item.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<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>
|
||||||
8
apps/Recipes/components.php
Normal file
8
apps/Recipes/components.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Lycoreco\Apps\Recipes\Models\RecipeModel;
|
||||||
|
|
||||||
|
function the_product_item(RecipeModel $recipe)
|
||||||
|
{
|
||||||
|
require_once APPS_PATH . '/Recipes/Templates/components/catalog-item.php';
|
||||||
|
}
|
||||||
BIN
media/recipes/chana_685f868b8fb94.jpg
Normal file
BIN
media/recipes/chana_685f868b8fb94.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 385 KiB |
Loading…
x
Reference in New Issue
Block a user