c
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\ComboSet\AdminController;
|
||||
|
||||
use Hura8\Components\ComboSet\Controller\bComboSetController;
|
||||
use Hura8\Components\Product\AdminController\AProductController;
|
||||
use Hura8\Interfaces\iEntityAdminController;
|
||||
use Hura8\Traits\AdminEntityBaseControllerTraits;
|
||||
|
||||
class AComboSetController extends bComboSetController implements iEntityAdminController
|
||||
{
|
||||
|
||||
use AdminEntityBaseControllerTraits;
|
||||
|
||||
}
|
||||
148
inc/Hura8/Components/ComboSet/Controller/bComboSetController.php
Normal file
148
inc/Hura8/Components/ComboSet/Controller/bComboSetController.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\ComboSet\Controller;
|
||||
|
||||
use Hura8\Components\ComboSet\Model\ComboSetLanguageModel;
|
||||
use Hura8\Components\ComboSet\Model\ComboSetModel;
|
||||
use Hura8\System\Controller\aEntityBaseController;
|
||||
|
||||
class bComboSetController extends aEntityBaseController
|
||||
{
|
||||
/* @var ComboSetModel $objComboSetModel */
|
||||
protected $objComboSetModel;
|
||||
|
||||
/* @var ComboSetLanguageModel $objComboSetLanguageModel */
|
||||
protected $objComboSetLanguageModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objComboSetModel = new ComboSetModel();
|
||||
|
||||
if(!$this->isDefaultLanguage()) {
|
||||
$this->objComboSetLanguageModel = new ComboSetLanguageModel();
|
||||
//$this->objVideoLanguageModel->createTableLang();
|
||||
parent::__construct($this->objComboSetModel, $this->objComboSetLanguageModel);
|
||||
|
||||
}else{
|
||||
parent::__construct($this->objComboSetModel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getAllSetIdsForAProduct($product_id)
|
||||
{
|
||||
return $this->objComboSetModel->getAllSetIdsForAProduct($product_id);
|
||||
}
|
||||
|
||||
|
||||
public function getTotalProductUseSet($set_id)
|
||||
{
|
||||
return $this->objComboSetModel->getTotalProductUseSet($set_id);
|
||||
}
|
||||
|
||||
|
||||
public function getListProductUseSet($set_id, $numPerPage)
|
||||
{
|
||||
return $this->objComboSetModel->getListProductUseSet($set_id, $numPerPage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function getProductListInfoInConfig(array $category) {
|
||||
$product_list_ids = [];
|
||||
foreach ($category as $index => $_category_info) {
|
||||
foreach ($_category_info['suggest_list'] as $_proindex => $_pro_info) {
|
||||
$product_list_ids[] = $_pro_info['real_id'];
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique($product_list_ids);
|
||||
}
|
||||
|
||||
|
||||
public function buildConfig( $category, $product) {
|
||||
|
||||
$group_category = [];
|
||||
|
||||
foreach ($category as $category_index => $_category_info) {
|
||||
$category_product = [];
|
||||
foreach ($product[$category_index] as $product_index => $_product_info) {
|
||||
//$_product_info['price'] = clean_price($_product_info['price']);
|
||||
$category_product[] = $_product_info;
|
||||
}
|
||||
|
||||
$group_category[] = [
|
||||
"title" => $_category_info['title'],
|
||||
//"type" => "category",
|
||||
//"real_id" => $_category_info['real_id'],
|
||||
//"select_type" => $_category_info['select_type'],//checkbox|radio
|
||||
"suggest_list" => $category_product,
|
||||
];
|
||||
}
|
||||
|
||||
return $group_category;
|
||||
}
|
||||
|
||||
|
||||
public function decomposeConfig($config) {
|
||||
$tab = [];
|
||||
$group = [];
|
||||
$category = [];
|
||||
$product = [];
|
||||
|
||||
$group_index = 0;
|
||||
$category_index = 0;
|
||||
$product_index = 0;
|
||||
|
||||
foreach ($config as $tab_index => $tab_info) {
|
||||
//construct tab
|
||||
$tab[$tab_index] = [
|
||||
'title' => $tab_info['title'],
|
||||
];
|
||||
|
||||
//construct group
|
||||
foreach ($tab_info['child'] as $child_group) {
|
||||
$group_index += 1;
|
||||
|
||||
$group[$tab_index][$group_index] = [
|
||||
'title' => $child_group['title'],
|
||||
];
|
||||
|
||||
//construct category
|
||||
foreach ($child_group['child'] as $child_category) {
|
||||
$category_index += 1;
|
||||
|
||||
$category[$group_index][$category_index] = [
|
||||
'title' => $child_category['title'],
|
||||
'real_id' => $child_category['real_id'],
|
||||
'select_type' => $child_category['select_type'],
|
||||
];
|
||||
|
||||
//construct product
|
||||
foreach ($child_category['suggest_list'] as $child_product) {
|
||||
$product_index += 1;
|
||||
|
||||
$product[$category_index][$product_index] = [
|
||||
'title' => $child_product['title'],
|
||||
'real_id' => $child_product['real_id'],
|
||||
'is_default' => $child_product['is_default'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
"tab" => $tab,
|
||||
"group" => $group,
|
||||
'category' => $category,
|
||||
'product' => $product,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\ComboSet\Model;
|
||||
|
||||
use Hura8\Interfaces\EntityType;
|
||||
use Hura8\System\Model\EntityLanguageModel;
|
||||
|
||||
|
||||
class ComboSetLanguageModel extends EntityLanguageModel
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct('combo_set');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
165
inc/Hura8/Components/ComboSet/Model/ComboSetModel.php
Normal file
165
inc/Hura8/Components/ComboSet/Model/ComboSetModel.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\ComboSet\Model;
|
||||
|
||||
use Hura8\Components\Product\AdminController\AProductController;
|
||||
use Hura8\Components\Product\Model\ProductSearchModel;
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
|
||||
|
||||
class ComboSetModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
protected $tb_set_product = 'tb_combo_set_product';
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct('combo_set');
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getAllSetIdsForAProduct($product_id)
|
||||
{
|
||||
$query = $this->db->runQuery(
|
||||
" SELECT `set_id` FROM ".$this->tb_set_product." WHERE `product_id` = ? ",
|
||||
['d'], [$product_id]
|
||||
);
|
||||
|
||||
$item_list = array();
|
||||
foreach ( $this->db->fetchAll($query) as $info ) {
|
||||
$item_list[] = $info['set_id'];
|
||||
}
|
||||
|
||||
return $item_list;
|
||||
}
|
||||
|
||||
|
||||
public function getTotalProductUseSet($set_id)
|
||||
{
|
||||
// search
|
||||
$keyword = getRequest("q");
|
||||
if($keyword) {
|
||||
$search = new ProductSearchModel();
|
||||
$match_result = $search->find($keyword);
|
||||
$catCondition = (sizeof($match_result) > 0) ? " AND `product_id` IN (".join(",", $match_result).") " : " AND `product_id` = -1 ";
|
||||
|
||||
$query = $this->db->runQuery("
|
||||
SELECT COUNT(product_id) AS total_product
|
||||
FROM ".$this->tb_set_product."
|
||||
WHERE `set_id` = ? " . $catCondition ."
|
||||
", ['d'], [$set_id]);
|
||||
|
||||
if ($info = $this->db->fetchAssoc($query)) {
|
||||
return $info['total_product'];
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
$set_info = $this->getInfo($set_id);
|
||||
|
||||
return $set_info['product_count'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getListProductUseSet($set_id, $numPerPage)
|
||||
{
|
||||
$page = getPageId();
|
||||
|
||||
// search
|
||||
$catCondition = "";
|
||||
$keyword = getRequest("q");
|
||||
if($keyword) {
|
||||
$search = new ProductSearchModel();
|
||||
$match_result = $search->find($keyword);
|
||||
$catCondition = (sizeof($match_result) > 0) ? " AND `product_id` IN (".join(",", $match_result).") " : " AND `product_id` = -1 ";
|
||||
}
|
||||
|
||||
$query = $this->db->runQuery("
|
||||
SELECT `product_id`
|
||||
FROM ".$this->tb_set_product."
|
||||
WHERE `set_id` = ? " . $catCondition ."
|
||||
ORDER BY id desc
|
||||
LIMIT ".($page - 1) * $numPerPage .", ".$numPerPage."
|
||||
", ['d'], [$set_id]);
|
||||
|
||||
$item_list = array();
|
||||
foreach ( $this->db->fetchAll($query) as $info ) {
|
||||
$item_list[] = $info['product_id'];
|
||||
}
|
||||
|
||||
return $item_list;
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryOrderBy(string $sort_by = "new")
|
||||
{
|
||||
$order_condition = "";
|
||||
|
||||
switch ($sort_by) {
|
||||
case "ordering";
|
||||
$order_condition = " `ordering` desc ";
|
||||
break;
|
||||
case "old";
|
||||
$order_condition = " id asc ";
|
||||
break;
|
||||
case "last_show_time";
|
||||
$order_condition = " last_show_time ASC ";
|
||||
break;
|
||||
}
|
||||
|
||||
return $order_condition;
|
||||
}
|
||||
|
||||
|
||||
protected function formatItemInfo(array $item_info) : array
|
||||
{
|
||||
$from_time = $item_info['from_time'];
|
||||
$from_time_date = ($from_time > 0) ? date("d-m-Y", $from_time) : '';
|
||||
$from_time_minute = ($from_time > 0) ? date("H:i", $from_time) : "00:00";
|
||||
|
||||
$to_time = $item_info['to_time'];
|
||||
$to_time_date = ($to_time > 0) ? date("d-m-Y", $to_time) : '';
|
||||
$to_time_minute = ($to_time > 0) ? date("H:i", $to_time) : "00:00";
|
||||
|
||||
$item_info['from_time_date'] = $from_time_date;
|
||||
$item_info['from_time_minute'] = $from_time_minute;
|
||||
$item_info['to_time_date'] = $to_time_date;
|
||||
$item_info['to_time_minute'] = $to_time_minute;
|
||||
|
||||
return $item_info;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///---------
|
||||
///
|
||||
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||
{
|
||||
|
||||
$catCondition = "";
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
if(isset($filter_condition["product_id"]) && $filter_condition["product_id"]){
|
||||
$catCondition .= " AND `id` IN ( SELECT `set_id` FROM ".$this->tb_set_product." WHERE `product_id` = ? ) ";
|
||||
|
||||
$bind_types[] = 'd';
|
||||
$bind_values[] = $filter_condition['product_id'];
|
||||
}
|
||||
|
||||
return [$catCondition, $bind_types, $bind_values];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user