Files
wk-sync-bundle/src/Booking/BookingUrlBuilder.php
T
admin.juergenandClaude Fable 5.1 142afa6e52 Initial version of the W&K sync bundle for Contao 5.7
Import of W&K seminar exports with preview, booking form via form generator
with event-dependent field rules, notification routing, inbox with folders
and CSV export for W&K.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-24 17:42:34 +02:00

65 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Mummert\ContaoWkSyncBundle\Booking;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\Routing\ContentUrlGenerator;
use Contao\PageModel;
use Mummert\ContaoWkSyncBundle\Sync\CalendarConfig;
/**
* Links zur Anmeldeseite und zum Anfrageformular.
*/
class BookingUrlBuilder
{
public function __construct(
private readonly ContaoFramework $framework,
private readonly ContentUrlGenerator $urlGenerator,
) {
}
public function bookingUrl(BookingEvent $event, CalendarConfig $calendar): string
{
$url = $this->pageUrl($calendar->bookingPage);
if ('' === $url) {
return '';
}
return rtrim($url, '/').'/'.($event->alias ?: $event->id);
}
public function inquiryUrl(BookingEvent $event, CalendarConfig $calendar): string
{
$url = $this->pageUrl($calendar->inquiryPage);
if ('' === $url) {
return '';
}
return $url.(str_contains($url, '?') ? '&' : '?').'event='.$event->id;
}
public function pageUrl(int $pageId): string
{
if ($pageId < 1) {
return '';
}
$this->framework->initialize();
$page = $this->framework->getAdapter(PageModel::class)->findPublishedById($pageId);
if (null === $page) {
return '';
}
try {
return $this->urlGenerator->generate($page);
} catch (\Throwable) {
return '';
}
}
}