123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- use app\models\Authors;
- use yii\sphinx\Query;
- use yii\web\View;
- $this->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);
- /**** ****/
- ?>
- <div class="row">
- <div class="info-box col-3 m-1">
- <span class="info-box-icon bg-info"><i class="far fa-copy"></i></span>
- <div class="info-box-content">
- <span class="info-box-text">Материалов</span>
- <span class="info-box-number"><?=$cnt?></span>
- <div class="progress">
- <div class="progress-bar bg-info" style="width: <?=$prc?>%"></div>
- </div>
- <span class="progress-description">
- <?=$prc?>% Среднее за день
- </span>
- </div>
- </div>
- <?
- $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();
- ?>
- <div class="info-box col-3 m-1">
- <span class="info-box-icon bg-info"><i class="far fa-copy"></i></span>
- <div class="info-box-content">
- <span class="info-box-text">Авторов на ленте</span>
- <span class="info-box-number"><?=$cnt?> (подписаны материалы: <?=$cnt3?>)</span>
- <span class="info-box-number">
- <?=$cnt2?> Указаны авторы
- </span>
- </div>
- </div>
- </div>
- <div class="table-responsive-sm custom-range-badge">
- <table class="table table-hover table-Light">
- <thead class="bg-gray table-sm">
- <tr>
- <th scope="col" class="col-md-1 col-sm-2 col-xs-5">время</th>
- <th scope="col" class="col-md-1 col-sm-2 col-xs-5">фото</th>
- <th scope="col">заголовок</th>
- <th scope="col">статусы</th>
- <th scope="col">управление</th>
- </tr>
- </thead>
- <tbody>
- <?
- 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 .= '<span class="badge badge-success font-weight-normal">проверено</span><br>';
- if( $item->top == 'Y' ) $strbage .= '<span class="badge badge-primary font-weight-normal">картина дня</span><br>';
- if( $item->NH == 'Y' ) $strbage .= '<span class="badge badge-info font-weight-normal">НЧ</span><br>';
- if( $item->comments == 'N' ) $strbage .= '<span class="badge badge-secondary font-weight-normal">no comments</span><br>';
- if( ($item->flags & 1) == 1 ) $strbage .= '<span class="badge badge-warning font-weight-normal">без главной</span><br>';
- if( $res = $cache->get("editNews_".$item->id) ){
- $strbage .= '<span class="badge badge-danger font-weight-normal author">'.unserialize($res)['author'].'</span>';
- }
- $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();
- ?>
- <tr<?=$colorize?>>
- <th scope="row" class="text-nowrap"><?=date("H:i d-m-Y",strtotime($item->dt_pub))?></th>
- <td><img src="<?=$icon?>" onerror="this.src='/images/defaultsm.jpg'" width="94" height="auto"></td>
- <td><?=$item->title?><br><small><?=$strTopics?><br><?=str_replace(',',' ',$item->editors)?></small><small class="bg-olive px-1"><?=$author->name?></small></td>
- <td rel_id="<?=$item->id?>"><?=$strbage?></td>
- <td><div class="btn-group btn-group-toggle" data-toggle="a" role="group"><a href="update?id=<?=$item->id?>" title="Править" role="button" class="btn btn-secondary btn-sm"><i class="far fa-edit"></i></a><a href="newsshow?id=<?=$item->id?>" title="спрятать" role="button" class="btn btn-sm btn-secondary"><i class="fa <?=($item->active == 'N')?'fa-eye-slash':'fa fa-eye'?>"></i></a><a href="newskd?id=<?=$item->id?>" role="button" class="btn btn-sm <?=($item->top == 'N')?'btn-secondary':'btn-primary'?>">КД</a><a href="newsnh?id=<?=$item->id?>" role="button" class="btn <?=($item->NH == 'N')?'btn-secondary':'btn-primary'?> btn-sm">НЧ</a><a href="/news/<?=$show?>" title="открыть на сайте" role="button" class="btn btn-secondary btn-sm" target="_blank"><i class="far fa-window-restore"></i></a><?if(Yii::$app->user->can('deleteNews')){?><a href="delete?id=<?=$item->id?>" title="открыть на сайте" role="button" class="btn btn-secondary btn-sm" target="_blank" onclick="return confirm('Вы уверены?')"><i class="fa fa-trash"></i></a><?}?></div></td>
- </tr>
- <?
- // <pre>
- // print_r($item);
- // </pre>
- ?>
- <?
- }
- ?>
- </tbody>
- </table>
- </div>
- <?php
- $ni = serialize($NewsItem);
- $nij = json_encode($NewsItem);
- $script = <<< JS
- setInterval( function (){ testping() }, 10000 );
- function testping(){
- $.get( 'testping', { cmd: 'GetAuthors', data: '$ni' }, function(data){
- data = JSON.parse(data);
- if( data.status == 'ok' ){
- var dn = JSON.parse('$nij');
- $.each( dn, function( key, value ) {
- $("[rel_id='"+value+"'] .author").remove();
- $("[rel_id='"+value+"'] br:last-child").remove();
- });
- $.each( data['authors'], function( key, value ) {
- // $("[rel_id='"+key+"'] .author").remove();
- // $("[rel_id='"+key+"'] br:last-child").remove();
- $("[rel_id='"+key+"']").append("<span class='badge badge-danger font-weight-normal author'>"+value+"</span>");
- console.log(key);
- });
- }
- } );
- }
- JS;
- $this->registerJs( $script,View::POS_READY);
- //print_r($newsDataProvider->getModels());
|