Compare commits

..

No commits in common. "master" and "dev" have entirely different histories.
master ... dev

8 changed files with 7 additions and 51 deletions

@ -1 +1 @@
Subproject commit e4fa326f3593fc61573bd81bfdfe75a3d4711124 Subproject commit 3907395506afab856559972fe7f19d2b8ccba8cd

View File

@ -8,7 +8,6 @@ use Cms\Classes\Page;
use Silva\Adrema\Exceptions\ComponentException; use Silva\Adrema\Exceptions\ComponentException;
use Silva\Adrema\Models\Settings; use Silva\Adrema\Models\Settings;
use Silva\Adrema\Support\FetchAllEvents; use Silva\Adrema\Support\FetchAllEvents;
use Validator;
abstract class EventManager extends ComponentBase abstract class EventManager extends ComponentBase
{ {
@ -16,7 +15,6 @@ abstract class EventManager extends ComponentBase
public array $settings = []; public array $settings = [];
public ?array $event = null; public ?array $event = null;
public array $eventMeta = []; public array $eventMeta = [];
public array $pageMeta = [];
/** @var Collection<int, mixed> */ /** @var Collection<int, mixed> */
public Collection $events; public Collection $events;
@ -39,31 +37,17 @@ abstract class EventManager extends ComponentBase
$this->loadColors(); $this->loadColors();
$this->loadSettings(); $this->loadSettings();
$this->loadSingleEvent(); $this->loadSingleEvent();
$this->loadQueryParams();
$this->page['breadcrumbs'] = $this->getBreadcrumbs(); $this->page['breadcrumbs'] = $this->getBreadcrumbs();
} }
private function loadQueryParams(): array {
$validator = Validator::make(array_only(request()->query(), ['signature', 'id', 'later']), [
'signature' => 'required|string',
'id' => 'required|string|uuid:4',
'later' => 'required|numeric|in:1',
]);
return $validator->fails()
? ['later' => '0']
: $validator->validated();
}
private function getBreadcrumbs(): Collection private function getBreadcrumbs(): Collection
{ {
$breadcrumbs = collect([]); $breadcrumbs = collect([]);
$breadcrumbs->push(['url' => '/', 'title' => 'Start', 'isActive' => false]);
$breadcrumbs->push(['url' => $this->settings['indexUrl'], 'title' => 'Veranstaltungen', 'isActive' => $this->event === null]); $breadcrumbs->push(['url' => $this->settings['indexUrl'], 'title' => 'Veranstaltungen', 'isActive' => $this->event === null]);
if ($this->event) { if ($this->event) {
$breadcrumbs->push([ $breadcrumbs->push([
'url' => str($this->settings['singleUrl'])->replace(':slug', $this->event['slug'])->toString(), 'url' => (string) str($this->settings['singleUrl'])->replace(':slug', $this->event['slug']),
'title' => $this->event['name'], 'title' => $this->event['name'],
'isActive' => !$this->isRegistering() 'isActive' => !$this->isRegistering()
]); ]);
@ -71,7 +55,7 @@ abstract class EventManager extends ComponentBase
if ($this->event && $this->isRegistering()) { if ($this->event && $this->isRegistering()) {
$breadcrumbs->push([ $breadcrumbs->push([
'url' => str($this->settings['registerUrl'])->replace(':slug', $this->event['slug'])->toString(), 'url' => (string) str($this->settings['registerUrl'])->replace(':slug', $this->event['slug']),
'title' => 'Anmeldung', 'title' => 'Anmeldung',
'isActive' => true, 'isActive' => true,
]); ]);
@ -169,7 +153,6 @@ abstract class EventManager extends ComponentBase
$this->eventMeta = data_get($eventData, 'meta', []); $this->eventMeta = data_get($eventData, 'meta', []);
$this->events = $this->page['events'] = collect($eventData['data']); $this->events = $this->page['events'] = collect($eventData['data']);
$this->event = $this->page['event'] = $this->events->first(fn ($event) => $event['slug'] == $eventSlug); $this->event = $this->page['event'] = $this->events->first(fn ($event) => $event['slug'] == $eventSlug);
$this->pageMeta = $this->loadQueryParams();
$this->currentUrl = url()->current(); $this->currentUrl = url()->current();
} }

View File

@ -1,6 +1,5 @@
{% include 'silva.adrema::head' %} {% include 'silva.adrema::head' %}
{% if __SELF__.event.can_register %}
<event-form <event-form
style="--primary: {{__SELF__.settings.primary_color}}; --secondary: {{__SELF__.settings.secondary_color}}; --font: {{__SELF__.settings.font_color}}; --circle: {{__SELF__.settings.circle_color}}" style="--primary: {{__SELF__.settings.primary_color}}; --secondary: {{__SELF__.settings.secondary_color}}; --font: {{__SELF__.settings.font_color}}; --circle: {{__SELF__.settings.circle_color}}"
index-url="{{__SELF__.settings.indexUrl}}" index-url="{{__SELF__.settings.indexUrl}}"
@ -10,4 +9,3 @@
form-id="{{__SELF__.event.id }}" form-id="{{__SELF__.event.id }}"
scroll scroll
></event-form> ></event-form>
{% endif %}

View File

@ -1,11 +1,8 @@
<?php <?php
use Silva\Adrema\Support\ClearCache;
use Silva\Adrema\Support\Proxy; use Silva\Adrema\Support\Proxy;
Route::get('/adrema-api/{route}', fn (string $route) => Response::json(app(Proxy::class)->run($route, 'get'))) Route::get('/adrema-api/{route}', fn (string $route) => Response::json(app(Proxy::class)->run($route, 'get')))
->where('route', '[a-zA-Z0-9\-/]+')->middleware('api'); ->where('route', '[a-zA-Z0-9\-/]+')->middleware('api');
Route::post('/adrema-api/{route}', fn (string $route) => app(Proxy::class)->submit($route)) Route::post('/adrema-api/{route}', fn (string $route) => app(Proxy::class)->submit($route))
->where('route', '[a-zA-Z0-9\-/]+')->middleware('api'); ->where('route', '[a-zA-Z0-9\-/]+')->middleware('api');
Route::get('/adrema/clear-cache', fn () => app(ClearCache::class)->run());

View File

@ -1,13 +0,0 @@
<?php
namespace Silva\Adrema\Support;
use Cache;
class ClearCache
{
public function run(): void
{
Cache::forget('adrema-all-events');
}
}

View File

@ -3,17 +3,19 @@
namespace Silva\Adrema\Support; namespace Silva\Adrema\Support;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Cache;
class FetchAllEvents class FetchAllEvents
{ {
public function run(): ?Collection public function run(): ?Collection
{ {
$events = app(Proxy::class)->run('api/form'); $events = Cache::remember('adrema-all-events', 3600, function () {
return app(Proxy::class)->run('/api/form');
});
if (!$events) { if (!$events) {
return null; return null;
} }
return collect($events); return collect($events);
} }
} }

View File

@ -2,7 +2,6 @@
namespace Silva\Adrema\Support; namespace Silva\Adrema\Support;
use Cache;
use Silva\Adrema\Models\Settings; use Silva\Adrema\Models\Settings;
use Http; use Http;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
@ -10,15 +9,6 @@ use Illuminate\Http\JsonResponse;
class Proxy class Proxy
{ {
public function run(string $url): ?array public function run(string $url): ?array
{
if ($url === 'api/form') {
return Cache::rememberForever('adrema-all-events', fn () => $this->get($url));
}
return $this->get($url);
}
protected function get(string $url): ?array
{ {
$response = Http::acceptJson()->get($this->url($url)); $response = Http::acceptJson()->get($this->url($url));

View File

@ -10,7 +10,6 @@
<script type="text/javascript"> <script type="text/javascript">
var adrema_event_config = {{__SELF__.event.config | json_encode | raw}}; var adrema_event_config = {{__SELF__.event.config | json_encode | raw}};
var adrema_event_meta = {{__SELF__.eventMeta | json_encode | raw}}; var adrema_event_meta = {{__SELF__.eventMeta | json_encode | raw}};
var adrema_page_meta = {{__SELF__.pageMeta | json_encode | raw}};
</script> </script>
{% endif %} {% endif %}