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:
2026-02-17 08:21:53 +01:00
parent 92397fce05
commit e2a821a10c
27 changed files with 697 additions and 413 deletions

View File

@@ -1,172 +0,0 @@
<?php
namespace front\factory;
class Layouts
{
static public function category_default_layout()
{
global $mdb;
return $mdb -> get( 'pp_layouts', 'id', [ 'categories_default' => 1 ] );
}
static public function default_layout()
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Layouts::default_layout";
$objectData = $cacheHandler -> get( $cacheKey );
if ( $objectData )
{
$cachedLayout = @unserialize( $objectData );
if ( is_array( $cachedLayout ) and !empty( $cachedLayout ) )
return $cachedLayout;
$cacheHandler -> delete( $cacheKey );
}
$layout = $mdb -> get( 'pp_layouts', '*', [ 'status' => 1 ] );
$cacheHandler -> set( $cacheKey, $layout );
return $layout;
}
static public function product_layout( $product_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Layouts::product_layout:$product_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( $objectData )
{
$cachedLayout = @unserialize( $objectData );
if ( is_array( $cachedLayout ) and !empty( $cachedLayout ) )
return $cachedLayout;
$cacheHandler -> delete( $cacheKey );
}
$layoutRows = $mdb -> 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)$product_id . "
ORDER BY pp_layouts.id DESC"
) -> fetchAll( \PDO::FETCH_ASSOC );
if ( is_array( $layoutRows ) and isset( $layoutRows[0] ) )
$layout = $layoutRows[0];
else
{
$layoutRows = $mdb -> 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)$product_id . "
ORDER BY pp_shop_products_categories.o ASC, pp_layouts.id DESC"
) -> fetchAll( \PDO::FETCH_ASSOC );
if ( is_array( $layoutRows ) and isset( $layoutRows[0] ) )
$layout = $layoutRows[0];
else
$layout = $mdb -> get( 'pp_layouts', '*', [ 'categories_default' => 1 ] );
}
if ( !$layout )
$layout = $mdb -> get( 'pp_layouts', '*', [ 'status' => 1 ] );
$cacheHandler -> set( $cacheKey, $layout );
return $layout;
}
static public function article_layout( $article_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Layouts::article_layout:$article_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$layout = $mdb -> get( 'pp_layouts', [ '[><]pp_articles' => [ 'id' => 'layout_id' ] ], '*', [ 'pp_articles.id' => (int)$article_id ] );
$cacheHandler -> set( $cacheKey, $layout );
}
else
{
return unserialize( $objectData );
}
return $layout;
}
static public function category_layout( $category_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Layouts::category_layout:$category_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( $objectData )
{
$cachedLayout = @unserialize( $objectData );
if ( is_array( $cachedLayout ) and !empty( $cachedLayout ) )
return $cachedLayout;
$cacheHandler -> delete( $cacheKey );
}
$layoutRows = $mdb -> 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)$category_id . "
ORDER BY pp_layouts.id DESC"
) -> fetchAll( \PDO::FETCH_ASSOC );
if ( is_array( $layoutRows ) and isset( $layoutRows[0] ) )
$layout = $layoutRows[0];
else
$layout = $mdb -> get( 'pp_layouts', '*', [ 'categories_default' => 1 ] );
if ( !$layout )
$layout = $mdb -> get( 'pp_layouts', '*', [ 'status' => 1 ] );
$cacheHandler -> set( $cacheKey, $layout );
return $layout;
}
static public function active_layout( $page_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Layouts::active_layout:$page_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$layout = $mdb -> get( 'pp_layouts', [ '[><]pp_layouts_pages' => [ 'id' => 'layout_id' ] ], '*', [ 'page_id' => (int)$page_id ] );
if ( !$layout )
$layout = $mdb -> get( 'pp_layouts', '*', [ 'status' => 1 ] );
$cacheHandler -> set( $cacheKey, $layout );
}
else
{
return unserialize( $objectData );
}
return $layout;
}
}

View File

@@ -1,59 +0,0 @@
<?php
namespace front\factory;
class Menu
{
public static function menu_details( $menu_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Menu::menu_details:$menu_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$menu = $mdb -> get( 'pp_menus', '*', [ 'id' => (int)$menu_id ] );
$menu['pages'] = self::menu_pages( $menu_id );
$cacheHandler -> set( $cacheKey, $menu );
}
else
{
return unserialize( $objectData );
}
return $menu;
}
public static function menu_pages( $menu_id, $parent_id = null )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Menu::menu_pages:$menu_id:$parent_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$results = $mdb -> select( 'pp_pages', [ 'id' ], [ 'AND' => [ 'status' => 1, 'menu_id' => (int)$menu_id, 'parent_id' => $parent_id ], 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) ) foreach ( $results as $row )
{
$page = \front\factory\Pages::page_details( $row['id'] );
$page['pages'] = self::menu_pages( $menu_id, $row['id'] );
$pages[] = $page;
}
$cacheHandler -> set( $cacheKey, $pages );
}
else
{
return unserialize($objectData);
}
return $pages;
}
}

View File

@@ -1,92 +0,0 @@
<?php
namespace front\factory;
class Pages
{
public static function page_sort( $page_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Pages::page_sort:$page_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$sort = $mdb -> get( 'pp_pages', 'sort_type', [ 'id' => $page_id ] );
$cacheHandler -> set( $cacheKey, $sort );
}
else
{
return unserialize( $objectData );
}
return $sort;
}
public static function lang_url( $page_id, $lang_id )
{
$page = self::page_details( $page_id, $lang_id );
$page['language']['seo_link'] ? $url = '/' . $page['language']['seo_link'] : $url = '/s-' . $page['id'] . '-' . \Shared\Helpers\Helpers::seo( $page['language']['title'] );
if ( $lang_id != ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->defaultLanguage() and $url != '#' )
$url = '/' . $lang_id . $url;
return $url;
}
public static function page_details( $id = '', $lang_tmp = '' )
{
global $mdb, $lang_id;
if ( !$id )
$id = self::main_page_id();
if ( $lang_tmp )
$lang_id = $lang_tmp;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Pages::page_details:$id:$lang_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData ) {
$page = $mdb->get('pp_pages', '*', ['id' => (int)$id]);
$page['language'] = $mdb->get('pp_pages_langs', '*', ['AND' => ['page_id' => (int)$id, 'lang_id' => $lang_id]]);
$cacheHandler->set($cacheKey, $page);
} else {
return unserialize($objectData);
}
return $page;
}
public static function main_page_id()
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Pages::main_page_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$id = $mdb -> get( 'pp_pages', 'id', [ 'AND' => [ 'status' => 1, 'start' => 1 ] ] );
if ( !$id )
$id = $mdb -> get( 'pp_pages', 'id', [ 'status' => 1, 'ORDER' => [ 'menu_id' => 'ASC', 'o' => 'ASC' ], 'LIMIT' => 1 ] );
$cacheHandler -> set( $cacheKey, $id );
}
else
{
return unserialize($objectData);
}
return $id;
}
}