ver. 0.286: Layouts, Menu, Pages frontend migration to Domain
- Add 6 frontend methods to LayoutsRepository (Redis cache, 3-level fallback) - Add 6 frontend methods to PagesRepository (Redis cache, recursive pages) - Create front\Views\Menu (clean VIEW replacing front\view\Menu) - Delete front\factory\Layouts, Menu, Pages + front\view\Menu + dead submenu.php - Fix null $lang_id TypeError in check_url_params() (remove string type hint + ?? '') - Optimize Helpers::htacces() from 3 layout calls to 1 - Tests: 470 OK, 1484 assertions (+16 new) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -227,6 +227,183 @@ class LayoutsRepository
|
||||
];
|
||||
}
|
||||
|
||||
// ── Frontend methods ──────────────────────────────────────────
|
||||
|
||||
public function categoryDefaultLayoutId()
|
||||
{
|
||||
return $this->db->get('pp_layouts', 'id', ['categories_default' => 1]);
|
||||
}
|
||||
|
||||
public function getDefaultLayout(): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = 'LayoutsRepository::getDefaultLayout';
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached) && !empty($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layout = $this->db->get('pp_layouts', '*', ['status' => 1]);
|
||||
if (!is_array($layout) || empty($layout)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $layout);
|
||||
return $layout;
|
||||
}
|
||||
|
||||
public function getProductLayout(int $productId): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "LayoutsRepository::getProductLayout:$productId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached) && !empty($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layoutRows = $this->db->query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_shop_products ON pp_layouts.id = pp_shop_products.layout_id
|
||||
WHERE pp_shop_products.id = " . (int)$productId . "
|
||||
ORDER BY pp_layouts.id DESC"
|
||||
)->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
if (is_array($layoutRows) && isset($layoutRows[0])) {
|
||||
$layout = $layoutRows[0];
|
||||
} else {
|
||||
$layoutRows = $this->db->query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_layouts_categories ON pp_layouts.id = pp_layouts_categories.layout_id
|
||||
JOIN pp_shop_products_categories ON pp_shop_products_categories.category_id = pp_layouts_categories.category_id
|
||||
WHERE pp_shop_products_categories.product_id = " . (int)$productId . "
|
||||
ORDER BY pp_shop_products_categories.o ASC, pp_layouts.id DESC"
|
||||
)->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
if (is_array($layoutRows) && isset($layoutRows[0])) {
|
||||
$layout = $layoutRows[0];
|
||||
} else {
|
||||
$layout = $this->db->get('pp_layouts', '*', ['categories_default' => 1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$layout) {
|
||||
$layout = $this->db->get('pp_layouts', '*', ['status' => 1]);
|
||||
}
|
||||
|
||||
if (!is_array($layout) || empty($layout)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $layout);
|
||||
return $layout;
|
||||
}
|
||||
|
||||
public function getArticleLayout(int $articleId): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "LayoutsRepository::getArticleLayout:$articleId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layout = $this->db->get('pp_layouts', ['[><]pp_articles' => ['id' => 'layout_id']], '*', ['pp_articles.id' => (int)$articleId]);
|
||||
|
||||
if (is_array($layout)) {
|
||||
$cacheHandler->set($cacheKey, $layout);
|
||||
return $layout;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getCategoryLayout(int $categoryId): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "LayoutsRepository::getCategoryLayout:$categoryId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached) && !empty($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layoutRows = $this->db->query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_layouts_categories ON pp_layouts.id = pp_layouts_categories.layout_id
|
||||
WHERE pp_layouts_categories.category_id = " . (int)$categoryId . "
|
||||
ORDER BY pp_layouts.id DESC"
|
||||
)->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
if (is_array($layoutRows) && isset($layoutRows[0])) {
|
||||
$layout = $layoutRows[0];
|
||||
} else {
|
||||
$layout = $this->db->get('pp_layouts', '*', ['categories_default' => 1]);
|
||||
}
|
||||
|
||||
if (!$layout) {
|
||||
$layout = $this->db->get('pp_layouts', '*', ['status' => 1]);
|
||||
}
|
||||
|
||||
if (!is_array($layout) || empty($layout)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $layout);
|
||||
return $layout;
|
||||
}
|
||||
|
||||
public function getActiveLayout(int $pageId): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "LayoutsRepository::getActiveLayout:$pageId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layout = $this->db->get('pp_layouts', ['[><]pp_layouts_pages' => ['id' => 'layout_id']], '*', ['page_id' => (int)$pageId]);
|
||||
|
||||
if (!$layout) {
|
||||
$layout = $this->db->get('pp_layouts', '*', ['status' => 1]);
|
||||
}
|
||||
|
||||
if (is_array($layout)) {
|
||||
$cacheHandler->set($cacheKey, $layout);
|
||||
return $layout;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// ── Private helpers ──────────────────────────────────────────
|
||||
|
||||
private function syncPages(int $layoutId, $pages): void
|
||||
{
|
||||
foreach ($this->normalizeIds($pages) as $pageId) {
|
||||
|
||||
Reference in New Issue
Block a user