[MVC] Полная миграция на MVC архитектуру

- Создано ядро MVC: App, Router, Controller, Model, View, Database
- Созданы модели: User, Product, Category, Cart, Order
- Созданы контроллеры: Home, Auth, Product, Cart, Order, Page, Admin
- Созданы layouts и partials для представлений
- Добавлены все views для страниц
- Настроена маршрутизация с чистыми URL
- Обновлена конфигурация Docker и Apache для mod_rewrite
- Добавлена единая точка входа public/index.php
This commit is contained in:
kirill.khorkov
2026-01-03 11:48:14 +03:00
parent 3f257120fa
commit d2c15ec37f
53 changed files with 8650 additions and 30 deletions

View File

@@ -0,0 +1,102 @@
<?php
namespace App\Controllers;
use App\Core\Controller;
use App\Models\Product;
use App\Models\Category;
/**
* ProductController - контроллер товаров и каталога
*/
class ProductController extends Controller
{
private Product $productModel;
private Category $categoryModel;
public function __construct()
{
$this->productModel = new Product();
$this->categoryModel = new Category();
}
/**
* Каталог товаров
*/
public function catalog(): void
{
$this->requireAuth();
$user = $this->getCurrentUser();
$isAdmin = $this->isAdmin();
// Получаем параметры фильтрации
$filters = [
'category_id' => (int) $this->getQuery('category', 0),
'search' => $this->getQuery('search', ''),
'min_price' => (int) $this->getQuery('min_price', 0),
'max_price' => (int) $this->getQuery('max_price', 1000000),
'colors' => $this->getQuery('colors', []),
'materials' => $this->getQuery('materials', [])
];
$showAll = $isAdmin && $this->getQuery('show_all') === '1';
// Получаем данные
$categories = $this->categoryModel->getActive();
$products = $showAll
? $this->productModel->getAllForAdmin(true)
: $this->productModel->getAvailable($filters);
$availableColors = $this->productModel->getAvailableColors();
$availableMaterials = $this->productModel->getAvailableMaterials();
// Подкатегории для выбранной категории
$subcategories = [];
if ($filters['category_id'] > 0) {
$subcategories = $this->categoryModel->getChildren($filters['category_id']);
}
$this->view('products/catalog', [
'user' => $user,
'isAdmin' => $isAdmin,
'categories' => $categories,
'subcategories' => $subcategories,
'products' => $products,
'filters' => $filters,
'showAll' => $showAll,
'availableColors' => $availableColors,
'availableMaterials' => $availableMaterials,
'success' => $this->getQuery('success'),
'error' => $this->getQuery('error')
]);
}
/**
* Страница товара
*/
public function show(int $id): void
{
$this->requireAuth();
$product = $this->productModel->findWithCategory($id);
if (!$product || (!$product['is_available'] && !$this->isAdmin())) {
$this->redirect('/catalog?error=product_not_found');
return;
}
$similarProducts = $this->productModel->getSimilar(
$id,
$product['category_id']
);
$this->view('products/show', [
'product' => $product,
'similarProducts' => $similarProducts,
'user' => $this->getCurrentUser(),
'isAdmin' => $this->isAdmin()
]);
}
}