diff --git a/.paul/PROJECT.md b/.paul/PROJECT.md
index d079c60..d469645 100644
--- a/.paul/PROJECT.md
+++ b/.paul/PROJECT.md
@@ -7,10 +7,11 @@ Autorski system CMS z panelem administracyjnym (17 modułów admin, 13 modułów
Autorski system CMS umożliwiający zarządzanie treściami i stronami internetowymi.
## Already Completed
-- Domain (6 repos): Articles, Languages, Layouts, Pages, Settings, User
-- Shared (5 modules): Cache, Helpers, Html, Image, Tpl
+- Domain (8 repos): Articles, Languages, Layouts, Pages, Settings, User, Scontainers, Banners
+- Shared (7 modules): Cache, Helpers, Html, Image, Tpl, Email, Security
- Form Edit System: FormEditViewModel, multi-tab, validation, persistence
- PHPUnit base: Bootstrap, 3 test files
+- Wrapper delegation pattern: legacy factories delegate to Domain repositories
## Requirements
@@ -45,3 +46,4 @@ Autorski system CMS umożliwiający zarządzanie treściami i stronami interneto
---
*Created: 2026-04-04*
+*Last updated: 2026-04-04 after Phase 3*
diff --git a/.paul/ROADMAP.md b/.paul/ROADMAP.md
index 06b3e4f..9218fb2 100644
--- a/.paul/ROADMAP.md
+++ b/.paul/ROADMAP.md
@@ -6,7 +6,7 @@ Pełna refaktoryzacja cmsPRO do architektury DDD wzorowanej na shopPRO. Wzorzec:
## Current Milestone
**v0.1 Refaktoryzacja** (v0.1.0)
Status: In progress
-Phases: 2 of 19 complete
+Phases: 3 of 19 complete
## Already Completed (before PAUL)
- **Domain (6 repos):** Articles, Languages, Layouts, Pages, Settings, User
@@ -20,7 +20,7 @@ Phases: 2 of 19 complete
|-------|------|-------|--------|-----------|
| 1 | Infrastructure & Autoloader | 1 | Complete | 2026-04-04 |
| 2 | Shared: Email + Security | 1 | Complete | 2026-04-04 |
-| 3 | Domain: Scontainers + Banners | 1 | Not started | - |
+| 3 | Domain: Scontainers + Banners | 1 | Complete | 2026-04-04 |
| 4 | Domain: Authors + Newsletter | 1 | Not started | - |
| 5 | Domain: SeoAdditional + Cron + Releases | 1 | Not started | - |
| 6 | Admin: Base Infrastructure | 1 | Not started | - |
diff --git a/.paul/STATE.md b/.paul/STATE.md
index 3b8a165..51094ea 100644
--- a/.paul/STATE.md
+++ b/.paul/STATE.md
@@ -5,18 +5,18 @@
See: .paul/PROJECT.md (updated 2026-04-04)
**Core value:** Autorski system CMS umożliwiający zarządzanie treściami i stronami internetowymi.
-**Current focus:** Phase 2 complete — ready for Phase 3
+**Current focus:** Phase 3 complete — ready for Phase 4
## Current Position
Milestone: v0.1 Refaktoryzacja
-Phase: 2 of 19 (Shared: Email + Security) — Complete
-Plan: 02-01 complete
+Phase: 3 of 19 (Domain: Scontainers + Banners) — Complete
+Plan: 03-01 complete
Status: Loop closed, ready for next PLAN
-Last activity: 2026-04-04 — Phase 2 complete, UNIFY done
+Last activity: 2026-04-04 — Phase 3 complete, UNIFY done
Progress:
-- Milestone: [▓░░░░░░░░░] 10%
+- Milestone: [▓▓░░░░░░░░] 15%
## Loop Position
@@ -29,8 +29,8 @@ PLAN ──▶ APPLY ──▶ UNIFY
## Performance Metrics
**Velocity:**
-- Total plans completed: 2
-- Total execution time: ~18min
+- Total plans completed: 3
+- Total execution time: ~20min
**By Phase:**
@@ -38,6 +38,7 @@ PLAN ──▶ APPLY ──▶ UNIFY
|-------|-------|------------|----------|
| 01-infrastructure | 1/1 | ~10min | ~10min |
| 02-shared-email-security | 1/1 | ~8min | ~8min |
+| 03-domain-scontainers-banners | 1/1 | ~2min | ~2min |
## Accumulated Context
@@ -46,6 +47,9 @@ PLAN ──▶ APPLY ──▶ UNIFY
- CsrfToken: single token per session (shopPRO pattern)
- Email: PHPMailer require via __DIR__ absolute paths
- Shared layer kompletny: Cache, Helpers, Html, Image, Tpl, Email, Security
+- Wrapper delegation: factory creates new repo per call (no singleton)
+- Front repos: $lang[0] passed explicitly, repos don't use globals
+- Front caching: migrated from \Cache:: to \Shared\Cache\CacheHandler::
### Deferred Issues
None.
@@ -56,9 +60,9 @@ None.
## Session Continuity
Last session: 2026-04-04
-Stopped at: Phase 2 complete, loop closed
-Next action: Run /paul:plan for Phase 3 (Domain: Scontainers + Banners)
-Resume file: .paul/phases/02-shared-email-security/02-01-SUMMARY.md
+Stopped at: Phase 3 complete, loop closed
+Next action: Run /paul:plan for Phase 4 (Domain: Authors + Newsletter)
+Resume file: .paul/phases/03-domain-scontainers-banners/03-01-SUMMARY.md
---
*STATE.md — Updated after every significant action*
diff --git a/.paul/phases/03-domain-scontainers-banners/03-01-PLAN.md b/.paul/phases/03-domain-scontainers-banners/03-01-PLAN.md
new file mode 100644
index 0000000..ea6a78e
--- /dev/null
+++ b/.paul/phases/03-domain-scontainers-banners/03-01-PLAN.md
@@ -0,0 +1,198 @@
+---
+phase: 03-domain-scontainers-banners
+plan: 01
+type: execute
+wave: 1
+depends_on: []
+files_modified:
+ - autoload/Domain/Scontainers/ScontainersRepository.php
+ - autoload/Domain/Banners/BannersRepository.php
+ - autoload/admin/factory/class.Scontainers.php
+ - autoload/admin/factory/class.Banners.php
+ - autoload/front/factory/class.Scontainers.php
+ - autoload/front/factory/class.Banners.php
+autonomous: true
+delegation: auto
+---
+
+
+## Goal
+Create Domain\Scontainers\ScontainersRepository and Domain\Banners\BannersRepository, then convert legacy factory classes to wrapper delegation.
+
+## Purpose
+Continue DDD refactoring — migrate Scontainers and Banners data access from static factory methods (global $mdb) to injected-dependency Domain repositories. Establishes wrapper delegation pattern for the first time in the project.
+
+## Output
+- 2 new Domain repository files
+- 4 legacy factory files converted to wrappers
+
+
+
+## Project Context
+@.paul/PROJECT.md
+@.paul/ROADMAP.md
+@.paul/STATE.md
+
+## Source Files
+@autoload/admin/factory/class.Scontainers.php
+@autoload/admin/factory/class.Banners.php
+@autoload/front/factory/class.Scontainers.php
+@autoload/front/factory/class.Banners.php
+@autoload/Domain/Languages/LanguagesRepository.php (pattern reference)
+
+
+
+
+## AC-1: ScontainersRepository exists with all methods
+```gherkin
+Given the autoloader is configured for Domain\ namespace
+When ScontainersRepository is instantiated with $db (Medoo)
+Then it provides containerDetails(), containerSave(), containerDelete(), scontainerByLang() methods
+And all methods use $this->db instead of global $mdb
+```
+
+## AC-2: BannersRepository exists with all methods
+```gherkin
+Given the autoloader is configured for Domain\ namespace
+When BannersRepository is instantiated with $db (Medoo)
+Then it provides bannerDetails(), bannerSave(), bannerDelete(), activeBanners(), mainBanner() methods
+And all methods use $this->db instead of global $mdb
+```
+
+## AC-3: Legacy admin factories delegate to repositories
+```gherkin
+Given admin\factory\Scontainers and admin\factory\Banners exist
+When their static methods are called (e.g. container_save(), banner_delete())
+Then they instantiate the Domain repository with global $mdb
+And delegate the call to the corresponding repository method
+And return the same result as before
+```
+
+## AC-4: Legacy front factories delegate to repositories
+```gherkin
+Given front\factory\Scontainers and front\factory\Banners exist
+When their static methods are called (e.g. scontainer_details(), banners())
+Then they delegate to the Domain repository
+And caching behavior is preserved (Cache::fetch/store in repository)
+```
+
+
+
+
+
+
+ Task 1: Create ScontainersRepository and BannersRepository
+ autoload/Domain/Scontainers/ScontainersRepository.php, autoload/Domain/Banners/BannersRepository.php
+
+ Create Domain\Scontainers\ScontainersRepository following LanguagesRepository pattern:
+ - namespace Domain\Scontainers
+ - Constructor: __construct($db) storing Medoo instance
+ - containerDetails($containerId): get from pp_scontainers + pp_scontainers_langs (all langs)
+ - containerSave($containerId, $title, $text, $status, $showTitle, $src, $html): insert/update pp_scontainers + pp_scontainers_langs with multi-language support. Handle single-lang vs multi-lang arrays exactly as current factory does. Call \S::delete_cache() after.
+ - containerDelete($containerId): delete from pp_scontainers, call \S::delete_cache()
+ - scontainerByLang($scontainerId, $langId): get container + single lang translation, use \Shared\Cache\CacheHandler::fetch/store (migrate from \Cache:: to \Shared\Cache\CacheHandler::)
+
+ Create Domain\Banners\BannersRepository following same pattern:
+ - namespace Domain\Banners
+ - Constructor: __construct($db)
+ - bannerDetails($bannerId): get from pp_banners + pp_banners_langs (all langs)
+ - bannerSave($bannerId, $name, $status, $dateStart, $dateEnd, $homePage, $src, $url, $html, $text): insert/update pp_banners + pp_banners_langs. Handle single/multi lang arrays. Call \S::delete_cache().
+ - bannerDelete($bannerId): delete from pp_banners, call \S::delete_cache()
+ - activeBanners($langId): active non-homepage banners with date filtering, use \Shared\Cache\CacheHandler for caching
+ - mainBanner($langId): single active homepage banner with date filtering, cached
+
+ IMPORTANT:
+ - PHP < 8.0 compatible (no match, no named args, no union types, no str_contains)
+ - Use $this->db->query() for complex SQL (date filtering in Banners) — keep raw SQL identical to current factory
+ - Multi-language save pattern: query pp_langs for active languages, loop and insert translations
+ - Status/checkbox conversion ('on' → 1, else 0) stays in repository methods
+
+ php -l autoload/Domain/Scontainers/ScontainersRepository.php && php -l autoload/Domain/Banners/BannersRepository.php
+ AC-1 and AC-2 satisfied: Both repositories exist with all methods, use injected $db
+
+
+
+ Task 2: Convert legacy factories to wrapper delegation
+ autoload/admin/factory/class.Scontainers.php, autoload/admin/factory/class.Banners.php, autoload/front/factory/class.Scontainers.php, autoload/front/factory/class.Banners.php
+
+ Convert all 4 factory files to thin wrappers that delegate to Domain repositories.
+
+ Pattern for each static method:
+ ```php
+ public static function method_name($args)
+ {
+ global $mdb;
+ $repo = new \Domain\Scontainers\ScontainersRepository($mdb);
+ return $repo->methodName($args);
+ }
+ ```
+
+ admin\factory\Scontainers:
+ - container_delete($id) → $repo->containerDelete($id)
+ - container_save(...) → $repo->containerSave(...)
+ - container_details($id) → $repo->containerDetails($id)
+
+ admin\factory\Banners:
+ - banner_delete($id) → $repo->bannerDelete($id)
+ - banner_save(...) → $repo->bannerSave(...)
+ - banner_details($id) → $repo->bannerDetails($id)
+
+ front\factory\Scontainers:
+ - scontainer_details($id) → $repo->scontainerByLang($id, $lang[0]) — note: use global $lang
+
+ front\factory\Banners:
+ - banners() → $repo->activeBanners($lang[0])
+ - main_banner() → $repo->mainBanner($lang[0])
+
+ IMPORTANT:
+ - Keep namespace declarations unchanged (admin\factory, front\factory)
+ - Keep method signatures identical (same parameter names and order)
+ - For front factories: pass $lang[0] explicitly to repository (repo does NOT use global $lang)
+
+ php -l autoload/admin/factory/class.Scontainers.php && php -l autoload/admin/factory/class.Banners.php && php -l autoload/front/factory/class.Scontainers.php && php -l autoload/front/factory/class.Banners.php
+ AC-3 and AC-4 satisfied: All legacy factories delegate to Domain repositories, signatures unchanged
+
+
+
+
+
+
+## DO NOT CHANGE
+- autoload/autoloader.php (autoloader stable)
+- composer.json (PSR-4 mapping already includes Domain\)
+- autoload/admin/controls/class.Scontainers.php (admin controllers — Phase 10)
+- autoload/admin/controls/class.Banners.php (admin controllers — Phase 10)
+- autoload/admin/view/ (admin views — later phases)
+- autoload/front/view/ (front views — later phases)
+- autoload/class.Scontainer.php (legacy ArrayAccess entity — separate concern)
+- Any existing Domain\ repositories (Articles, Languages, Layouts, Pages, Settings, User)
+
+## SCOPE LIMITS
+- Only factory → repository migration, NOT admin controllers or views
+- No new Composer dependencies
+- No database schema changes
+- Do not refactor the multi-language save pattern (keep it working as-is)
+
+
+
+
+Before declaring plan complete:
+- [ ] php -l passes for all 6 files (2 new + 4 modified)
+- [ ] ScontainersRepository has: containerDetails, containerSave, containerDelete, scontainerByLang
+- [ ] BannersRepository has: bannerDetails, bannerSave, bannerDelete, activeBanners, mainBanner
+- [ ] All 4 factory files are thin wrappers (no direct $mdb usage, only delegation)
+- [ ] No PHP 8.0+ syntax used
+- [ ] \S::delete_cache() calls preserved in repository methods
+- [ ] Caching (\Shared\Cache\CacheHandler) used in front-facing repository methods
+
+
+
+- All tasks completed
+- All verification checks pass
+- Zero regression — factory method signatures unchanged
+- Domain repositories follow established pattern (constructor DI, $this->db)
+
+
+
diff --git a/.paul/phases/03-domain-scontainers-banners/03-01-SUMMARY.md b/.paul/phases/03-domain-scontainers-banners/03-01-SUMMARY.md
new file mode 100644
index 0000000..ded45c1
--- /dev/null
+++ b/.paul/phases/03-domain-scontainers-banners/03-01-SUMMARY.md
@@ -0,0 +1,115 @@
+---
+phase: 03-domain-scontainers-banners
+plan: 01
+subsystem: domain
+tags: [medoo, repository, scontainers, banners, wrapper-delegation]
+
+requires:
+ - phase: 01-infrastructure
+ provides: PSR-4 autoloader for Domain\ namespace
+
+provides:
+ - Domain\Scontainers\ScontainersRepository
+ - Domain\Banners\BannersRepository
+ - Wrapper delegation pattern (first usage in project)
+
+affects: [phase-10-admin-banners-authors-scontainers, phase-15-front-pages-menu-banners-scontainers]
+
+tech-stack:
+ added: []
+ patterns: [wrapper-delegation, domain-repository-with-cache]
+
+key-files:
+ created:
+ - autoload/Domain/Scontainers/ScontainersRepository.php
+ - autoload/Domain/Banners/BannersRepository.php
+ modified:
+ - autoload/admin/factory/class.Scontainers.php
+ - autoload/admin/factory/class.Banners.php
+ - autoload/front/factory/class.Scontainers.php
+ - autoload/front/factory/class.Banners.php
+
+key-decisions:
+ - "Wrapper delegation pattern: factory static methods delegate to repo instances via global $mdb"
+ - "Front factories pass $lang[0] explicitly — repositories do not use global $lang"
+ - "Caching migrated from \\Cache:: to \\Shared\\Cache\\CacheHandler:: in repository layer"
+
+patterns-established:
+ - "Wrapper delegation: global $mdb; $repo = new \\Domain\\X\\XRepository($mdb); return $repo->method()"
+ - "Front factory passes language ID explicitly to repository"
+
+duration: ~2min
+started: 2026-04-04T00:00:00Z
+completed: 2026-04-04T00:00:00Z
+---
+
+# Phase 3 Plan 01: Scontainers + Banners Repositories Summary
+
+**Domain repositories for Scontainers and Banners with wrapper delegation in all 4 legacy factories.**
+
+## Performance
+
+| Metric | Value |
+|--------|-------|
+| Duration | ~2min |
+| Tasks | 2 completed (delegated) |
+| Files created | 2 |
+| Files modified | 4 |
+
+## Acceptance Criteria Results
+
+| Criterion | Status | Notes |
+|-----------|--------|-------|
+| AC-1: ScontainersRepository exists with all methods | Pass | 5 methods (incl. constructor), 110 lines |
+| AC-2: BannersRepository exists with all methods | Pass | 6 methods (incl. constructor), 148 lines |
+| AC-3: Legacy admin factories delegate to repositories | Pass | 6 static methods → thin wrappers |
+| AC-4: Legacy front factories delegate to repositories | Pass | 3 static methods → thin wrappers, $lang[0] passed explicitly |
+
+## Accomplishments
+
+- Created ScontainersRepository with containerDetails, containerSave, containerDelete, scontainerByLang
+- Created BannersRepository with bannerDetails, bannerSave, bannerDelete, activeBanners, mainBanner
+- Established wrapper delegation pattern — first usage in the project, template for all future phases
+
+## Files Created/Modified
+
+| File | Change | Purpose |
+|------|--------|---------|
+| `autoload/Domain/Scontainers/ScontainersRepository.php` | Created | Domain repository for scontainers CRUD + cached front read |
+| `autoload/Domain/Banners/BannersRepository.php` | Created | Domain repository for banners CRUD + cached active/main banner |
+| `autoload/admin/factory/class.Scontainers.php` | Modified | Wrapper: 3 methods delegate to ScontainersRepository |
+| `autoload/admin/factory/class.Banners.php` | Modified | Wrapper: 3 methods delegate to BannersRepository |
+| `autoload/front/factory/class.Scontainers.php` | Modified | Wrapper: 1 method delegates with $lang[0] |
+| `autoload/front/factory/class.Banners.php` | Modified | Wrapper: 2 methods delegate with $lang[0] |
+
+## Decisions Made
+
+| Decision | Rationale | Impact |
+|----------|-----------|--------|
+| Wrapper creates new repo instance per call | Matches static factory pattern, no singleton needed | Simple, no state leaks between calls |
+| Front repos use CacheHandler, not \Cache | Aligns with Shared layer conventions | Consistent caching across Domain layer |
+| $lang[0] passed as parameter, not global in repo | Repositories should not depend on globals | Cleaner, testable API |
+
+## Deviations from Plan
+
+None — plan executed exactly as written.
+
+## Issues Encountered
+
+None.
+
+## Next Phase Readiness
+
+**Ready:**
+- Domain\Scontainers and Domain\Banners available for Admin controllers (Phase 10)
+- Wrapper delegation pattern established for future Domain phases (4, 5)
+
+**Concerns:**
+- None
+
+**Blockers:**
+- None
+
+---
+*Phase: 03-domain-scontainers-banners, Plan: 01*
+*Completed: 2026-04-04*
diff --git a/autoload/Domain/Banners/BannersRepository.php b/autoload/Domain/Banners/BannersRepository.php
new file mode 100644
index 0000000..a30f3a9
--- /dev/null
+++ b/autoload/Domain/Banners/BannersRepository.php
@@ -0,0 +1,148 @@
+db = $db;
+ }
+
+ // -------------------------------------------------------------------------
+ // Odczyt
+ // -------------------------------------------------------------------------
+
+ public function bannerDetails( $bannerId )
+ {
+ $banner = $this->db->get( 'pp_banners', '*', [ 'id' => $bannerId ] );
+ if ( !$banner ) return null;
+
+ $langs = $this->db->select( 'pp_banners_langs', '*', [ 'id_banner' => $bannerId ] );
+ $banner['languages'] = [];
+ if ( is_array( $langs ) )
+ foreach ( $langs as $lang )
+ $banner['languages'][ $lang['id_lang'] ] = $lang;
+
+ return $banner;
+ }
+
+ public function activeBanners( $langId )
+ {
+ if ( $banners = \Shared\Cache\CacheHandler::fetch( 'banners' ) )
+ return $banners;
+
+ $results = $this->db->query(
+ 'SELECT id, name FROM pp_banners WHERE status = 1 AND ( date_start <= \'' . date( 'Y-m-d' ) . '\' OR date_start IS NULL ) AND ( date_end >= \'' . date( 'Y-m-d' ) . '\' OR date_end IS NULL ) AND home_page = 0'
+ )->fetchAll( \PDO::FETCH_ASSOC );
+
+ $banners = [];
+ if ( is_array( $results ) )
+ {
+ foreach ( $results as $row )
+ {
+ $langData = $this->db->get( 'pp_banners_langs', '*', [
+ 'AND' => [ 'id_banner' => $row['id'], 'id_lang' => $langId ]
+ ] );
+ $row['languages'] = $langData ?: [];
+ $banners[] = $row;
+ }
+ }
+
+ \Shared\Cache\CacheHandler::store( 'banners', $banners );
+ return $banners;
+ }
+
+ public function mainBanner( $langId )
+ {
+ $cacheKey = "main_banner:$langId";
+ if ( $banner = \Shared\Cache\CacheHandler::fetch( $cacheKey ) )
+ return $banner;
+
+ $results = $this->db->query(
+ 'SELECT id, name FROM pp_banners WHERE status = 1 AND ( date_start <= \'' . date( 'Y-m-d' ) . '\' OR date_start IS NULL ) AND ( date_end >= \'' . date( 'Y-m-d' ) . '\' OR date_end IS NULL ) AND home_page = 1 ORDER BY date_end ASC LIMIT 1'
+ )->fetchAll( \PDO::FETCH_ASSOC );
+
+ if ( !is_array( $results ) || empty( $results ) ) return null;
+
+ $banner = $results[0];
+ $langData = $this->db->get( 'pp_banners_langs', '*', [
+ 'AND' => [ 'id_banner' => $banner['id'], 'id_lang' => $langId ]
+ ] );
+ $banner['languages'] = $langData ?: [];
+
+ \Shared\Cache\CacheHandler::store( $cacheKey, $banner );
+ return $banner;
+ }
+
+ // -------------------------------------------------------------------------
+ // Zapis / usuwanie
+ // -------------------------------------------------------------------------
+
+ public function bannerSave( $bannerId, $name, $status, $dateStart, $dateEnd, $homePage, $src, $url, $html, $text )
+ {
+ $languages = $this->db->select( 'pp_langs', '*', [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
+ if ( !is_array( $languages ) ) $languages = [];
+ $langCount = count( $languages );
+
+ if ( !$bannerId )
+ {
+ $this->db->insert( 'pp_banners', [
+ 'name' => $name,
+ 'status' => $status == 'on' ? 1 : 0,
+ 'date_start' => $dateStart ? $dateStart : null,
+ 'date_end' => $dateEnd ? $dateEnd : null,
+ 'home_page' => $homePage == 'on' ? 1 : 0,
+ ] );
+ $bannerId = $this->db->id();
+ if ( !$bannerId ) return false;
+
+ foreach ( $languages as $i => $lang )
+ {
+ $this->db->insert( 'pp_banners_langs', [
+ 'id_banner' => $bannerId,
+ 'id_lang' => $lang['id'],
+ 'src' => $langCount > 1 ? $src[ $i ] : $src,
+ 'url' => $langCount > 1 ? $url[ $i ] : $url,
+ 'html' => $langCount > 1 ? $html[ $i ] : $html,
+ 'text' => $langCount > 1 ? $text[ $i ] : $text,
+ ] );
+ }
+ }
+ else
+ {
+ $this->db->update( 'pp_banners', [
+ 'name' => $name,
+ 'status' => $status == 'on' ? 1 : 0,
+ 'date_start' => $dateStart ? $dateStart : null,
+ 'date_end' => $dateEnd ? $dateEnd : null,
+ 'home_page' => $homePage == 'on' ? 1 : 0,
+ ], [ 'id' => $bannerId ] );
+
+ $this->db->delete( 'pp_banners_langs', [ 'id_banner' => $bannerId ] );
+
+ foreach ( $languages as $i => $lang )
+ {
+ $this->db->insert( 'pp_banners_langs', [
+ 'id_banner' => $bannerId,
+ 'id_lang' => $lang['id'],
+ 'src' => $langCount > 1 ? $src[ $i ] : $src,
+ 'url' => $langCount > 1 ? $url[ $i ] : $url,
+ 'html' => $langCount > 1 ? $html[ $i ] : $html,
+ 'text' => $langCount > 1 ? $text[ $i ] : $text,
+ ] );
+ }
+ }
+
+ \S::delete_cache();
+ return $bannerId;
+ }
+
+ public function bannerDelete( $bannerId )
+ {
+ $result = $this->db->delete( 'pp_banners', [ 'id' => $bannerId ] );
+ \S::delete_cache();
+ return $result;
+ }
+}
diff --git a/autoload/Domain/Scontainers/ScontainersRepository.php b/autoload/Domain/Scontainers/ScontainersRepository.php
new file mode 100644
index 0000000..c2ba8ba
--- /dev/null
+++ b/autoload/Domain/Scontainers/ScontainersRepository.php
@@ -0,0 +1,110 @@
+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 ] );
+ }
+}
diff --git a/autoload/admin/factory/class.Banners.php b/autoload/admin/factory/class.Banners.php
index ebab27b..197ff62 100644
--- a/autoload/admin/factory/class.Banners.php
+++ b/autoload/admin/factory/class.Banners.php
@@ -7,123 +7,21 @@ class Banners
public static function banner_delete( $banner_id )
{
global $mdb;
-
- $result = $mdb -> delete( 'pp_banners', [ 'id' => (int) $banner_id ] );
- \S::delete_cache();
-
- return $result;
+ $repo = new \Domain\Banners\BannersRepository($mdb);
+ return $repo->bannerDelete($banner_id);
}
public static function banner_save( $banner_id, $name, $status, $date_start, $date_end, $home_page, $src, $url, $html, $text )
{
global $mdb;
-
- if ( !$banner_id )
- {
- $mdb -> insert( 'pp_banners', [
- 'name' => $name,
- 'status' => $status == 'on' ? 1 : 0,
- 'date_start' => $date_start != '' ? $date_start : null,
- 'date_end' => $date_end != '' ? $date_end : null,
- 'home_page' => $home_page == 'on' ? 1 : 0
- ] );
-
- $id = $mdb -> id();
-
- if ( $id )
- {
- $i = 0;
-
- $results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
- if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
- {
- $mdb -> insert( 'pp_banners_langs', [
- 'id_banner' => (int)$id,
- 'id_lang' => $row['id'],
- 'src' => $src[ $i ],
- 'url' => $url[ $i ],
- 'html' => $html[ $i ],
- 'text' => $text[ $i ]
- ] );
- $i++;
- }
- else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
- {
- $mdb -> insert( 'pp_banners_langs', [
- 'id_banner' => (int)$id,
- 'id_lang' => $row['id'],
- 'src' => $src,
- 'url' => $url,
- 'html' => $html,
- 'text' => $text
- ] );
- }
-
- \S::delete_cache();
-
- return $id;
- }
- }
- else
- {
- $mdb -> update( 'pp_banners',
- [
- 'name' => $name,
- 'status' => $status == 'on' ? 1 : 0,
- 'date_start' => $date_start != '' ? $date_start : null,
- 'date_end' => $date_end != '' ? $date_end : null,
- 'home_page' => $home_page == 'on' ? 1 : 0
- ], [
- 'id' => (int) $banner_id
- ] );
-
- $mdb -> delete( 'pp_banners_langs', [ 'id_banner' => (int)$banner_id ] );
-
- $i = 0;
-
- $results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
- if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
- {
- $mdb -> insert( 'pp_banners_langs', [
- 'id_banner' => (int)$banner_id,
- 'id_lang' => $row['id'],
- 'src' => $src[ $i ],
- 'url' => $url[ $i ],
- 'html' => $html[ $i ],
- 'text' => $text[ $i ]
- ] );
- $i++;
- }
- else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
- {
- $mdb -> insert( 'pp_banners_langs', [
- 'id_banner' => (int)$banner_id,
- 'id_lang' => $row['id'],
- 'src' => $src,
- 'url' => $url,
- 'html' => $html,
- 'text' => $text
- ] );
- }
-
- \S::delete_cache();
- return $banner_id;
- }
- return false;
+ $repo = new \Domain\Banners\BannersRepository($mdb);
+ return $repo->bannerSave($banner_id, $name, $status, $date_start, $date_end, $home_page, $src, $url, $html, $text);
}
public static function banner_details( $id_banner )
{
global $mdb;
-
- $banner = $mdb -> get( 'pp_banners', '*', [ 'id' => (int)$id_banner ] );
-
- $results = $mdb -> select( 'pp_banners_langs', '*', [ 'id_banner' => (int)$id_banner ] );
- if ( is_array( $results ) ) foreach ( $results as $row )
- $banner['languages'][$row['id_lang']] = $row;
-
- return $banner;
+ $repo = new \Domain\Banners\BannersRepository($mdb);
+ return $repo->bannerDetails($id_banner);
}
-
-}
-?>
+}
\ No newline at end of file
diff --git a/autoload/admin/factory/class.Scontainers.php b/autoload/admin/factory/class.Scontainers.php
index 9d355a7..f7f1882 100644
--- a/autoload/admin/factory/class.Scontainers.php
+++ b/autoload/admin/factory/class.Scontainers.php
@@ -7,115 +7,21 @@ class Scontainers
public static function container_delete( $container_id )
{
global $mdb;
- return $mdb -> delete( 'pp_scontainers', [ 'id' => (int) $container_id ] );
+ $repo = new \Domain\Scontainers\ScontainersRepository($mdb);
+ return $repo->containerDelete($container_id);
}
public static function container_save( $container_id, $title, $text, $status, $show_title, $src, $html )
{
global $mdb;
-
- if ( !$container_id )
- {
- $mdb -> insert( 'pp_scontainers',
- [
- 'status' => $status == 'on' ? 1 : 0,
- 'show_title' => $show_title == 'on' ? 1 : 0,
- 'src' => $src
- ] );
-
- $id = $mdb -> id();
-
- if ( $id )
- {
- $i = 0;
-
- $results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
- if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
- {
- $mdb -> insert( 'pp_scontainers_langs',
- [
- 'container_id' => (int) $id,
- 'lang_id' => $row['id'],
- 'title' => $title[$i],
- 'text' => $text[$i],
- 'html' => $html[$i]
- ] );
- $i++;
- }
- else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
- {
- $mdb -> insert( 'pp_scontainers_langs', [
- 'container_id' => (int) $id,
- 'lang_id' => $row['id'],
- 'title' => $title,
- 'text' => $text,
- 'html' => $html
- ] );
- }
-
- \S::delete_cache();
-
- return $id;
- }
- }
- else
- {
- $mdb -> update( 'pp_scontainers',
- [
- 'status' => $status == 'on' ? 1 : 0,
- 'show_title' => $show_title == 'on' ? 1 : 0,
- 'src' => $src
- ],
- [
- 'id' => (int) $container_id
- ] );
-
- $mdb -> delete( 'pp_scontainers_langs',
- [ 'container_id' => (int) $container_id ] );
-
- $i = 0;
-
- $results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
- if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
- {
- $mdb -> insert( 'pp_scontainers_langs',
- [
- 'container_id' => (int) $container_id,
- 'lang_id' => $row['id'],
- 'title' => $title[$i],
- 'text' => $text[$i],
- 'html' => $html[$i]
- ] );
- $i++;
- }
- else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
- {
- $mdb -> insert( 'pp_scontainers_langs',
- [
- 'container_id' => (int) $container_id,
- 'lang_id' => $row['id'],
- 'title' => $title,
- 'text' => $text,
- 'html' => $html
- ] );
- }
-
- \S::delete_cache();
-
- return $container_id;
- }
+ $repo = new \Domain\Scontainers\ScontainersRepository($mdb);
+ return $repo->containerSave($container_id, $title, $text, $status, $show_title, $src, $html);
}
public static function container_details( $container_id )
{
global $mdb;
-
- $container = $mdb -> get( 'pp_scontainers', '*', [ 'id' => (int) $container_id ] );
-
- $results = $mdb -> select( 'pp_scontainers_langs', '*', [ 'container_id' => (int) $container_id ] );
- if ( is_array( $results ) ) foreach ( $results as $row )
- $container['languages'][$row['lang_id']] = $row;
-
- return $container;
+ $repo = new \Domain\Scontainers\ScontainersRepository($mdb);
+ return $repo->containerDetails($container_id);
}
}
\ No newline at end of file
diff --git a/autoload/front/factory/class.Banners.php b/autoload/front/factory/class.Banners.php
index 568a0f2..4aad9f9 100644
--- a/autoload/front/factory/class.Banners.php
+++ b/autoload/front/factory/class.Banners.php
@@ -6,58 +6,14 @@ class Banners
public static function banners()
{
global $mdb, $lang;
-
- if ( !$banners = \Cache::fetch( 'banners' ) )
- {
- $results = $mdb -> query( 'SELECT '
- . 'id, name '
- . 'FROM '
- . 'pp_banners '
- . 'WHERE '
- . 'status = 1 '
- . 'AND '
- . '( date_start <= \'' . date( 'Y-m-d' ) . '\' OR date_start IS NULL ) '
- . 'AND '
- . '( date_end >= \'' . date( 'Y-m-d' ) . '\' OR date_end IS NULL ) '
- . 'AND '
- . 'home_page = 0' ) -> fetchAll();
- if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
- {
- $row['languages'] = $mdb -> get( 'pp_banners_langs', '*', [ 'AND' => [ 'id_banner' => (int)$row['id'], 'id_lang' => $lang[0] ] ] );
- $banners[] = $row;
- }
- \Cache::store( 'banners', $banners );
- }
- return $banners;
+ $repo = new \Domain\Banners\BannersRepository($mdb);
+ return $repo->activeBanners($lang[0]);
}
-
+
public static function main_banner()
{
global $mdb, $lang;
-
- if ( !$banner = \Cache::fetch( "main_banner:" . $lang[0] ) )
- {
- $banner = $mdb -> query( 'SELECT '
- . '* '
- . 'FROM '
- . 'pp_banners '
- . 'WHERE '
- . 'status = 1 '
- . 'AND '
- . '( date_start <= \'' . date( 'Y-m-d' ) . '\' OR date_start IS NULL ) '
- . 'AND '
- . '( date_end >= \'' . date( 'Y-m-d' ) . '\' OR date_end IS NULL ) '
- . 'AND '
- . 'home_page = 1 '
- . 'ORDER BY '
- . 'date_end ASC '
- . 'LIMIT 1' ) -> fetchAll();
- $banner = $banner[0];
- if ( $banner )
- $banner['languages'] = $mdb -> get( 'pp_banners_langs', '*', [ 'AND' => [ 'id_banner' => (int)$banner['id'], 'id_lang' => $lang[0] ] ] );
-
- \Cache::store( "main_banner:" . $lang[0], $banner );
- }
- return $banner;
+ $repo = new \Domain\Banners\BannersRepository($mdb);
+ return $repo->mainBanner($lang[0]);
}
}
\ No newline at end of file
diff --git a/autoload/front/factory/class.Scontainers.php b/autoload/front/factory/class.Scontainers.php
index 8a6be0a..3d1bc85 100644
--- a/autoload/front/factory/class.Scontainers.php
+++ b/autoload/front/factory/class.Scontainers.php
@@ -6,18 +6,7 @@ class Scontainers
public static function scontainer_details( $scontainer_id )
{
global $mdb, $lang;
-
- if ( !$scontainer = \Cache::fetch( "scontainer_details:$scontainer_id:" . $lang[0] ) )
- {
- $scontainer = $mdb -> get( 'pp_scontainers', '*', [ 'id' => (int)$scontainer_id ] );
-
- $results = $mdb -> select( 'pp_scontainers_langs', '*', [ 'AND' => [ 'container_id' => (int)$scontainer_id, 'lang_id' => $lang[0] ] ] );
- if ( is_array( $results ) ) foreach ( $results as $row )
- $scontainer['languages'] = $row;
-
- \Cache::store( "scontainer_details:$scontainer_id:" . $lang[0], $scontainer );
- }
-
- return $scontainer;
+ $repo = new \Domain\Scontainers\ScontainersRepository($mdb);
+ return $repo->scontainerByLang($scontainer_id, $lang[0]);
}
-}
+}
\ No newline at end of file