feat: Add banner management functionality

- Implemented a new Banner model to represent banner data.
- Created a BannerRepository for database interactions related to banners.
- Developed a BannerService to handle business logic for banners.
- Added admin views for listing and adding banners.
- Integrated banner hooks for frontend rendering and click tracking.
- Created frontend styles and scripts for banner display and interaction.
- Updated database migrations to include a new banners table.
- Enhanced AdminController to manage banner actions and pages.
This commit is contained in:
2026-05-05 01:03:05 +03:30
parent 5930c1ad6f
commit 32c065e4b6
15 changed files with 1350 additions and 4 deletions

View File

@@ -0,0 +1,81 @@
<?php
namespace Sodino\Repositories;
use Sodino\Models\Banner;
/**
* Banner Repository
*/
class BannerRepository {
private $table_name;
public function __construct() {
global $wpdb;
$this->table_name = $wpdb->prefix . 'sodino_banners';
}
public function getAll() {
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM {$this->table_name} ORDER BY priority DESC, id ASC", ARRAY_A);
$banners = [];
foreach ($results as $result) {
$banners[] = new Banner($result);
}
return $banners;
}
public function getById($id) {
global $wpdb;
$result = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$this->table_name} WHERE id = %d", $id), ARRAY_A);
return $result ? new Banner($result) : null;
}
public function getEnabled() {
global $wpdb;
$results = $wpdb->get_results("SELECT * FROM {$this->table_name} WHERE status = 1 ORDER BY priority DESC, id ASC", ARRAY_A);
$banners = [];
foreach ($results as $result) {
$banners[] = new Banner($result);
}
return $banners;
}
public function save(Banner $banner) {
global $wpdb;
$data = $banner->toArray();
unset($data['id'], $data['created_at']);
if ($banner->id) {
$wpdb->update($this->table_name, $data, ['id' => $banner->id]);
$this->clearCache();
return $banner->id;
}
$wpdb->insert($this->table_name, $data);
$this->clearCache();
return $wpdb->insert_id;
}
public function delete($id) {
global $wpdb;
$result = $wpdb->delete($this->table_name, ['id' => $id]);
$this->clearCache();
return $result;
}
public function incrementImpression($id) {
global $wpdb;
$wpdb->query($wpdb->prepare("UPDATE {$this->table_name} SET impressions = impressions + 1 WHERE id = %d", $id));
$this->clearCache();
}
public function incrementClick($id) {
global $wpdb;
$wpdb->query($wpdb->prepare("UPDATE {$this->table_name} SET clicks = clicks + 1 WHERE id = %d", $id));
$this->clearCache();
}
public function clearCache() {
wp_cache_flush();
}
}