@extends('layouts.default')

@section('title')
@parent
Новости проекта {{ $project->name }}
@stop

@section('js')
	<script src="{{ asset('js/news.js') }}"></script>
@stop

@section('content')

<?php $project_news = ProjectNews::whereRaw("project_id = 9 AND project_news.access_user_id IN ('0', ".Sentry::getUser()->id.')')->orderBy('created_at','DESC')->paginate(15); ?>

<div class="row">
  <div class="col-md-12">
		<h4>Новости проекта {{ $project->name }} 
		  <button class="btn btn-primary pull-right" onClick="location.href ='{{ URL::to('projects') }}/{{ $project->id }}/project_news/create'">Добавить новость</button>
		</h4>
		<div class="table-responsive">
			<table class="table table-striped table-hover">
				<thead>
				<th>Дата</th>
				<th>Рубрика</th>				
				<th>Название</th>
				<th>Содержание</th>				
				<th style="width: 18%">Действия</th>
				</thead>
				<tbody>
					@foreach ($project_news as $projectNews)
					<?php 
            $arr = explode(' ', $projectNews->created_at);
	          $arr1 = explode('-', $arr['0']);
            $date = $arr1['2'].'.'.$arr1['1'].'.'.$arr1['0']; 
          ?>
					<tr>
						<td>
							{{ $date }}
						</td>
						<td>
							{{ $projectNews->projectNewsTypes->name}}{{($projectNews->projectNewsTypes->type) ? ": {$projectNews->projectNewsTypes->type}" : "" }}
						</td>
						<td>
							<a href ='{{ action('ProjectNewsController@show', array($project->id, $projectNews->id)) }}'>{{ $projectNews->name }}</a>
						</td>
						<?php 
              $shortContent = mb_substr(strip_tags(html_entity_decode($projectNews->content)), 0, 150, 'UTF-8').'...';
            ?>
						<td>
							{{ $shortContent }}
						</td>
						<td>
							<button class="btn btn-sm btn-default" onClick="location.href ='{{ action('ProjectNewsController@edit', array($project->id, $projectNews->id)) }}'">Редактировать</button>
							<button class="btn btn-sm btn-default action_confirm" type="button" data-method="delete" href="{{ action('ProjectNewsController@destroy', array($project->id, $projectNews->id)) }}">Удалить</button>
						</td>
					</tr>
					<?php 
				    Session::put('urlBack', 'projects/9/project_news');
          ?>
					@endforeach
				</tbody>
			</table>
		</div>
		{{ $project_news->links(); }}
	</div>
</div>
@stop
