<?php
use  \app\models\News;
use  \app\models\base\Kd;
use app\models\base\Image;
global $dcount;
$dcount = 20;
$a1 = [];
$this->title='Главная "картина дня"';

$nhc = new \yii\data\ActiveDataProvider(
    [
        "query"=>News::getNH(), //News::find()->andWhere(['active'=>'Y', 'NH'=>['Y','F']])->orderBy(["NH"=>SORT_DESC,"dt_pub"=>SORT_DESC])->limit(1),
        "pagination" => false
    ]
);

$nh = new \yii\data\ActiveDataProvider(
    [
        "query"=>News::find()->where(['active'=>'Y'])->andWhere(['<>', 'NH', 'N'])->andWhere(['>', 'dt_pub', date("Y-m-d H:i:s")])->orderBy(["dt_pub"=>SORT_DESC])->limit(10),
        "pagination" => false
    ]
);

print_a($nh->query->createCommand()->rawSQL);
?>

<div class="">
	<div class="row">
<?
	draw( $cur = $nhc->getModels()[0], true);
	foreach( $sort = $nh->getModels() as $item ){
		if($cur->id != $item->id)
		{
			$a1[$item->id] = $item->id;
			draw($item);
		}
	}
	if($cur == false){
?>
<div class="col-sm-3 p-2">
	<div class="position-relative p-3 bg-gray" style="height: 300px">
		<div class="ribbon-wrapper ribbon-lg">
			<div class="ribbon bg-danger text-lg">
				Внимание
			</div>
		</div>
		<h3>НЧ пуста, срочно поставте НЧ</h3>
	</div>
</div>
<?
	}

	if($sort == false){
?>
<div class="col-sm-3 p-2">
	<div class="position-relative p-3 bg-gray" style="height: 300px">
		<div class="ribbon-wrapper ribbon-lg">
			<div class="ribbon bg-danger text-lg">
				Внимание
			</div>
		</div>
		<h1>Очередь пуста, поставте НЧ на будующие периоды</h1>
	</div>
</div>
<?
	}
?>
	</div>
</div>
<?
function draw($item, $cur = false){
	global $dcount;
	static $i = 0;
	$preview = $item->preview;
?>

<div class="col-sm-3 p-2">
	<div class="position-relative p-3 bg-gray" style="height: auto">
		<img src="<?=$preview->getUrl(Image::SIZE_680x383)?>" alt="Photo 1" class="img-fluid">
		<div class="ribbon-wrapper ribbon-lg">
			<div class="ribbon <?=($cur)?'bg-success':'bg-info'?> text-lg">
				<?=($cur)?'Сейчас':'Будет'?>
			</div>
		</div>
<?
	if( $item->NH == 'F'){
		echo "<span style='position:absolute;top:10px;right:7px;'><i class='fas fa-thumbtack text-fuchsia' style='font-size: 24px; text-shadow: #000 2px 2px 4px;'></i></span>";
	}
?>
		<?=date( "d-m-Y h:i", strtotime($item->dt_pub))?><br><?=$item->title?><br>
		<a href="/manager/news/update?id=<?=$item->id?>" class="btn btn-primary">Редактор</a><a href="/manager/nh/fix?id=<?=$item->id?>" class="btn btn-primary">Закрепить</a><a href="/manager/nh/del?id=<?=$item->id?>" class="btn btn-primary">Убрать</a>
	</div>
</div>
<?
	$i++;
}
