<?php
use  \app\models\base\Story;
use  \app\models\base\NewsTopic;
use  \app\models\base\Tags;

$this->title="Главная страница";

$newsDataProvider = new \yii\data\ActiveDataProvider(
    [
        "query"=>\app\models\Design::find()->orderBy(["order"=>SORT_ASC]),
        "pagination" => false
    ]
);

?>
<div class="table-responsive-sm custom-range-badge">
<table class="table table-hover table-Light" id="sortable" data-ajax="sort">
  <thead class="bg-gray table-sm">
    <tr class="tr-state-disabled">
      <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" class="col-sm-1">управление</th>
    </tr>
  </thead>
  <tbody>
<?
	foreach( $newsDataProvider->getModels() as $item ){
//		print_r($item);
//return;
		$strbage = '';
		switch($item->type){
			case 'story':
				$model = Story::findOne($item->parent_id);
				break;
			case 'topic':
				$model = NewsTopic::findOne($item->parent_id);
				break;
			case 'tag':
				$model = Tags::findOne($item->parent_id);
				break;
			default:
				$title = $item->title;
				$model = null;
				break;
		}
		if( $model ){
			$title = (trim($item->title) == '')?$model->title:$item->title;
		}else{
			$strbage .= '<span class="badge badge-danger">Дохлый элемент</span><br>';
		}

		$mark = '';
		if( $item->active == 'N' ){
			$mark = ' class="table-dark"';
			$strbage .= '<span class="badge badge-dark">Спрятано</span><br>';
		}
		switch($item->design){
			case 1:
				$strbage .= '<i class="fa fa-image"></i> <i class="fa fa-dollar-sign"></i>';
				break;
			case 2:
				$strbage .= '<i class="fas fa-stream"></i><i class="fas fa-stream"></i><i class="fas fa-stream"></i><i class="fas fa-stream"></i>';
				break;
			case 3:
				$strbage .= '<i class="fa fa-map"></i>';
				break;
			case 4:
				$strbage .= '<i class="fa fa-image"></i><i class="fa fa-image"></i><i class="fa fa-image"></i>';
				break;
			case 5:
				$strbage .= '<i class="fa fa-image bg-warning"></i><i class="fa fa-image bg-primary"></i><i class="fa fa-image bg-warning"></i>';
				break;
			case 6:
				$strbage .= '<i class="fa fa-image"></i> <i class="fa fa-image"></i>';
				break;
			default:
				$strbage .= 'неопределён дизайн';
				break;
		}
?>
    <tr<?=$mark?> class="ui-sortable" id="item_<?=$item->id?>">
      <th scope="row" class="text-nowrap"><?=$item->id?></th>
      <td><?=$title?><br><small><?=($model && $model->description)?$model->description:''?><small></td>
      <td><?=$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="active?id=<?=$item->id?>" title="не видно ни кому" role="button" class="btn btn-secondary btn-sm"><i class="fa <?=($item->active == 'Y')?'fa-play':'fa fa-stop'?>"></i></a>
<?
		if( Yii::$app->user->can('admin') ){
?>
      <a href="del?id=<?=$item->id?>" role="button" class="btn btn-secondary btn-sm" onClick="return confirm('Удалить?')" title="удалить"><i class="fa fa-trash"></i></a>
<?
		}
?>
    </tr>
<?
//	<pre>
//	print_r($item);
//	</pre>
?>
<?
	}
?>
  </tbody>
</table>
</div>
<script>
</script>

<?php
//print_r($newsDataProvider->getModels());
