Files
RomhackPlaza/app/Http/Controllers/EntryController.php

75 lines
1.9 KiB
PHP
Raw Normal View History

2026-05-20 18:25:15 +02:00
<?php
namespace App\Http\Controllers;
2026-05-27 21:24:38 +02:00
use App\Helpers\EntryHelpers;
2026-05-20 18:25:15 +02:00
use App\Models\Entry;
2026-06-16 16:21:43 +02:00
use App\Models\News;
2026-06-02 20:54:10 +02:00
use Illuminate\Support\Facades\Gate;
2026-05-20 18:25:15 +02:00
use Illuminate\Http\Request;
use Illuminate\View\View;
class EntryController extends Controller
{
2026-06-16 16:21:43 +02:00
private const SECTION_TYPES = ['translations', 'romhacks', 'homebrew', 'utilities', 'documents', 'lua-scripts'];
2026-05-20 18:25:15 +02:00
public function index(): View
{
return view('entries.index');
2026-05-20 18:25:15 +02:00
}
2026-06-08 16:25:52 +02:00
public function section_redirect(string $section)
{
return redirect( databaseRoute( ['types' => [ $section ] ] ) );
}
2026-05-20 18:25:15 +02:00
public function show(string $section, Entry $entry): View
{
2026-06-02 20:54:10 +02:00
if (!in_array($section, self::SECTION_TYPES))
2026-05-20 18:25:15 +02:00
abort(404);
2026-06-02 20:54:10 +02:00
if ($entry->type !== $section)
2026-05-20 18:25:15 +02:00
abort(404);
2026-06-16 16:21:43 +02:00
if( !\Auth::guest() )
Gate::authorize('viewAny', $entry);
2026-06-02 20:54:10 +02:00
// 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);
2026-05-27 21:24:38 +02:00
2026-06-02 20:54:10 +02:00
return view('entries.show', compact('entry', 'section', 'comments'));
2026-05-20 18:25:15 +02:00
}
2026-06-08 16:25:52 +02:00
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);
2026-06-16 16:21:43 +02:00
$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'));
2026-06-08 16:25:52 +02:00
}
2026-05-20 18:25:15 +02:00
}