Skip to content

Commit bbb69f1

Browse files
fix: add event status and participant status
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
1 parent 196b2f1 commit bbb69f1

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

lib/private/Calendar/CalendarEventBuilder.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use DateTimeInterface;
1313
use InvalidArgumentException;
1414
use OCP\AppFramework\Utility\ITimeFactory;
15+
use OCP\Calendar\CalendarEventStatus;
1516
use OCP\Calendar\ICalendarEventBuilder;
1617
use OCP\Calendar\ICreateFromString;
1718
use Sabre\VObject\Component\VCalendar;
@@ -23,6 +24,7 @@ class CalendarEventBuilder implements ICalendarEventBuilder {
2324
private ?string $summary = null;
2425
private ?string $description = null;
2526
private ?string $location = null;
27+
private ?CalendarEventStatus $status = null;
2628
private ?array $organizer = null;
2729
private array $attendees = [];
2830

@@ -57,6 +59,11 @@ public function setLocation(string $location): ICalendarEventBuilder {
5759
return $this;
5860
}
5961

62+
public function setStatus(CalendarEventStatus $status): static {
63+
$this->status = $status;
64+
return $this;
65+
}
66+
6067
public function setOrganizer(string $email, ?string $commonName = null): ICalendarEventBuilder {
6168
$this->organizer = [$email, $commonName];
6269
return $this;
@@ -91,6 +98,7 @@ public function toIcs(): string {
9198
'SUMMARY' => $this->summary,
9299
'DTSTART' => $this->startDate,
93100
'DTEND' => $this->endDate,
101+
'STATUS' => $this->status->value,
94102
];
95103
if ($this->description !== null) {
96104
$props['DESCRIPTION'] = $this->description;
@@ -126,6 +134,13 @@ private static function addAttendeeToVEvent(VEvent $vevent, string $name, array
126134
$params = [];
127135
if ($cn !== null) {
128136
$params['CN'] = $cn;
137+
if ($name === 'ORGANIZER') {
138+
$params['ROLE'] = 'CHAIR';
139+
$params['PARTSTAT'] = 'ACCEPTED';
140+
} else {
141+
$params['ROLE'] = 'REQ-PARTICIPANT';
142+
$params['PARTSTAT'] = 'NEEDS-ACTION';
143+
}
129144
}
130145
$vevent->add($name, $email, $params);
131146
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
namespace OCP\Calendar;
9+
10+
/**
11+
* The status of a calendar event.
12+
*
13+
* @since 32.0.0
14+
*/
15+
enum CalendarEventStatus: string {
16+
case TENTATIVE = 'TENTATIVE';
17+
case CONFIRMED = 'CONFIRMED';
18+
case CANCELLED = 'CANCELLED';
19+
};

lib/public/Calendar/ICalendarEventBuilder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public function setDescription(string $description): self;
6565
*/
6666
public function setLocation(string $location): self;
6767

68+
/**
69+
* Set the event status.
70+
*
71+
* @since 32.0.0
72+
*/
73+
public function setStatus(CalendarEventStatus $status): static;
74+
6875
/**
6976
* Set the event organizer.
7077
* This property is required if attendees are added!

tests/data/ics/event-builder-complete.ics

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ DTSTAMP:20250105T000000Z
88
SUMMARY:My event
99
DTSTART:20250105T170958Z
1010
DTEND:20250105T171958Z
11+
STATUS:CONFIRMED
1112
DESCRIPTION:Foo bar baz
1213
ORGANIZER:mailto:organizer@domain.tld
1314
ATTENDEE:mailto:attendee1@domain.tld

tests/data/ics/event-builder-without-attendees.ics

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ DTSTAMP:20250105T000000Z
88
SUMMARY:My event
99
DTSTART:20250105T170958Z
1010
DTEND:20250105T171958Z
11+
STATUS:CONFIRMED
1112
DESCRIPTION:Foo bar baz
1213
END:VEVENT
1314
END:VCALENDAR

tests/lib/Calendar/CalendarEventBuilderTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use InvalidArgumentException;
1414
use OC\Calendar\CalendarEventBuilder;
1515
use OCP\AppFramework\Utility\ITimeFactory;
16+
use OCP\Calendar\CalendarEventStatus;
1617
use OCP\Calendar\ICreateFromString;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use Test\TestCase;
@@ -37,6 +38,7 @@ protected function setUp(): void {
3738
public function testToIcs(): void {
3839
$this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
3940
$this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
41+
$this->calendarEventBuilder->setStatus(CalendarEventStatus::CONFIRMED);
4042
$this->calendarEventBuilder->setSummary('My event');
4143
$this->calendarEventBuilder->setDescription('Foo bar baz');
4244
$this->calendarEventBuilder->setOrganizer('mailto:organizer@domain.tld');
@@ -51,6 +53,7 @@ public function testToIcs(): void {
5153
public function testToIcsWithoutOrganizerAndAttendees(): void {
5254
$this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
5355
$this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
56+
$this->calendarEventBuilder->setStatus(CalendarEventStatus::CONFIRMED);
5457
$this->calendarEventBuilder->setSummary('My event');
5558
$this->calendarEventBuilder->setDescription('Foo bar baz');
5659

@@ -62,6 +65,7 @@ public function testToIcsWithoutOrganizerAndAttendees(): void {
6265
public function testToIcsWithoutMailtoPrefix(): void {
6366
$this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
6467
$this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
68+
$this->calendarEventBuilder->setStatus(CalendarEventStatus::CONFIRMED);
6569
$this->calendarEventBuilder->setSummary('My event');
6670
$this->calendarEventBuilder->setDescription('Foo bar baz');
6771
$this->calendarEventBuilder->setOrganizer('organizer@domain.tld');
@@ -76,6 +80,7 @@ public function testToIcsWithoutMailtoPrefix(): void {
7680
public function testCreateInCalendar(): void {
7781
$this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
7882
$this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
83+
$this->calendarEventBuilder->setStatus(CalendarEventStatus::CONFIRMED);
7984
$this->calendarEventBuilder->setSummary('My event');
8085
$this->calendarEventBuilder->setDescription('Foo bar baz');
8186
$this->calendarEventBuilder->setOrganizer('organizer@domain.tld');

0 commit comments

Comments
 (0)