This commit is contained in:
2024-01-31 11:36:25 +07:00
parent caef156a05
commit 4561bd68d1
125 changed files with 9117 additions and 58 deletions

View File

@@ -0,0 +1,16 @@
<?php
namespace Hura8\Components\Banner\AdminController;
use Hura8\Components\Banner\Controller\bBannerController;
use Hura8\Interfaces\iEntityAdminController;
use Hura8\Traits\AdminEntityBaseControllerTraits;
class ABannerController extends bBannerController implements iEntityAdminController
{
use AdminEntityBaseControllerTraits;
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Hura8\Components\Banner\AdminController;
use Hura8\Components\Banner\Model\BannerLocationModel;
use Hura8\System\Controller\aAdminEntityBaseController;
class ABannerLocationController extends aAdminEntityBaseController
{
public function __construct()
{
parent::__construct(new BannerLocationModel());
}
public function getTemplateBanner() {
return ABannerController::$template_banners;
}
protected function deleteFileBeforeDeleteItem($item_id): bool
{
return true;
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Hura8\Components\Banner\Controller;
use Hura8\Components\Banner\Model\BannerLocationModel;
use Hura8\Components\Banner\Model\BannerModel;
use Hura8\System\Controller\aEntityBaseController;
class bBannerController extends aEntityBaseController
{
static $image_folder = "media/banner";
static $template_banners = array(
//"index" => "Toàn bộ website" ,
"header" => "Đầu trang" ,
"homepage" => "Trang chủ" ,
"column_left" => "Cột trái" ,
"column_right" => "Cột phải" ,
"footer" => "Chân trang" ,
"product_detail"=> "Chi tiết sản phẩm" ,
"product_list" => "Danh sách &amp; Danh mục sản phẩm" ,
"collection_list" => "Bộ sưu tập" ,
"article_home" => "Trang chủ tin tức" ,
"brand_detail" => "Chi tiết thương hiệu",
);
protected $objBannerModel;
protected $objBannerLocationModel;
public function __construct()
{
$this->objBannerModel = new BannerModel();
$this->objBannerLocationModel = new BannerLocationModel();
parent::__construct($this->objBannerModel);
}
protected function formatItemInList(array $item_info)
{
return self::formatFile($item_info);
}
protected function formatItemInfo(array $item_info)
{
return self::formatFile($item_info);
}
public static function formatFile(array $item_info)
{
if($item_info['file_url']) {
$item_info['display_file'] = STATIC_DOMAIN ."/". static::$image_folder ."/". $item_info['file_url'];
}else if($item_info['file_external_url']) {
$item_info['display_file'] = $item_info['file_external_url'];
}
$item_info['html_code'] = "<a href=\"/ad.php?id=".$item_info['tracking_id']."\" target='_blank' rel='nofollow'><img border='0' src=\"".$item_info['display_file']."\" alt=\"".htmlspecialchars($item_info['title'])."\" /></a>";
return $item_info;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Hura8\Components\Banner\Model;
use Hura8\Interfaces\AppResponse;
use Hura8\Interfaces\iEntityModel;
use Hura8\Interfaces\EntityType;
use Hura8\System\Model\aEntityBaseModel;
use Hura8\System\Security\DataClean;
use Hura8\System\Security\DataType;
class BannerLocationModel extends aEntityBaseModel implements iEntityModel
{
public function __construct() {
parent::__construct(EntityType::BANNER_LOCATION);
}
protected function extendedFilterOptions(): array
{
return [];
}
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
{
return null;
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace Hura8\Components\Banner\Model;
use Hura8\System\Model\aEntityBaseModel;
use Hura8\Interfaces\iEntityModel;
use Hura8\Interfaces\EntityType;
class BannerModel extends aEntityBaseModel implements iEntityModel
{
protected $tb_banner_location = "tb_banner_location";
protected $tb_banner_per_category = "tb_banner_per_category";
public function __construct() {
parent::__construct(
EntityType::BANNER, "", new BannerSearchModel()
);
}
protected function extendedFilterOptions() : array
{
return [
// empty for now
];
}
public function getInfoByTrackingId($tracking_id)
{
$query = $this->db->runQuery("SELECT * FROM `".$this->tb_entity."` WHERE `tracking_id` = ? LIMIT 1 ", ['s'], [$tracking_id]) ;
if( $item_info = $this->db->fetchAssoc($query)){
return $this->formatItemInfo($item_info);
}
return false;
}
public function getBannerPerTemplate(array $template_list, $numberOfBannerPerTpl=100){
$all_bind_types = [];
$all_bind_values = [];
$view_id = 0;
$build_query = [];
foreach($template_list as $tpl) {
list($where_condition, $bind_types, $bind_values) = $this->buildQueryPerTpl($tpl, $view_id, $numberOfBannerPerTpl);
$build_query[] = " (".$where_condition.") ";
$all_bind_types = array_merge($all_bind_types, $bind_types);
$all_bind_values = array_merge($all_bind_values, $bind_values);
}
if(!sizeof($build_query)) return [];
$query = $this->db->runQuery(join(" UNION ALL ", $build_query), $all_bind_types, $all_bind_values);
return $this->db->fetchAll($query);
}
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
{
/*$condition = array(
[location] => 2
[category] => 0
);*/
$catCondition = [];
$bind_types = [];
$bind_values = [];
if(isset($filter_condition['location']) && $filter_condition['location']) {
$catCondition[] = " AND `location` = ? ";
$bind_types[] = 'd';
$bind_values[] = $filter_condition['location'];
}
if(isset($filter_condition['category']) && $filter_condition['category']) {
$catCondition[] = " AND `id` IN ( SELECT `banner_id` FROM `".$this->tb_banner_per_category."` WHERE `category_id` = ? ) ";
$bind_types[] = 'd';
$bind_values[] = $filter_condition['category'];
}
return array( join(" ", $catCondition), $bind_types, $bind_values);
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Hura8\Components\Banner\Model;
use Hura8\Interfaces\iSearch;
use Hura8\System\Model\aSearchBaseModel;
class BannerSearchModel extends aSearchBaseModel implements iSearch
{
private $filter_fields = [
"location" => "tb_banner.location",
"status" => "tb_banner.status",
];
private $fulltext_fields = [
"keywords" => ["tb_banner.title",],
];
public function __construct()
{
parent::__construct(
"tb_banner",
$this->fulltext_fields,
$this->filter_fields
);
//$this->createTableSearch();
}
}