Phase 3 complete: - ScontainersRepository: containerDetails, containerSave, containerDelete, scontainerByLang - BannersRepository: bannerDetails, bannerSave, bannerDelete, activeBanners, mainBanner - 4 legacy factories converted to thin wrappers delegating to Domain repos Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
111 lines
3.5 KiB
PHP
111 lines
3.5 KiB
PHP
<?php
|
|
namespace Domain\Scontainers;
|
|
|
|
class ScontainersRepository
|
|
{
|
|
private $db;
|
|
|
|
public function __construct( $db )
|
|
{
|
|
$this->db = $db;
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Odczyt
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function containerDetails( $containerId )
|
|
{
|
|
$container = $this->db->get( 'pp_scontainers', '*', [ 'id' => $containerId ] );
|
|
if ( !$container ) return null;
|
|
|
|
$langs = $this->db->select( 'pp_scontainers_langs', '*', [ 'container_id' => $containerId ] );
|
|
$container['languages'] = [];
|
|
if ( is_array( $langs ) )
|
|
foreach ( $langs as $lang )
|
|
$container['languages'][ $lang['lang_id'] ] = $lang;
|
|
|
|
return $container;
|
|
}
|
|
|
|
public function scontainerByLang( $scontainerId, $langId )
|
|
{
|
|
$cacheKey = "scontainer_details:$scontainerId:$langId";
|
|
if ( $scontainer = \Shared\Cache\CacheHandler::fetch( $cacheKey ) )
|
|
return $scontainer;
|
|
|
|
$scontainer = $this->db->get( 'pp_scontainers', '*', [ 'id' => $scontainerId ] );
|
|
if ( !$scontainer ) return null;
|
|
|
|
$langData = $this->db->select( 'pp_scontainers_langs', '*', [
|
|
'AND' => [ 'container_id' => $scontainerId, 'lang_id' => $langId ]
|
|
] );
|
|
$scontainer['languages'] = is_array( $langData ) ? $langData : [];
|
|
|
|
\Shared\Cache\CacheHandler::store( $cacheKey, $scontainer );
|
|
return $scontainer;
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Zapis / usuwanie
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function containerSave( $containerId, $title, $text, $status, $showTitle, $src, $html )
|
|
{
|
|
$languages = $this->db->select( 'pp_langs', '*', [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
|
if ( !is_array( $languages ) ) $languages = [];
|
|
$langCount = count( $languages );
|
|
|
|
if ( !$containerId )
|
|
{
|
|
$this->db->insert( 'pp_scontainers', [
|
|
'status' => $status == 'on' ? 1 : 0,
|
|
'show_title' => $showTitle == 'on' ? 1 : 0,
|
|
'src' => $src,
|
|
] );
|
|
$containerId = $this->db->id();
|
|
if ( !$containerId ) return false;
|
|
|
|
foreach ( $languages as $i => $lang )
|
|
{
|
|
$this->db->insert( 'pp_scontainers_langs', [
|
|
'container_id' => $containerId,
|
|
'lang_id' => $lang['id'],
|
|
'title' => $langCount > 1 ? $title[ $i ] : $title,
|
|
'text' => $langCount > 1 ? $text[ $i ] : $text,
|
|
'html' => $langCount > 1 ? $html[ $i ] : $html,
|
|
] );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$this->db->update( 'pp_scontainers', [
|
|
'status' => $status == 'on' ? 1 : 0,
|
|
'show_title' => $showTitle == 'on' ? 1 : 0,
|
|
'src' => $src,
|
|
], [ 'id' => $containerId ] );
|
|
|
|
$this->db->delete( 'pp_scontainers_langs', [ 'container_id' => $containerId ] );
|
|
|
|
foreach ( $languages as $i => $lang )
|
|
{
|
|
$this->db->insert( 'pp_scontainers_langs', [
|
|
'container_id' => $containerId,
|
|
'lang_id' => $lang['id'],
|
|
'title' => $langCount > 1 ? $title[ $i ] : $title,
|
|
'text' => $langCount > 1 ? $text[ $i ] : $text,
|
|
'html' => $langCount > 1 ? $html[ $i ] : $html,
|
|
] );
|
|
}
|
|
}
|
|
|
|
\S::delete_cache();
|
|
return $containerId;
|
|
}
|
|
|
|
public function containerDelete( $containerId )
|
|
{
|
|
return $this->db->delete( 'pp_scontainers', [ 'id' => $containerId ] );
|
|
}
|
|
}
|