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
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
'OCP\\Broadcast\\Events\\IBroadcastEvent' => $baseDir . '/lib/public/Broadcast/Events/IBroadcastEvent.php',
'OCP\\Cache\\CappedMemoryCache' => $baseDir . '/lib/public/Cache/CappedMemoryCache.php',
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => $baseDir . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
'OCP\\Calendar\\CalendarEventStatus' => $baseDir . '/lib/public/Calendar/CalendarEventStatus.php',
'OCP\\Calendar\\Exceptions\\CalendarException' => $baseDir . '/lib/public/Calendar/Exceptions/CalendarException.php',
'OCP\\Calendar\\IAvailabilityResult' => $baseDir . '/lib/public/Calendar/IAvailabilityResult.php',
'OCP\\Calendar\\ICalendar' => $baseDir . '/lib/public/Calendar/ICalendar.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Broadcast\\Events\\IBroadcastEvent' => __DIR__ . '/../../..' . '/lib/public/Broadcast/Events/IBroadcastEvent.php',
'OCP\\Cache\\CappedMemoryCache' => __DIR__ . '/../../..' . '/lib/public/Cache/CappedMemoryCache.php',
'OCP\\Calendar\\BackendTemporarilyUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Calendar/BackendTemporarilyUnavailableException.php',
'OCP\\Calendar\\CalendarEventStatus' => __DIR__ . '/../../..' . '/lib/public/Calendar/CalendarEventStatus.php',
'OCP\\Calendar\\Exceptions\\CalendarException' => __DIR__ . '/../../..' . '/lib/public/Calendar/Exceptions/CalendarException.php',
'OCP\\Calendar\\IAvailabilityResult' => __DIR__ . '/../../..' . '/lib/public/Calendar/IAvailabilityResult.php',
'OCP\\Calendar\\ICalendar' => __DIR__ . '/../../..' . '/lib/public/Calendar/ICalendar.php',
Expand Down
15 changes: 15 additions & 0 deletions lib/private/Calendar/CalendarEventBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use DateTimeInterface;
use InvalidArgumentException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Calendar\CalendarEventStatus;
use OCP\Calendar\ICalendarEventBuilder;
use OCP\Calendar\ICreateFromString;
use Sabre\VObject\Component\VCalendar;
Expand All @@ -23,6 +24,7 @@ class CalendarEventBuilder implements ICalendarEventBuilder {
private ?string $summary = null;
private ?string $description = null;
private ?string $location = null;
private ?CalendarEventStatus $status = null;
private ?array $organizer = null;
private array $attendees = [];

Expand Down Expand Up @@ -57,6 +59,11 @@ public function setLocation(string $location): ICalendarEventBuilder {
return $this;
}

public function setStatus(CalendarEventStatus $status): static {
$this->status = $status;
return $this;
}

public function setOrganizer(string $email, ?string $commonName = null): ICalendarEventBuilder {
$this->organizer = [$email, $commonName];
return $this;
Expand Down Expand Up @@ -91,6 +98,7 @@ public function toIcs(): string {
'SUMMARY' => $this->summary,
'DTSTART' => $this->startDate,
'DTEND' => $this->endDate,
'STATUS' => $this->status->value,
];
if ($this->description !== null) {
$props['DESCRIPTION'] = $this->description;
Expand Down Expand Up @@ -126,6 +134,13 @@ private static function addAttendeeToVEvent(VEvent $vevent, string $name, array
$params = [];
if ($cn !== null) {
$params['CN'] = $cn;
if ($name === 'ORGANIZER') {
$params['ROLE'] = 'CHAIR';
$params['PARTSTAT'] = 'ACCEPTED';
} else {
$params['ROLE'] = 'REQ-PARTICIPANT';
$params['PARTSTAT'] = 'NEEDS-ACTION';
}
}
$vevent->add($name, $email, $params);
}
Expand Down
19 changes: 19 additions & 0 deletions lib/public/Calendar/CalendarEventStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Calendar;

/**
* The status of a calendar event.
*
* @since 32.0.0
*/
enum CalendarEventStatus: string {
case TENTATIVE = 'TENTATIVE';
case CONFIRMED = 'CONFIRMED';
case CANCELLED = 'CANCELLED';
};
7 changes: 7 additions & 0 deletions lib/public/Calendar/ICalendarEventBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public function setDescription(string $description): self;
*/
public function setLocation(string $location): self;

/**
* Set the event status.
*
* @since 32.0.0
*/
public function setStatus(CalendarEventStatus $status): static;

/**
* Set the event organizer.
* This property is required if attendees are added!
Expand Down
1 change: 1 addition & 0 deletions tests/data/ics/event-builder-complete.ics
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DTSTAMP:20250105T000000Z
SUMMARY:My event
DTSTART:20250105T170958Z
DTEND:20250105T171958Z
STATUS:CONFIRMED
DESCRIPTION:Foo bar baz
ORGANIZER:mailto:organizer@domain.tld
ATTENDEE:mailto:attendee1@domain.tld
Expand Down
1 change: 1 addition & 0 deletions tests/data/ics/event-builder-without-attendees.ics
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ DTSTAMP:20250105T000000Z
SUMMARY:My event
DTSTART:20250105T170958Z
DTEND:20250105T171958Z
STATUS:CONFIRMED
DESCRIPTION:Foo bar baz
END:VEVENT
END:VCALENDAR
5 changes: 5 additions & 0 deletions tests/lib/Calendar/CalendarEventBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use InvalidArgumentException;
use OC\Calendar\CalendarEventBuilder;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Calendar\CalendarEventStatus;
use OCP\Calendar\ICreateFromString;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
Expand All @@ -37,6 +38,7 @@ protected function setUp(): void {
public function testToIcs(): void {
$this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
$this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
$this->calendarEventBuilder->setStatus(CalendarEventStatus::CONFIRMED);
$this->calendarEventBuilder->setSummary('My event');
$this->calendarEventBuilder->setDescription('Foo bar baz');
$this->calendarEventBuilder->setOrganizer('mailto:organizer@domain.tld');
Expand All @@ -51,6 +53,7 @@ public function testToIcs(): void {
public function testToIcsWithoutOrganizerAndAttendees(): void {
$this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
$this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
$this->calendarEventBuilder->setStatus(CalendarEventStatus::CONFIRMED);
$this->calendarEventBuilder->setSummary('My event');
$this->calendarEventBuilder->setDescription('Foo bar baz');

Expand All @@ -62,6 +65,7 @@ public function testToIcsWithoutOrganizerAndAttendees(): void {
public function testToIcsWithoutMailtoPrefix(): void {
$this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
$this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
$this->calendarEventBuilder->setStatus(CalendarEventStatus::CONFIRMED);
$this->calendarEventBuilder->setSummary('My event');
$this->calendarEventBuilder->setDescription('Foo bar baz');
$this->calendarEventBuilder->setOrganizer('organizer@domain.tld');
Expand All @@ -76,6 +80,7 @@ public function testToIcsWithoutMailtoPrefix(): void {
public function testCreateInCalendar(): void {
$this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2025-01-05T17:09:58Z'));
$this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
$this->calendarEventBuilder->setStatus(CalendarEventStatus::CONFIRMED);
$this->calendarEventBuilder->setSummary('My event');
$this->calendarEventBuilder->setDescription('Foo bar baz');
$this->calendarEventBuilder->setOrganizer('organizer@domain.tld');
Expand Down
Loading