CalDavEventManager

đŸ“Ļ CalDav\Client\CalDavEventManager

CalDAV Event Manager Handles all event-related operations through the CalDAV protocol including: - Creating new events - Updating existing events - Deleting events - Listing events from calendars - Moving events between calendars
function __construct($baseUrl, $username, $password, $authMethod = 'digest') { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; // Set authentication method if ($authMethod === 'digest') { $this->authMethod = CURLAUTH_DIGEST; } else if ($authMethod === 'basic') { $this->authMethod = CURLAUTH_BASIC; } else { $this->authMethod = CURLAUTH_ANY; // ... (truncated)

🔧 __construct

function __construct($baseUrl, $username, $password, $authMethod = 'digest') { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; // Set authentication method if ($authMethod === 'digest') { $this->authMethod = CURLAUTH_DIGEST; } else if ($authMethod === 'basic') { $this->authMethod = CURLAUTH_BASIC; } else { $this->authMethod = CURLAUTH_ANY; // ... (truncated)

🔧 __construct

function __construct($baseUrl, $username, $password, $authMethod = 'digest') { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; // Set authentication method if ($authMethod === 'digest') { $this->authMethod = CURLAUTH_DIGEST; } else if ($authMethod === 'basic') { $this->authMethod = CURLAUTH_BASIC; } else { $this->authMethod = CURLAUTH_ANY; // ... (truncated)

🔧 __construct

function __construct($baseUrl, $username, $password, $authMethod = 'digest') { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; // Set authentication method if ($authMethod === 'digest') { $this->authMethod = CURLAUTH_DIGEST; } else if ($authMethod === 'basic') { $this->authMethod = CURLAUTH_BASIC; } else { $this->authMethod = CURLAUTH_ANY; // ... (truncated)

🔧 __construct

function __construct($baseUrl, $username, $password, $authMethod = 'digest') { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; // Set authentication method if ($authMethod === 'digest') { $this->authMethod = CURLAUTH_DIGEST; } else if ($authMethod === 'basic') { $this->authMethod = CURLAUTH_BASIC; } else { $this->authMethod = CURLAUTH_ANY; // ... (truncated)

🔧 __construct

function __construct($baseUrl, $username, $password, $authMethod = 'digest') { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; // Set authentication method if ($authMethod === 'digest') { $this->authMethod = CURLAUTH_DIGEST; } else if ($authMethod === 'basic') { $this->authMethod = CURLAUTH_BASIC; } else { $this->authMethod = CURLAUTH_ANY; // ... (truncated)

🔧 __construct

Constructor
function __construct($baseUrl, $username, $password, $authMethod = 'digest') { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; // Set authentication method if ($authMethod === 'digest') { $this->authMethod = CURLAUTH_DIGEST; } else if ($authMethod === 'basic') { $this->authMethod = CURLAUTH_BASIC; } else { $this->authMethod = CURLAUTH_ANY; // ... (truncated)

âš™ī¸ Parameters


🔧 setError

Set error information
function setError(string $message, $code = null, \Exception $exception = null): void { $this->lastError = [ 'message' => $message, 'code' => $code, 'exception' => $exception ? $exception->getMessage() : null ]; }

âš™ī¸ Parameters


🔧 listEvents

List all events from a calendar
function listEvents(string $username, string $calendarId): array { $debug = []; try { // Build the calendar URL $calendarUrl = "{$this->baseUrl}/calendars/{$username}

âš™ī¸ Parameters

â†Šī¸ Returns

(array) Array of events

🔧 getEvent

Get a specific event by ID
function getEvent($eventUrl): ?array { try { // Initialize curl $this->ch = curl_init(); curl_setopt_array($this->ch, [ CURLOPT_URL => $eventUrl, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPGET => true, CURLOPT_USERPWD => $this->username . ':' . $this->password, CURLOPT_HTTPAUTH => $this->authMethod ?? CURLAUTH_DIGEST, CURLOPT_SSL_VERIFYPEER => false, // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array|null) Event data or null if not found

🔧 parseICalData

Parse iCal data into event array
function parseICalData(string $icalData): ?array { try { $icalData = preg_replace("/\r\n[ \t]/", " ", $icalData); $lines = explode("\n", $icalData); $event = []; $inEvent = false; foreach ($lines as $line) { $line = trim($line); if (strcasecmp($line, 'BEGIN:VEVENT') === 0) { $inEvent = true; // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array|null) Parsed event data or null if parsing fails

🔧 parseICalDate

Parse iCal date format to ISO 8601
function parseICalDate(string $line): string { try { preg_match('/(\d{8}T\d{6}Z?)/', $line, $matches); if (!empty($matches[1])) { $date = $matches[1]; return substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6, 2) . 'T' . substr($date, 9, 2) . ':' . substr($date, 11, 2) . ':' . // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(string) Formatted date string

🔧 createEvent

Create a new event in a calendar $result = $calDavEventManager->createEvent($username, $calendarUrl, $eventData, null, true); if ($result['success']) { Download the ICS file header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $result['filename'] . '"'); echo $result['ics_content']; exit; }
function createEvent(string $username, string $calendarUrl, array $eventData, ?string $password = null, bool $download = false): array { $debug = []; try { // Use provided password or fall back to instance password $password = $password ?? $this->password; // First verify the calendar exists $this->ch = curl_init(); curl_setopt_array($this->ch, [ CURLOPT_URL => $calendarUrl, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => 'PROPFIND', CURLOPT_USERPWD => $username . ':' . $password, // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array) Result of the operation

🔧 sanitizeFilename

Sanitize a string to be used as a filename
function sanitizeFilename(string $filename): string { // Remove any character that isn't a letter, digit, space, underscore or hyphen $filename = preg_replace('/[^\w\s\-\.]/u', '', $filename); // Replace spaces with underscores $filename = str_replace(' ', '_', $filename); // Limit length if (strlen($filename) > 50) { $filename = substr($filename, 0, 47) . '...'; } return $filename ?: 'event'; }

âš™ī¸ Parameters

â†Šī¸ Returns

(string) Sanitized filename

🔧 escapeICalText

Escape special characters in iCal text and fold long lines
function escapeICalText(string $text): string { return addcslashes($text, ',;\\'); }

âš™ī¸ Parameters

â†Šī¸ Returns

(string) Escaped and folded text

🔧 updateEvent

Update an existing event
function updateEvent(string $username, string $calendarId, string $eventId, array $eventData, ?string $password = null): array { $debug = [ 'process_steps' => [], 'event_data' => $eventData, 'calendar_id' => $calendarId ]; try { // Use provided password or fall back to instance password $password = $password ?? $this->password; // Clean up the old event ID $oldEventId = trim($eventId); $oldEventId = str_replace('.ics', '', $oldEventId); // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array) Response array with success status and message

🔧 deleteEvent

Delete an event from the calendar
function deleteEvent(string $username, string $calendarId, string $eventId, ?string $password = null): array { $debug = [ 'process_steps' => [], 'original_event_id' => $eventId, 'calendar_id' => $calendarId ]; try { // Use provided password or fall back to instance password $password = $password ?? $this->password; // Clean up the event ID - remove any .ics extension and ensure proper format $eventId = trim($eventId); $eventId = str_replace('.ics', '', $eventId); // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array) Response array with success status and message

🔧 moveEvent

Move an event from one calendar to another
function moveEvent(string $username, string $sourceCalendarId, string $targetCalendarId, string $eventId, array $eventData, ?string $sourcePassword = null, ?string $targetPassword = null, ?string $targetUsername = null): array { $debug = []; try { // Use provided passwords or fall back to instance password $sourcePassword = $sourcePassword ?? $this->password; $targetPassword = $targetPassword ?? $this->password; $targetUsername = $targetUsername ?? $username; // Create the event in the target calendar $createResult = $this->createEvent($targetUsername, $targetCalendarId, $eventData, $targetPassword); $debug['create_result'] = $createResult; if (!$createResult['success']) { return [ // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array) Response array with success status and message