Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/Types/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
25 changes: 10 additions & 15 deletions tests/Feature/IcsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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]
Expand All @@ -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', [
Expand All @@ -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(),
Expand All @@ -97,19 +101,16 @@ 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', [
'date' => now()->toDateString(),
'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());

}

Expand All @@ -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', [
Expand All @@ -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]
Expand All @@ -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(),
Expand Down Expand Up @@ -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]
Expand Down