File size: 1.56Kb
<?php
namespace App\Controllers;
use App\Core\Controller;
use App\Core\Request;
use App\Core\Response;
use App\Core\Session;
use App\Models\Forum;
class ForumController extends Controller
{
private Forum $forumModel;
public function __construct()
{
$this->forumModel = new Forum();
}
public function index(Request $request): Response
{
$forums = $this->forumModel->getAll();
$stats = $this->forumModel->getStats();
return $this->render('forum.index', compact('forums', 'stats'));
}
public function show(Request $request, string $slug): Response
{
$forum = $this->forumModel->findBySlug($slug);
if (!$forum) return new Response('Forum not found', 404);
return $this->render('forum.show', compact('forum'));
}
public function trending(Request $request): Response
{
$posts = $this->forumModel->getTrending(20);
return $this->render('forum.trending', compact('posts'));
}
public function stats(Request $request): Response
{
$stats = $this->forumModel->getStats();
return $this->render('forum.stats', compact('stats'));
}
public function search(Request $request): Response
{
$q = trim($request->get('q', ''));
$results = $this->forumModel->search($q);
return $this->render('forum.search', compact('q', 'results'));
}
public function moderationDash(Request $request): Response
{
return $this->render('forum.moderation');
}
}