Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into new-user-atrbs
Browse files Browse the repository at this point in the history
  • Loading branch information
paaton committed Nov 27, 2023
2 parents c5bf563 + a07c7ab commit 6386ce7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Application/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ public function addRoutesInto(App $app): App
})->add(AdminsOnlyMiddleware::class)->add(LoggedOnlyMiddleware::class);
});
});

$app->get($app->getBasePath() . '/{eventSlug}', EventController::class . '::redirectEvent')
->setName('redirectEvent');

return $app;
}
Expand Down
12 changes: 11 additions & 1 deletion src/Event/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ public function list(Response $response): Response
['events' => $this->eventRepository->findActiveNontestEvents()],
);
}

public function redirectEvent(string $eventSlug, Request $request, Response $response): Response
{
$event = $this->eventRepository->findBySlug($eventSlug);
if ($event === null) {
return $this->redirect($request, $response, 'eventList');
}

return $this->redirect($request, $response, 'getDashboard', ['eventSlug' => $event->slug]);
}

/*
public function createEvent(Request $request, Response $response, array $args) {
$params = $request->getParams();
Expand Down Expand Up @@ -67,6 +78,5 @@ public function createEvent(Request $request, Response $response, array $args) {
$this->flashMessages->warning('Některé údaje nebyly validní - prosím zkus zadání údajů znovu.');
return $response->withRedirect($this->router->urlFor('createEvent'));
// TODO add event-admins (roles table?)
}*/
}
5 changes: 5 additions & 0 deletions src/Event/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public function findActiveNontestAutopaymentsOnEvents(): array
'end_day' => new Relation(DateTimeUtils::getDateTime('-3 month')->format(DATE_ATOM), '>'),
]);
}

public function findBySlug(string $eventSlug): ?Event
{
return $this->findOneBy(['slug' => $eventSlug]);
}
}
2 changes: 1 addition & 1 deletion src/Middleware/EventInfoMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function process(Request $request, ResponseHandler $handler): Response
$route = $routeContext->getRoute();

$eventSlug = $route?->getArgument('eventSlug') ?? '';
$event = $this->eventRepository->findOneBy(['slug' => $eventSlug]);
$event = $this->eventRepository->findBySlug($eventSlug);
if ($event instanceof Event) {
$request = $request->withAttribute('event', $event);
$this->view->getEnvironment()->addGlobal('event', $event); // used in templates
Expand Down

0 comments on commit 6386ce7

Please sign in to comment.