76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Helpers\EntryHelpers;
|
|
use App\Models\Entry;
|
|
use App\Models\News;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class EntryController extends Controller
|
|
{
|
|
|
|
private const SECTION_TYPES = ['translations', 'romhacks', 'homebrew', 'utilities', 'documents', 'lua-scripts'];
|
|
|
|
public function index(): View
|
|
{
|
|
return view('entries.index');
|
|
}
|
|
|
|
public function section_redirect(string $section)
|
|
{
|
|
return redirect( databaseRoute( ['types' => [ $section ] ] ) );
|
|
}
|
|
|
|
public function show(string $section, Entry $entry): View
|
|
{
|
|
if (!in_array($section, self::SECTION_TYPES))
|
|
abort(404);
|
|
|
|
if ($entry->type !== $section)
|
|
abort(404);
|
|
|
|
if( !\Auth::guest() )
|
|
Gate::authorize('viewAny', $entry);
|
|
|
|
// Permissions.
|
|
$entryPolicy = match ($entry->state) {
|
|
'pending' => 'viewPending',
|
|
'draft' => 'viewDraft',
|
|
'rejected' => 'viewRejected',
|
|
'hidden' => 'viewHidden',
|
|
'locked' => 'viewLocked',
|
|
'published' => null,
|
|
'default' => null
|
|
};
|
|
|
|
if ($entryPolicy)
|
|
Gate::authorize($entryPolicy, $entry);
|
|
|
|
$comments = EntryHelpers::getLatestComments($entry);
|
|
$reviews = $entry->reviews()->orderBy('created_at', 'desc')->limit(10)->get();
|
|
|
|
return view('entries.show', compact('entry', 'section', 'comments', 'reviews'));
|
|
|
|
}
|
|
|
|
public function drafts(): View
|
|
{
|
|
$drafts = Entry::where('user_id', \Auth::user()->user_id )
|
|
->where('state', 'draft')
|
|
->with('game.platform', 'status')
|
|
->orderBy('updated_at', 'desc')
|
|
->paginate(20);
|
|
|
|
$newsDrafts = News::where('user_id', \Auth::user()->user_id )
|
|
->where('state', 'draft')
|
|
->orderBy('updated_at', 'desc')
|
|
->paginate(20);
|
|
|
|
return view('entries.drafts', compact('drafts', 'newsDrafts'));
|
|
}
|
|
|
|
}
|