<?php
declare(strict_types=1);

namespace App\Controllers;

use App\Core\Controller;
use App\Core\Database;

final class PublicHomeController extends Controller
{
    public function index(): void
    {
        $db = Database::getInstance();

        // only active conferences should appear (if column exists)
        $hasActive = (int)$db->query("
            SELECT COUNT(*) FROM information_schema.columns
            WHERE table_schema=DATABASE() AND table_name='conferences' AND column_name='is_active'
        ")->fetchColumn() > 0;

        if ($hasActive) {
            $st = $db->query("SELECT * FROM conferences WHERE is_active=1 ORDER BY id DESC LIMIT 50");
        } else {
            $st = $db->query("SELECT * FROM conferences ORDER BY id DESC LIMIT 50");
        }
        $confs = $st->fetchAll() ?: [];

        $this->view('public/home/index', ['confs'=>$confs]);
    }
}
