123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- use app\models\Authors;
- 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
- ],
- ]
- );
- */
- $b_date = date("Y-m-d 00:00:00",time()-60*60*24*5);
- $e_date = date("3000-m-d 23:59:59");
- $tnow = date("Y-m-d H:i:s");
- //\app\models\base\News::find()->andwhere(['between', 'dt_pub', $b_date , $e_date])->orwhere(['active'=>'N'])->orderBy(["dt_pub"=>SORT_DESC])->limit(200)
- //echo "SELECT * FROM `news` WHERE (`dt_pub` between '$b_date' and '$e_date' and `active`='N') or (`dt_pub` > '$tnow' and `active`='Y')"; exit;
- $newsDataProvider = new \yii\data\ActiveDataProvider(
- [
- "query"=>\app\models\base\News::findBySql("SELECT * FROM `news` FORCE INDEX(`calendar`) WHERE (`dt_pub` between '$b_date' and '$e_date' and `active`='N') or (`dt_pub` > '$tnow' and `active`='Y') order by `dt_pub` DESC"),
- "pagination" =>[
- "pageSize"=>200
- ],
- ]
- );
- $cache = Yii::$app->cache;
- /**** ****/
- ?>
- <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>
- <?
- $NewsItem = array();
- foreach( $newsDataProvider->getModels() as $item ){
- // print_r($item->getTopics());
- $strTopics = '';
- $NewsItem[] = $item->id;
- 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">'.unserialize($res)['author'].'</span><br>';
- }
- $show = ($item->active == 'N' || strtotime($item->dt_pub) > time())?'preview/'.$item->uid:$item->id;
- $author = Authors::getAuthor($item->author);
- $icon = $item->getImage()->getIcon();
- ?>
- <tr<?=($item->active == 'N')?' class="table-secondary"':''?>>
- <th scope="row" class="text-nowrap"><span class="<?=( strtotime($item->dt_pub) < time() )?'text-fuchsia':''?>"><?=date("H:i d-m-Y",strtotime($item->dt_pub))?></span></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></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());
|