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

98 lines
3.0 KiB
PHP
Raw Normal View History

2026-06-02 20:54:10 +02:00
<?php
namespace App\Http\Controllers;
use App\Helpers\XenForoHelpers;
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 App\Services\XenforoService;
use Illuminate\Http\Request;
class QueueController extends Controller
{
public function index()
{
$entries = Entry::inQueue()
->with(['authors', 'game.platform'])
->orderByRaw("CASE WHEN state = 'pending' THEN 1 ELSE 0 END")
->orderBy('created_at', 'asc')
2026-06-16 16:21:43 +02:00
->get()
->map(fn($item) => $item->setAttribute('queue_type', 'entry'));
$news = News::inQueue()
->orderByRaw("CASE WHEN state = 'pending' THEN 1 ELSE 0 END")
->orderBy('created_at', 'asc')
->get()
->map(fn($item) => $item->setAttribute('queue_type', 'news'));
$entries = $entries->concat($news)->sort(function($a, $b) {
$aPending = $a->state === 'pending' ? 0 : 1;
$bPending = $b->state === 'pending' ? 0 : 1;
if($aPending !== $bPending) {
return $aPending <=> $bPending;
}
return $a->created_at <=> $b->created_at;
})->values();
2026-06-02 20:54:10 +02:00
return view('queue.index', compact('entries'));
}
public function updateComment(Request $request, Entry $entry)
{
$request->validate(['comment' => 'nullable|string|max:2000']);
$entry->update(['staff_comment' => $request->input('comment')]);
2026-06-16 16:21:43 +02:00
return back()->with('success', 'Comment supdated');
}
public function updateComment_news(Request $request, News $news)
{
$request->validate(['comment' => 'nullable|string|max:2000']);
$news->update(['staff_comment' => $request->input('comment')]);
2026-06-02 20:54:10 +02:00
return back()->with('success', 'Comment updated');
}
public function approve(Request $request, Entry $entry)
{
2026-06-16 16:21:43 +02:00
$entry->update(['state' => 'published', 'created_at' => now()]);
2026-06-02 20:54:10 +02:00
XenForoHelpers::entryApproved($entry);
return back()->with('success', 'Entry approved');
}
2026-06-16 16:21:43 +02:00
public function approve_news(Request $request, News $news)
{
$news->update(['state' => 'published', 'created_at' => now()]);
XenForoHelpers::entryApproved($news);
return back()->with('success', 'Entry approved');
}
2026-06-02 20:54:10 +02:00
public function reject(Request $request, Entry $entry)
{
$request->validate(['reason' => 'nullable|string|max:2000']);
$entry->update(['state' => 'rejected', 'staff_comment' => $request->input('reason'), 'rejected_at' => now() ]);
2026-06-16 16:21:43 +02:00
XenForoHelpers::entryRejected($entry);
return back()->with('success', 'Entry rejected');
}
public function reject_news(Request $request, News $news)
{
$request->validate(['reason' => 'nullable|string|max:2000']);
$news->update(['state' => 'rejected', 'staff_comment' => $request->input('reason'), 'rejected_at' => now() ]);
XenForoHelpers::entryRejected($news);
2026-06-02 20:54:10 +02:00
return back()->with('success', 'Entry rejected');
}
}