diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 1e0f8b0..a2541f7 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -12,14 +12,12 @@ If you'd like to have a different event timezone default than the app default (u The default collection for your events is `events`, if you use a different one, publish the config file and then update it via the CP. -For the ICS downloads, you can have a "location" field. By default Events uses a field named 'location' but if you need something different add it to the config: - -```php - 'collections' => [ - 'events' => [ - 'location_field' => 'your_location_field', - ], - ], +For the ICS downloads, it will use `address`, `coordinates`, and `description` fields if they exist. If your field is named something else, use a [Computed Value](https://statamic.dev/computed-values). `coordinates` must be a keyed array: +``` +'coordinates' => [ + 'latitude' => 40, + 'longitude' => 50, +], ``` ## Fieldset diff --git a/src/Types/Event.php b/src/Types/Event.php index cb61c3c..06a23b4 100644 --- a/src/Types/Event.php +++ b/src/Types/Event.php @@ -109,15 +109,19 @@ public function toICalendarEvent(string|CarbonInterface $date): ?ICalendarEvent ->startsAt($immutableDate->setTimeFromTimeString($this->startTime())) ->endsAt($immutableDate->setTimeFromTimeString($this->endTime())); - if (!is_null($location = $this->location($this->event))) { - $iCalEvent->address($location); + if (! is_null($address = $this->event->address ?? $this->location($this->event))) { + $iCalEvent->address($address); } - if (!is_null($description = $this->event->description)) { + if (! is_null($coords = $this->event->coordinates)) { + $iCalEvent->coordinates($coords['latitude'], $coords['longitude']); + } + + if (! is_null($description = $this->event->description)) { $iCalEvent->description($description); } - if (!is_null($link = $this->event->link)) { + if (! is_null($link = $this->event->link)) { $iCalEvent->url($link); } diff --git a/tests/Feature/IcsControllerTest.php b/tests/Feature/IcsControllerTest.php index 3e60eef..2e43ae3 100755 --- a/tests/Feature/IcsControllerTest.php +++ b/tests/Feature/IcsControllerTest.php @@ -22,9 +22,13 @@ protected function setUp(): void 'start_date' => Carbon::now()->toDateString(), 'start_time' => '11:00', 'end_time' => '12:00', + 'address' => '123 Main St', 'location' => 'The Location', + 'coordinates' => [ + 'latitude' => 40, + 'longitude' => 50, + ], 'description' => 'The description', - 'link' => 'https://transformstudios.com' ])->save(); } @@ -38,10 +42,12 @@ public function can_create_single_day_event_ics_file() 'event' => 'the-id', ]))->assertDownload('single-event.ics'); + $content = $response->streamedContent(); + $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); - $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); - $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); - $this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent()); + $this->assertStringContainsString('LOCATION:123 Main St', $content); + $this->assertStringContainsString('DESCRIPTION:The description', $content); + $this->assertStringContainsString('GEO:40;50', $content); } #[Test] @@ -61,7 +67,6 @@ public function can_create_single_day_recurring_event_ics_file() 'recurrence' => 'weekly', 'location' => 'The Location', 'description' => 'The description', - 'link' => 'https://transformstudios.com' ])->save(); $response = $this->get(route('statamic.events.ics.show', [ @@ -72,7 +77,6 @@ public function can_create_single_day_recurring_event_ics_file() $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); - $this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent()); $this->get(route('statamic.events.ics.show', [ 'date' => now()->addDay()->toDateString(), @@ -97,7 +101,6 @@ public function can_create_ics_with_single_date_recurrence() 'recurrence' => 'weekly', 'location' => 'The Location', 'description' => 'The description', - 'link' => 'https://transformstudios.com' ])->save(); $response = $this->get(route('statamic.events.ics.show', [ @@ -105,11 +108,9 @@ public function can_create_ics_with_single_date_recurrence() 'event' => 'the-recurring-id', ]))->assertDownload('recurring-event.ics'); - $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); - $this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent()); } @@ -130,7 +131,6 @@ public function can_create_ics_with_recurrence() 'recurrence' => 'weekly', 'location' => 'The Location', 'description' => 'The description', - 'link' => 'https://transformstudios.com' ])->save(); $response = $this->get(route('statamic.events.ics.show', [ @@ -140,8 +140,6 @@ public function can_create_ics_with_recurrence() $this->assertStringContainsString('DTSTART:'.now()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); - $this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent()); - } #[Test] @@ -158,7 +156,6 @@ public function can_create_single_day_multiday_event_ics_file() 'multi_day' => true, 'location' => 'The Location', 'description' => 'The description', - 'link' => 'https://transformstudios.com', 'days' => [ [ 'date' => now()->toDateString(), @@ -191,8 +188,6 @@ public function can_create_single_day_multiday_event_ics_file() $this->assertStringContainsString('DTSTART:'.now()->addDay()->setTimeFromTimeString('11:00')->format('Ymd\THis'), $response->streamedContent()); $this->assertStringContainsString('LOCATION:The Location', $response->streamedContent()); $this->assertStringContainsString('DESCRIPTION:The description', $response->streamedContent()); - $this->assertStringContainsString('URL:https://transformstudios.com', $response->streamedContent()); - } #[Test]