title="Новости";
//тест (заменить на новостьи дня и по календарику)
/*
$newsDataProvider = new \yii\data\ActiveDataProvider(
[
"query"=>\app\models\News::getMainView()->orderBy(["dt_pub"=>SORT_DESC])->limit(50),
"pagination" =>[
"pageSize"=>50
],
]
);
*/
if( isset( $_GET['search'] ) && trim( $_GET['search'] ) != ''){
$news_query = \app\models\base\News::find()->joinWith('topics t');
$news_query->alias('n')->andWhere([
"n.id"=>(new Query())
->from('amic_news')
->select(['id'])
->addOptions(['max_matches' => 200])
->addOptions(['field_weights'=> ['title' => 10, 'body' => 8, 'lead'=>5] ])
->match($_GET['search'])
->orderBy(["dt_pub"=>SORT_DESC])
->limit(200)
->column()
]);
$newsDataProvider1 = new \yii\data\ActiveDataProvider(
[
"query"=>$news_query,
"pagination" =>[
"pageSize"=>200
],
]
);
}
if (Yii::$app->request->isGet && $get = Yii::$app->request->get('dt')){
$b_date = date("Y-m-d 00:00:00", strtotime($get));
$e_date = date("Y-m-d 23:59:59", strtotime($get));
Yii::$app->session->set('dt-newslistadm', $get);
}elseif( $get = Yii::$app->session->get('dt-newslistadm') ){
$b_date = date("Y-m-d 00:00:00", strtotime($get));
$e_date = date("Y-m-d 23:59:59", strtotime($get));
}else{
$b_date = date("Y-m-d 00:00:00");
$e_date = date("Y-m-d 23:59:59");
}
$newsDataProvider = new \yii\data\ActiveDataProvider(
[
"query"=>\app\models\base\News::find()->andwhere(['between', 'dt_pub', $b_date , $e_date])->orderBy(["dt_pub"=>SORT_DESC])->limit(200),
"pagination" =>[
"pageSize"=>200
],
]
);
$cnt = $newsDataProvider->getCount();
if( $cnt == 0 ){ //return; возможный вариант
$newsDataProvider = new \yii\data\ActiveDataProvider(
[
"query"=>\app\models\base\News::find()->andwhere(['>', 'id', 0])->orderBy(["dt_pub"=>SORT_DESC])->limit(200),
"pagination" =>[
"pageSize"=>200
],
]
);
$cnt = $newsDataProvider->getCount();
}
$cache = Yii::$app->cache;
$NewsItem = array();
$prc = round($cnt*100/60);
/**** ****/
?>
Материалов
=$cnt?>
=$prc?>% Среднее за день
$newsDataProvidera = new \yii\data\ActiveDataProvider(
[
"query"=>\app\models\base\News::find()->select(["SUBSTRING_INDEX(`editors`,',',1) as e"])->andwhere(['between', 'dt_pub', $b_date , $e_date])->groupBy(["e"]),
"pagination" =>false
]
);
$cnt = $newsDataProvidera->getCount();
$newsDataProvidera = new \yii\data\ActiveDataProvider(
[
"query"=>\app\models\base\News::find()->select('count(author)')->andwhere(['between', 'dt_pub', $b_date , $e_date])->andwhere(['<>', 'author', '5'])->groupBy(["author"]),
"pagination" =>false
]
);
$cnt2 = $newsDataProvidera->getCount();
$newsDataProvidera = new \yii\data\ActiveDataProvider(
[
"query"=>\app\models\base\News::find()->select('count(*)')->andwhere(['between', 'dt_pub', $b_date , $e_date])->andwhere(['<>', 'author', '5'])->andWhere(['show_author'=>'Y'])->groupBy(["author"]),
"pagination" =>false
]
);
$cnt3 = $newsDataProvidera->getCount();
?>
Авторов на ленте
=$cnt?> (подписаны материалы: =$cnt3?>)
=$cnt2?> Указаны авторы
время |
фото |
заголовок |
статусы |
управление |
if( isset( $newsDataProvider1 ) && $newsDataProvider1){
$items = array_reverse( $newsDataProvider1->getModels() );
}else{
$items = $newsDataProvider->getModels();
}
foreach( $items as $item ){
// print_r($item->getTopics());
$NewsItem[] = $item->id;
$strTopics = '';
foreach( $item->getTopics()->primaryModel->topics as $topic ){
$strTopics = $strTopics." [".$topic->title."]";
}
$strbage = '';
if( $item->verifed == 'Y' ) $strbage .= 'проверено
';
if( $item->top == 'Y' ) $strbage .= 'картина дня
';
if( $item->NH == 'Y' ) $strbage .= 'НЧ
';
if( $item->comments == 'N' ) $strbage .= 'no comments
';
if( ($item->flags & 1) == 1 ) $strbage .= 'без главной
';
if( $res = $cache->get("editNews_".$item->id) ){
$strbage .= ''.unserialize($res)['author'].'';
}
$author = Authors::getAuthor($item->author);
$show = ($item->active == 'N' || strtotime($item->dt_pub) > time())?'preview/'.$item->uid:$item->id;
$colorize = ($item->active == 'N' || strtotime($item->dt_pub) > time())?' class="table-secondary"':'';
$colorize = ($item->active == 'Y' && strtotime($item->dt_pub) > time())?' class="table-info"':$colorize;
$icon = $item->getImage()->getIcon();
?>
>
=date("H:i d-m-Y",strtotime($item->dt_pub))?> |
|
=$item->title?> =$strTopics?> =str_replace(',',' ',$item->editors)?>=$author->name?> |
=$strbage?> |
КДНЧuser->can('deleteNews')){?> }?> |
//
// print_r($item);
//
?>
}
?>
"+value+"");
console.log(key);
});
}
} );
}
JS;
$this->registerJs( $script,View::POS_READY);
//print_r($newsDataProvider->getModels());