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,44 @@
<?php
namespace Hura8\Components\Brand\AdminController;
use Hura8\Components\Brand\Controller\bBrandController;
use Hura8\Interfaces\iEntityAdminController;
use Hura8\Traits\AdminEntityBaseControllerTraits;
class ABrandController extends bBrandController implements iEntityAdminController
{
use AdminEntityBaseControllerTraits;
public function getGroupByFirstLetter() {
return $this->objBrandModel->getGroupByFirstLetter();
}
protected function deleteFileBeforeDeleteItem($item_id): bool
{
// delete thumb files
$item_info = $this->getInfo($item_id);
if($item_info['thumbnail']) {
foreach (static::$resized_sizes as $size => $value) {
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $item_info['thumbnail'];
unlink($file_local_path);
}
// remove original file
$file_local_path = PUBLIC_DIR . "/". static::$image_folder . "/". $item_info['thumbnail'];
unlink($file_local_path);
}
//delete media files?
// todo:
// ok
return true;
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace Hura8\Components\Brand\Controller;
use Hura8\Components\Brand\Model\BrandLanguageModel;
use Hura8\Components\Brand\Model\BrandModel;
use Hura8\System\Controller\aEntityBaseController;
class bBrandController extends aEntityBaseController
{
static $image_folder = "media/brand";
static $resized_sizes = array(
's' => ['width' => 200,] ,
);
/* @var BrandModel $objBrandModel */
protected $objBrandModel;
/* @var BrandLanguageModel $objBrandLanguageModel */
protected $objBrandLanguageModel;
protected $view_language = '';
public function __construct()
{
$this->objBrandModel = new BrandModel();
if(!$this->isDefaultLanguage()) {
$this->objBrandLanguageModel = new BrandLanguageModel();
//$this->objVideoLanguageModel->createTableLang();
parent::__construct($this->objBrandModel, $this->objBrandLanguageModel);
}else{
parent::__construct($this->objBrandModel);
}
}
public function getInfoByUrl(string $band_index) : ?array
{
return $this->objBrandModel->getInfoByUrl($band_index);
}
protected function formatItemInList(array $item_info) : array
{
return $this->formatItemInfo($item_info);
}
protected function formatItemInfo(array $item_info) : ?array
{
if(!$item_info) return null;
$info = static::formatItemImage($item_info);
$info['url'] = "/brand/".$info['brand_index'];
return $info;
}
public static function formatItemImage(array $item_info) {
$info = $item_info;
foreach (static::$resized_sizes as $size => $value) {
$info['image'][$size] = ($info['thumbnail']) ? STATIC_DOMAIN . "/". static::$image_folder . "/". $size. IMAGE_FILE_SEPARATOR . $info['thumbnail'] : '';
}
return $info;
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Hura8\Components\Brand\Model;
use Hura8\System\Model\EntityLanguageModel;
use Hura8\Interfaces\EntityType;
class BrandLanguageModel extends EntityLanguageModel
{
protected $richtext_fields = [
'description',
];
public function __construct() {
parent::__construct(EntityType::BRAND, '', $this->richtext_fields);
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace Hura8\Components\Brand\Model;
use Hura8\Interfaces\AppResponse;
use Hura8\System\Config;
use Hura8\System\Controller\UrlManagerController;
use Hura8\System\Model\aEntityBaseModel;
use Hura8\Interfaces\iEntityModel;
use Hura8\Interfaces\EntityType;
use Hura8\Interfaces\TableName;
class BrandModel extends aEntityBaseModel implements iEntityModel
{
static $url_type = "brand:detail";
public function __construct() {
parent::__construct(EntityType::BRAND);
}
protected function extendedFilterOptions() : array
{
return [
// empty for now
];
}
public function getGroupByFirstLetter() {
$query = $this->db->runQuery(
"SELECT `letter`, COUNT(*) AS item_count FROM `".$this->tb_entity."` GROUP BY `letter` ORDER BY `letter` ASC "
);
return $this->db->fetchAll($query);
}
protected function _buildQueryConditionExtend(array $filter_condition): ?array
{
/*$condition = array(
"letter" => "",
);*/
$catCondition = [];
$bind_types = [];
$bind_values = [];
if(isset($filter_condition["letter"]) && strlen($filter_condition["letter"]) == 1){
$catCondition[] = " AND `letter` = ? ";
$bind_types[] = 's';
$bind_values[] = $filter_condition["letter"];
}
return array( join(" ", $catCondition), $bind_types, $bind_values);
}
public function getInfoByUrl($brand_index) : ?array
{
$brand_index = preg_replace("/[^a-z0-9\.\-\_]/i", '', $brand_index);
$query = $this->db->runQuery("SELECT * FROM `".$this->tb_entity."` WHERE `brand_index` = ? LIMIT 1 ", ['s'], [$brand_index]);
if($item_info = $this->db->fetchAssoc($query)){
return $this->formatItemInfo($item_info);
}
return null;
}
}