@extends('layouts.default')

@section('title')
@parent
Обучающие материалы
@stop

@section('content')
<?php $project_news = ProjectNews::whereRaw("project_id = 9 AND type_id IN (5, 6) AND project_news.access_user_id IN ('0', ".Sentry::getUser()->id.')')->orderBy('created_at','DESC')->paginate(10); ?>
<div class="panel panel-default">
  <div class="panel-heading">
    <ul class="nav nav-tabs">
	    <li> 
		    <h4>Обучающие материалы: &nbsp;</h4>
	    </li>
	    <?php $training = ProjectNewsTypes::whereIn('id', array(5,6))->get() ?>
	    @foreach ($training as $trainingType)
	    <li>
		    <a href="training/part/{{ $trainingType->id}}">{{ $trainingType->type }}
		      <span class="badge"><?php $q = ProjectNews::whereRaw("project_id = 9 AND type_id =".$trainingType->id." AND project_news.access_user_id IN ('0', ".Sentry::getUser()->id.') AND project_news.id NOT IN (SELECT project_news_viewed.project_news_id FROM  project_news_viewed WHERE user_id = '.Sentry::getUser()->id.' )')->count(); echo ($q ? $q : '') ?></span>
		    </a>
	    </li>
	  @endforeach
    </ul>
	</div>
  <div class="panel-body">
  			<table>
	  			<thead>
	  			<th></th>			
	  			</thead>
	  			<tbody>
				  	@foreach ($project_news as $projectNews)
				  	<tr>
							<td class="news-list">
								<h3>{{ $projectNews->name }} 
									@if (! DB::table('project_news_viewed')->whereRaw('project_news_id ='.$projectNews->id.' AND user_id = '.Sentry::getUser()->id)->first() )
									<span class="label label-danger">Новая</span>
									@endif
								</h3>
								<?php 
    	            $arr = explode(' ', $projectNews->created_at);
	  	            $arr1 = explode('-', $arr['0']);
    	            $date = $arr1['2'].'.'.$arr1['1'].'.'.$arr1['0']; 
    	          ?>
								<div>{{ $date }} -
								{{ $projectNews->projectNewsTypes->name}}{{($projectNews->projectNewsTypes->type) ? ": {$projectNews->projectNewsTypes->type}" : "" }}
								</div>
								<?php 
    	            $shortContent = mb_substr(strip_tags(html_entity_decode($projectNews->content)), 0, 300, 'UTF-8').'...';
    	          ?>
								<div> {{ $shortContent }} </div>
								<a href ='{{ action('ProjectNewsController@show', array($project->id, $projectNews->id)) }}'>Подробнее</a>
							</td>
						</tr>
					  <?php 
							Session::put('urlBack', 'projects/9/training/');
            ?>
					@endforeach
	  			</tbody>
	  		</table>
  </div>
	{{ $project_news->links(); }}
</div>
@stop