c
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Article\Model;
|
||||
|
||||
|
||||
use Hura8\System\Model\EntityLanguageModel;
|
||||
use Hura8\Interfaces\EntityType;
|
||||
|
||||
|
||||
class ArticleCategoryLanguageModel extends EntityLanguageModel
|
||||
{
|
||||
|
||||
protected $richtext_fields = [
|
||||
'description',
|
||||
];
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(EntityType::ARTICLE_CATEGORY, '', $this->richtext_fields);
|
||||
}
|
||||
|
||||
}
|
||||
33
inc/Hura8/Components/Article/Model/ArticleCategoryModel.php
Normal file
33
inc/Hura8/Components/Article/Model/ArticleCategoryModel.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Article\Model;
|
||||
|
||||
|
||||
use Hura8\System\Model\aCategoryBaseModel;
|
||||
use Hura8\Interfaces\iEntityCategoryModel;
|
||||
use Hura8\Interfaces\EntityType;
|
||||
|
||||
|
||||
class ArticleCategoryModel extends aCategoryBaseModel implements iEntityCategoryModel
|
||||
{
|
||||
|
||||
static $url_module = "article";
|
||||
static $url_view = "category";
|
||||
static $url_type = "article:category";
|
||||
|
||||
protected $tb_article_per_category = "tb_article_per_category";
|
||||
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(EntityType::ARTICLE_CATEGORY);
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
19
inc/Hura8/Components/Article/Model/ArticleLanguageModel.php
Normal file
19
inc/Hura8/Components/Article/Model/ArticleLanguageModel.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Article\Model;
|
||||
|
||||
use Hura8\System\Model\EntityLanguageModel;
|
||||
use Hura8\Interfaces\EntityType;
|
||||
|
||||
class ArticleLanguageModel extends EntityLanguageModel
|
||||
{
|
||||
|
||||
protected $richtext_fields = [
|
||||
'description',
|
||||
];
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(EntityType::ARTICLE, '', $this->richtext_fields);
|
||||
}
|
||||
|
||||
}
|
||||
150
inc/Hura8/Components/Article/Model/ArticleModel.php
Normal file
150
inc/Hura8/Components/Article/Model/ArticleModel.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Article\Model;
|
||||
|
||||
use Hura8\System\Controller\UrlManagerController;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
use Hura8\System\ModuleManager;
|
||||
use Hura8\Interfaces\iEntityModel;
|
||||
use Hura8\Interfaces\EntityType;
|
||||
|
||||
|
||||
class ArticleModel extends aEntityBaseModel implements iEntityModel
|
||||
{
|
||||
|
||||
static $url_type = "article:detail";
|
||||
|
||||
protected $tb_article_info = "tb_article_info";
|
||||
protected $tb_article_per_category = 'tb_article_per_category';
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
EntityType::ARTICLE,
|
||||
"",
|
||||
new ArticleSearchModel()
|
||||
);
|
||||
}
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getFullInfo($id) : ?array
|
||||
{
|
||||
$query = $this->db->runQuery(
|
||||
"SELECT * FROM `".$this->tb_entity."` basic, `".$this->tb_article_info."` info
|
||||
WHERE basic.`id` = info.`article_id` AND basic.id = ?
|
||||
LIMIT 1 ",
|
||||
['d'], [$id]
|
||||
);
|
||||
|
||||
if( $item_info = $this->db->fetchAssoc($query)){
|
||||
return $item_info;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||
{
|
||||
/*$condition = array(
|
||||
"category" => getRequestInt("category"),
|
||||
"no_image" => 0,//1
|
||||
);*/
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
//Tim danh muc
|
||||
if(isset($filter_condition["category"]) && $filter_condition["category"]) {
|
||||
|
||||
$objArticleCategoryModel = new ArticleCategoryModel();
|
||||
$category_info = $objArticleCategoryModel->getInfo($filter_condition["category"]);
|
||||
|
||||
if($category_info) {
|
||||
if($category_info['is_parent']) {
|
||||
$catCondition[] = " AND `id` IN (SELECT `item_id` FROM `".$this->tb_article_per_category."` WHERE `category_id` IN (".$category_info['child_ids'].") ) ";
|
||||
//$bind_types[] = 'd';
|
||||
//$bind_values[] = $filter_condition["category"];
|
||||
}else{
|
||||
$catCondition[] = " AND `id` IN (SELECT `item_id` FROM `".$this->tb_article_per_category."` WHERE `category_id` = ? ) ";
|
||||
$bind_types[] = 'd';
|
||||
$bind_values[] = $filter_condition["category"];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
|
||||
protected function addArticleToCategory($item_id, array $category_list_id) {
|
||||
$this->db->runQuery("DELETE FROM `".$this->tb_article_per_category."` WHERE `item_id` = ? ", ['d'], [$item_id]);
|
||||
|
||||
$bulk_inserts = [];
|
||||
foreach($category_list_id as $cat_id) {
|
||||
if (! $cat_id) continue;
|
||||
|
||||
$bulk_inserts[] = [
|
||||
'category_id' => $cat_id,
|
||||
'item_id' => $item_id,
|
||||
'status' => 1,
|
||||
'create_time' => CURRENT_TIME,
|
||||
];
|
||||
}
|
||||
|
||||
if(sizeof($bulk_inserts)) {
|
||||
$this->db->bulk_insert($this->tb_article_per_category, $bulk_inserts);
|
||||
}
|
||||
|
||||
// update counter
|
||||
$objArticleCategoryModel = new ArticleCategoryModel();
|
||||
foreach($category_list_id as $cat_id) {
|
||||
$objArticleCategoryModel->updateItemCount($cat_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function updateUrl($id, $url_index): bool
|
||||
{
|
||||
|
||||
$module_routing = ModuleManager::getModuleRouting("article");
|
||||
$request_path_config = isset($module_routing["detail"]) ? $module_routing["detail"]['url_manager']['request_path'] : '';
|
||||
|
||||
if(!$request_path_config) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$request_path = UrlManagerController::translateRequestPathConfig($request_path_config, $id, $url_index);
|
||||
$id_path = UrlManagerController::createIdPath("article", "detail", $id);
|
||||
|
||||
$objUrlManager = new UrlManagerController();
|
||||
$new_request_path = $objUrlManager->createUrl("article:detail", $request_path, $id_path, 0);
|
||||
|
||||
if($new_request_path) {
|
||||
$this->db->update(
|
||||
$this->tb_entity,
|
||||
[
|
||||
'request_path' => $new_request_path,
|
||||
],
|
||||
[
|
||||
'id' => $id,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
29
inc/Hura8/Components/Article/Model/ArticleSearchModel.php
Normal file
29
inc/Hura8/Components/Article/Model/ArticleSearchModel.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Article\Model;
|
||||
|
||||
use Hura8\Interfaces\iSearch;
|
||||
use Hura8\System\Model\aSearchBaseModel;
|
||||
|
||||
class ArticleSearchModel extends aSearchBaseModel implements iSearch
|
||||
{
|
||||
|
||||
private $filter_fields = [
|
||||
"status"=> "tb_article.status",
|
||||
];
|
||||
|
||||
private $fulltext_fields = [
|
||||
"keywords" => ["tb_article.title", ],
|
||||
];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
"tb_article",
|
||||
$this->fulltext_fields,
|
||||
$this->filter_fields
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
55
inc/Hura8/Components/Article/Model/UArticleModel.php
Normal file
55
inc/Hura8/Components/Article/Model/UArticleModel.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Article\Model;
|
||||
|
||||
class UArticleModel extends ArticleModel
|
||||
{
|
||||
|
||||
public function getSameCategoryArticle($main_id, $category_id){
|
||||
|
||||
$query = $this->db->runQuery("
|
||||
(
|
||||
SELECT `item_id`
|
||||
FROM ".$this->tb_article_per_category."
|
||||
WHERE `category_id` = ? AND `status`=1 AND `item_id` > ?
|
||||
ORDER BY `item_id` DESC
|
||||
LIMIT 10
|
||||
|
||||
) UNION ALL (
|
||||
SELECT `item_id`
|
||||
FROM ".$this->tb_article_per_category."
|
||||
WHERE `category_id` = ? AND `status`=1 AND `item_id` < ?
|
||||
ORDER BY `item_id` DESC
|
||||
LIMIT 10
|
||||
)
|
||||
",
|
||||
['d', 'd', 'd', 'd'],
|
||||
[$category_id, $main_id, $category_id, $main_id]
|
||||
);
|
||||
|
||||
$article_list_id = [];
|
||||
$article_item_info = array();
|
||||
$article_item = [];
|
||||
|
||||
foreach ( $this->db->fetchAll($query) as $rs ) {
|
||||
if(!isset($article_item_info[$rs["item_id"]])) $article_item_info[$rs["item_id"]] = array();
|
||||
if(!in_array($rs["item_id"], $article_list_id)) $article_list_id[] = $rs["item_id"];
|
||||
|
||||
if($rs["item_id"] > $main_id) {
|
||||
$article_item['new'][$rs["item_id"]] = &$article_item_info[$rs["item_id"]];
|
||||
}
|
||||
else {
|
||||
$article_item['old'][$rs["item_id"]] = &$article_item_info[$rs["item_id"]];
|
||||
}
|
||||
}
|
||||
|
||||
$list_article_info = $this->getListByIds($article_list_id);
|
||||
foreach ($article_list_id as $_id) {
|
||||
if(isset($list_article_info[$_id])) $article_item_info[$_id] = $list_article_info[$_id];
|
||||
}
|
||||
|
||||
|
||||
return $article_item;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user