<?php
namespace App\Controller;
use App\Repository\PlanRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class CategoryController extends AbstractController
{
#[Route('/category/{slug}', name: 'app_category')]
public function show(string $slug, PlanRepository $planRepository): Response
{
// Convert slugs like 'xeon-kvm' to 'Xeon KVM Server' if needed, or better:
// just search the DB where category = $slug, or name contains '$slug' logic.
// For flexibility, let's map the slugs to actual human titles.
$slugToCategory = [
'xeon-kvm' => 'Xeon KVM Server',
'ryzen-kvm' => 'Ryzen KVM Server',
'epyc-kvm' => 'Epyc KVM Server',
'ipv6-kvm' => 'IPv6 Only KVM',
'intel-dedicated' => 'Intel Dedicated',
'amd-dedicated' => 'AMD Dedicated',
'sale-dedicated' => 'Sale Dedicated',
'gameserver' => 'Gameserver',
'webhosting' => 'Webhosting',
'nextcloud' => 'Nextcloud Hosting',
'colocation' => 'Colocation',
'object-storage' => 'Object Storage'
];
$title = $slugToCategory[$slug] ?? ucfirst(str_replace('-', ' ', $slug));
// Find plans where the category exactly matches the title.
$plans = $planRepository->findBy(['category' => $title], ['price' => 'ASC']);
return $this->render('category/index.html.twig', [
'slug' => $slug,
'title' => $title,
'plans' => $plans,
]);
}
}