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>
This commit is contained in:
2026-02-16 21:25:50 +01:00
parent 53d945843a
commit 8e97413361
54 changed files with 594 additions and 346 deletions

View File

@@ -312,4 +312,84 @@ class BannerRepository
$this->db->insert('pp_banners_langs', $translationData);
}
// ─── Frontend methods ───────────────────────────────────────────
/**
* Pobiera aktywne banery (home_page = 0) z filtrowaniem dat, z Redis cache.
* Zwraca dane w formacie zgodnym z szablonami: $banner['languages'] = płaski wiersz.
*/
public function banners(string $langId): ?array
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "BannerRepository::banners:{$langId}";
$objectData = $cacheHandler->get($cacheKey);
if ($objectData) {
return unserialize($objectData);
}
$today = date('Y-m-d');
$results = $this->db->query(
"SELECT id, name FROM pp_banners "
. "WHERE status = 1 "
. "AND (date_start <= '{$today}' OR date_start IS NULL) "
. "AND (date_end >= '{$today}' OR date_end IS NULL) "
. "AND home_page = 0"
)->fetchAll();
$banners = null;
if (is_array($results) && !empty($results)) {
foreach ($results as $row) {
$row['languages'] = $this->db->get('pp_banners_langs', '*', [
'AND' => ['id_banner' => (int)$row['id'], 'id_lang' => $langId]
]);
$banners[] = $row;
}
}
$cacheHandler->set($cacheKey, $banners);
return $banners;
}
/**
* Pobiera glowny baner (home_page = 1) z filtrowaniem dat, z Redis cache.
* Zwraca dane w formacie zgodnym z szablonami: $banner['languages'] = plaski wiersz.
*/
public function mainBanner(string $langId): ?array
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "BannerRepository::mainBanner:{$langId}";
$objectData = $cacheHandler->get($cacheKey);
if ($objectData) {
return unserialize($objectData);
}
$today = date('Y-m-d');
$results = $this->db->query(
"SELECT * FROM pp_banners "
. "WHERE status = 1 "
. "AND (date_start <= '{$today}' OR date_start IS NULL) "
. "AND (date_end >= '{$today}' OR date_end IS NULL) "
. "AND home_page = 1 "
. "ORDER BY date_end ASC "
. "LIMIT 1"
)->fetchAll();
$banner = null;
if (is_array($results) && !empty($results)) {
$banner = $results[0];
$banner['languages'] = $this->db->get('pp_banners_langs', '*', [
'AND' => ['id_banner' => (int)$banner['id'], 'id_lang' => $langId]
]);
}
$cacheHandler->set($cacheKey, $banner);
return $banner;
}
}