diff --git a/Plugin.php b/Plugin.php index 5d12c30..76ad665 100644 --- a/Plugin.php +++ b/Plugin.php @@ -3,6 +3,7 @@ namespace Silva\Adrema; use Backend; +use Silva\Adrema\Components\EventDescription; use Silva\Adrema\Components\EventIndex; use Silva\Adrema\Components\EventRegister; use Silva\Adrema\Models\Settings; @@ -52,6 +53,7 @@ class Plugin extends PluginBase return [ EventIndex::class => 'adrema_event_index', EventRegister::class => 'adrema_event_register', + EventDescription::class => 'adrema_event_description', ]; } diff --git a/assets/vendor/adrema-form b/assets/vendor/adrema-form index c55bb17..9666310 160000 --- a/assets/vendor/adrema-form +++ b/assets/vendor/adrema-form @@ -1 +1 @@ -Subproject commit c55bb174c2caa5ed1cda99a04c877455e0387f13 +Subproject commit 9666310ebfa9125ea0d2771b63166b39d7179999 diff --git a/components/EventDescription.php b/components/EventDescription.php new file mode 100644 index 0000000..34b7990 --- /dev/null +++ b/components/EventDescription.php @@ -0,0 +1,17 @@ +loadColors(); + $this->loadSingleEvent(); + } + + public function isRegistering(): bool + { + return false; + } +} diff --git a/components/EventIndex.php b/components/EventIndex.php index 02ae3e9..9a8daf1 100644 --- a/components/EventIndex.php +++ b/components/EventIndex.php @@ -4,4 +4,8 @@ namespace Silva\Adrema\Components; class EventIndex extends EventManager { + protected function isRegistering(): bool + { + return false; + } } diff --git a/components/EventManager.php b/components/EventManager.php index 1e39e60..5564e17 100644 --- a/components/EventManager.php +++ b/components/EventManager.php @@ -2,18 +2,24 @@ namespace Silva\Adrema\Components; +use Illuminate\Support\Collection; use Cms\Classes\ComponentBase; use Cms\Classes\Page; use Silva\Adrema\Exceptions\ComponentException; use Silva\Adrema\Models\Settings; +use Silva\Adrema\Support\FetchAllEvents; use Silva\Adrema\Support\FetchSingleEvent; abstract class EventManager extends ComponentBase { - public array $settings; - public ?array $event; + public array $settings = []; + public ?array $event = null; + + /** @var Collection */ + public Collection $events; public string $currentUrl; + abstract protected function isRegistering(): bool; public function componentDetails() { @@ -28,8 +34,34 @@ abstract class EventManager extends ComponentBase public function onRun() { $this->addAssets(); + $this->loadColors(); $this->loadSettings(); $this->loadSingleEvent(); + $this->page['breadcrumbs'] = $this->getBreadcrumbs(); + } + + private function getBreadcrumbs(): Collection + { + $breadcrumbs = collect([]); + $breadcrumbs->push(['url' => $this->settings['indexUrl'], 'title' => 'Veranstaltungen', 'isActive' => $this->event === null]); + + if ($this->event) { + $breadcrumbs->push([ + 'url' => (string) str($this->settings['singleUrl'])->replace(':slug', $this->event['slug']), + 'title' => $this->event['name'], + 'isActive' => !$this->isRegistering() + ]); + } + + if ($this->event && $this->isRegistering()) { + $breadcrumbs->push([ + 'url' => (string) str($this->settings['registerUrl'])->replace(':slug', $this->event['slug']), + 'title' => 'Anmeldung', + 'isActive' => true, + ]); + } + + return $breadcrumbs; } public function defineProperties() @@ -109,7 +141,7 @@ abstract class EventManager extends ComponentBase ]; } - private function loadSingleEvent(): void + protected function loadSingleEvent(): void { $eventSlug = $this->property('eventSlug'); @@ -117,8 +149,8 @@ abstract class EventManager extends ComponentBase return; } - $this->event = app(FetchSingleEvent::class)->run($eventSlug); - $this->page->title = $this->event['name']; + $this->events = $this->page['events'] = collect(app(FetchAllEvents::class)->run()['data']); + $this->event = $this->page['event'] = $this->events->first(fn ($event) => $event['slug'] == $eventSlug); $this->currentUrl = url()->current(); } @@ -131,8 +163,16 @@ abstract class EventManager extends ComponentBase private function loadSettings(): void { $this->settings = [ - 'primary_color' => Settings::get('primary_color'), + ...$this->settings, ...$this->resolvePageUrls(), ]; } + + protected function loadColors(): void + { + $this->settings = [ + ...$this->settings, + 'primary_color' => Settings::get('primary_color'), + ]; + } } diff --git a/components/EventRegister.php b/components/EventRegister.php index 5b5b5da..06065f5 100644 --- a/components/EventRegister.php +++ b/components/EventRegister.php @@ -4,4 +4,8 @@ namespace Silva\Adrema\Components; class EventRegister extends EventManager { + protected function isRegistering(): bool + { + return true; + } } diff --git a/components/eventdescription/default.htm b/components/eventdescription/default.htm new file mode 100644 index 0000000..17ed198 --- /dev/null +++ b/components/eventdescription/default.htm @@ -0,0 +1,9 @@ + + + diff --git a/components/eventregister/default.htm b/components/eventregister/default.htm index aea7ff8..5e7dd95 100644 --- a/components/eventregister/default.htm +++ b/components/eventregister/default.htm @@ -5,4 +5,5 @@ index-url="{{__SELF__.settings.indexUrl}}" single-url="{{__SELF__.settings.singleUrl}}" register-url="{{__SELF__.settings.registerUrl}}" + config-var-name="adrema_event_config" > diff --git a/support/FetchAllEvents.php b/support/FetchAllEvents.php index 68be16a..b610b2f 100644 --- a/support/FetchAllEvents.php +++ b/support/FetchAllEvents.php @@ -2,10 +2,17 @@ namespace Silva\Adrema\Support; +use Illuminate\Support\Collection; + class FetchAllEvents { - public function run(): ?array + public function run(): ?Collection { - return app(Proxy::class)->run('/api/form'); + $events = app(Proxy::class)->run('/api/form'); + + if (!$events) { + return null; + } + return collect($events); } } diff --git a/views/head.htm b/views/head.htm index 1bad2dd..2a2b7de 100644 --- a/views/head.htm +++ b/views/head.htm @@ -6,13 +6,14 @@ {% endput %} + + {% endif %} {% put metatags %} {% endput %} -