<?php
$this->title="Активные рубрики";
if (Yii::$app->request->isGet && $post = Yii::$app->request->get('id')){
	$newsDataProvider = new \yii\data\ActiveDataProvider(
		[
			"query"=>\app\models\base\NewsTopic::find()->where(['active'=>1, 'topic_id'=>$post])->orderBy(["order"=>SORT_ASC]),
			"pagination" => false
		]
	);
	$this->title="Активные рубрики: ".$post;
}else{
	$newsDataProvider = new \yii\data\ActiveDataProvider(
		[
			"query"=>\app\models\base\NewsTopic::find()->where(['active'=>1, 'topic_id'=>null])->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="topicsort">
  <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" 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>
<?
	foreach( $newsDataProvider->getModels() as $item ){
//		print_r($item);
//return;
		$strbage = '<span class="badge badge-success">норма</span><br>';
		$mark = '';
		if( $item->active == 0 ){
			$mark = ' class="table-dark"';
			$strbage .= '<span class="badge badge-dark">удалено</span><br>';
		}
		if( $item->show == 'N' ){
			$mark = ' class="table-secondary"';
			$strbage .= '<span class="badge badge-secondary">Вне меню (спец.раздел)</span><br>';
		}
		if( $item->url == '----' ){
			$mark = ' class="table-info"';
			$strbage .= '<span class="badge badge-primary">Отбивка (спец.раздел)</span><br>';
		}
?>
    <tr<?=$mark?> class="ui-sortable" id="item_<?=$item->id?>">
      <th scope="row" class="text-nowrap"><?=$item->id?></th>
      <td><img src="/topic-images/<?=$item->id?>_size2.jpg" class="img-thumbnail" onerror="this.src='/images/topics/36_size2.jpg'"></td>
      <td><?=$item->title?><br><small><?=$item->description?></small></td>
      <td><?=$strbage?></td>
      <td><div class="btn-group btn-group-toggle" data-toggle="a" role="group">
      <a href="topiclist?id=<?=$item->id?>" role="button" class="btn btn-secondary btn-sm" title="подпункты"><i class="fa fa-list"></i></a>
      <a href="topicupdate?id=<?=$item->id?>" title="Править" role="button" class="btn btn-secondary btn-sm"><i class="far fa-edit"></i></a>
      <a href="topicshow?id=<?=$item->id?>" title="спрятать в меню" role="button" class="btn btn-secondary btn-sm"><i class="fa <?=($item->show == 'N')?'fa-eye-slash':'fa fa-eye'?>"></i></a>
      <a href="topicactive?id=<?=$item->id?>" title="не видно ни кому" role="button" class="btn btn-secondary btn-sm"><i class="fa <?=($item->active)?'fa-play':'fa fa-stop'?>"></i></a>
<?
		if( Yii::$app->user->can('admin') )
		{
?>
      <a href="topicdel?id=<?=$item->id?>" role="button" class="btn btn-secondary btn-sm" onClick="return confirm('Удалить?')" title="удалить"><i class="fa fa-trash"></i></a>
<?
		}
?>
      <a href="/topic/<?=$item->url?>" title="открыть на сайте" role="button" class="btn btn-secondary btn-sm"><i class="far fa-window-restore"></i></a>

    </tr>
<?
//	<pre>
//	print_r($item);
//	</pre>
?>
<?
	}
?>
  </tbody>
</table>
</div>
<script>
</script>

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