Files
shopPRO/autoload/front/factory/class.Layouts.php
Jacek Pyziak 8e97413361 ver. 0.282: Banners frontend migration, Cache cleanup, Shared\Cache namespace
- Banners frontend: front\Views\Banners (new), BannerRepository +2 frontend methods,
  front\view\Site przepięty, usunięte front\factory\Banners i front\view\Banners
- Cache cleanup: eliminacja legacy class.Cache.php (file-based cache),
  13 metod front\factory przepiętych z \Cache::fetch/store na CacheHandler
- Shared\Cache namespace: CacheHandler i RedisConnection przeniesione do Shared\Cache\,
  60 odwołań CacheHandler i 12 odwołań RedisConnection przepiętych,
  usunięte backward-compat wrappery class.CacheHandler.php i class.RedisConnection.php
- Naprawione rozbieżności kluczy cache (random_products, category_name)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 21:25:50 +01:00

173 lines
4.8 KiB
PHP

<?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;
}
}