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>
65 lines
1.5 KiB
PHP
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 '';
|
|
}
|
|
}
|
|
}
|