added frontend and made it usable
This commit is contained in:
1 parent
96408f00d8
commit
b9b15152bc
50 files changed
+7974
-1
No files matched your search
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Repository\CategoryRepository;
|
||||
use App\Repository\EventRepository;
|
||||
use App\Service\EventMapSerializer;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class EventController extends AbstractController
|
||||
{
|
||||
private const PER_PAGE = 24;
|
||||
|
||||
#[Route('/events', name: 'event_list')]
|
||||
public function list(Request $request, EventRepository $events, CategoryRepository $categories): Response
|
||||
{
|
||||
$page = max(1, $request->query->getInt('page', 1));
|
||||
$category = $request->query->get('category') ?: null;
|
||||
$offset = (($page ?: 1) - 1) * self::PER_PAGE;
|
||||
|
||||
$items = $events->findPage(self::PER_PAGE, $offset, $category);
|
||||
$total = $events->countPage($category);
|
||||
|
||||
return $this->render('events/list.html.twig', [
|
||||
'activeNav' => 'events',
|
||||
'events' => $items,
|
||||
'categories' => $categories->findUsedNames(),
|
||||
'activeCategory' => $category,
|
||||
'page' => $page,
|
||||
'totalPages' => max(1, (int) ceil($total / self::PER_PAGE)),
|
||||
'total' => $total,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/events/{id}', name: 'event_show', requirements: ['id' => '\d+'])]
|
||||
public function show(int $id, EventRepository $events, EventMapSerializer $mapSerializer): Response
|
||||
{
|
||||
$event = $events->findOneNotDeleted($id);
|
||||
if (!$event) {
|
||||
throw $this->createNotFoundException('Event nicht gefunden.');
|
||||
}
|
||||
|
||||
return $this->render('events/show.html.twig', [
|
||||
'activeNav' => 'events',
|
||||
'event' => $event,
|
||||
'mapEventJson' => $event->hasCoordinates() ? $mapSerializer->toJson([$event]) : '[]',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user