aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/Calendar/ICalendarEventBuilder.php
blob: c99dc60cc8ca02cbc62796e0b8c7bafd04b40bd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OCP\Calendar;

use DateTimeInterface;
use InvalidArgumentException;
use OCP\Calendar\Exceptions\CalendarException;

/**
 * The calendar event builder can be used to conveniently build a calendar event and then serialize
 * it to a ICS string. The ICS string can be submitted to calendar instances implementing the
 * {@see \OCP\Calendar\ICreateFromString} interface.
 *
 * Also note this class can not be injected directly with dependency injection.
 * Instead, inject {@see \OCP\Calendar\IManager} and use
 * {@see \OCP\Calendar\IManager::createEventBuilder()} afterwards.
 *
 * All setters return self to allow chaining method calls.
 *
 * @since 31.0.0
 */
interface ICalendarEventBuilder {
	/**
	 * Set the start date, time and time zone.
	 * This property is required!
	 *
	 * @since 31.0.0
	 */
	public function setStartDate(DateTimeInterface $start): self;

	/**
	 * Set the end date, time and time zone.
	 * This property is required!
	 *
	 * @since 31.0.0
	 */
	public function setEndDate(DateTimeInterface $end): self;

	/**
	 * Set the event summary or title.
	 * This property is required!
	 *
	 * @since 31.0.0
	 */
	public function setSummary(string $summary): self;

	/**
	 * Set the event description.
	 *
	 * @since 31.0.0
	 */
	public function setDescription(string $description): self;

	/**
	 * Set the event location. It can either be a physical address or a URL.
	 *
	 * @since 31.0.0
	 */
	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!
	 *
	 * The "mailto:" prefix is optional and will be added automatically if it is missing.
	 *
	 * @since 31.0.0
	 */
	public function setOrganizer(string $email, ?string $commonName = null): self;

	/**
	 * Add a new attendee to the event.
	 * Adding at least one attendee requires also setting the organizer!
	 *
	 * The "mailto:" prefix is optional and will be added automatically if it is missing.
	 *
	 * @since 31.0.0
	 */
	public function addAttendee(string $email, ?string $commonName = null): self;

	/**
	 * Serialize the built event to an ICS string if all required properties set.
	 *
	 * @since 31.0.0
	 *
	 * @return string The serialized ICS string
	 *
	 * @throws InvalidArgumentException If required properties were not set
	 */
	public function toIcs(): string;

	/**
	 * Create the event in the given calendar.
	 *
	 * @since 31.0.0
	 *
	 * @return string The filename of the created event
	 *
	 * @throws InvalidArgumentException If required properties were not set
	 * @throws CalendarException If writing the event to the calendar fails
	 */
	public function createInCalendar(ICreateFromString $calendar): string;
}