72 lines
2.9 KiB
PHP
Executable File
72 lines
2.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Home\Widget;
|
|
use Gy_Library\DBCont;
|
|
use Gy_Library\HomeController;
|
|
|
|
class NewsListWidget extends HomeController{
|
|
public function index($topic_id=0)
|
|
{
|
|
$cate_id=I('get.cate_id');
|
|
if(!empty($cate_id)){
|
|
$map['_string'] = "FIND_IN_SET({$cate_id},cate_id)";
|
|
}
|
|
if(!empty($topic_id)){
|
|
$news_id = D('TopicFromNews')->where(['topic_id'=>$topic_id,'status'=>DBCont::YES_BOOL_STATUS])->order('sort asc')->getField('news_id',true);
|
|
if(!empty($news_id)){
|
|
$map['id'] = ['IN',$news_id];
|
|
$news_id_sort = implode(',',$news_id);
|
|
$order ="FIELD (id,{$news_id_sort})";
|
|
}else{
|
|
$map['_string'] = "1=0";
|
|
}
|
|
}else{
|
|
$order ='sort asc,start_date desc, id desc';
|
|
}
|
|
$page = I('page');
|
|
$page == '' && $page = 1;
|
|
$per_page = !empty(C('HOME_PER_PAGE_NUM'))?C('HOME_PER_PAGE_NUM'): 1 ;
|
|
$model = D('News');
|
|
|
|
$map['status'] = DBCont::YES_BOOL_STATUS;
|
|
$count = $model->getListForCount($map);
|
|
if ($per_page === false) {
|
|
$para = array($count);
|
|
} else {
|
|
$para = array($count, $per_page);
|
|
}
|
|
$class = new \ReflectionClass('\Gy_Library\GyPage');
|
|
$page_object = $class->newInstanceArgs($para);
|
|
$pagination = $page_object->show();
|
|
$this->assign('pagination', $pagination);
|
|
|
|
$keywords_id=I('get.keywords_id');
|
|
if(!empty($keywords_id)){
|
|
$map['_string'] = "FIND_IN_SET({$keywords_id},keywords_id)";
|
|
$news_list = D('SearchV')->where($map)->order($order)->page($page,$per_page)->select();
|
|
}else{
|
|
$news_list = $model->where($map)->order($order)->page($page,$per_page)->select();
|
|
}
|
|
foreach($news_list as &$item) {
|
|
$cate_res = explode(',', $item['cate_id']);
|
|
$keyword_res = explode(',', $item['keywords_id']);
|
|
if ($item['type'] === 'tribune') {
|
|
foreach ($cate_res as $k => $v1) {
|
|
if ($k < 1) {
|
|
$item['cate_name'][] = D('TribuneCate')->where(['id' => $v1])->getField('name');
|
|
$item['keywords_name'] = D('Keywords')->where(['id' => ['IN', $keyword_res]])->limit(4)->getField('id,name', true);
|
|
}
|
|
}
|
|
} else {
|
|
$item['cate_name'] = D('NewsCate')->where(['id' => ['IN', $cate_res]])->limit(2)->getField('id,name', true);
|
|
$item['keywords_name'] = D('Keywords')->where(['id' => ['IN', $keyword_res]])->limit(4)->getField('id,name', true);
|
|
}
|
|
}
|
|
$this->list=$news_list;
|
|
$this->keywords_id=!empty($keywords_id)?$keywords_id:0;
|
|
$this->topic_id=$topic_id;
|
|
$this->cate_id=!empty($cate_id)?$cate_id:0;
|
|
$this->display('Widget/newsList');
|
|
}
|
|
}
|