CalDavCalendarManager

đŸ“Ļ CalDav\Client\CalDavCalendarManager

CalDAV Calendar Manager Client Handles all calendar-related operations through the CalDAV protocol. This class provides functionality for: - Listing available calendars - Creating new calendars - Updating existing calendars - Deleting calendars - Managing calendar sharing
function __construct($baseUrl, $username, $password, $config ) { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; $this->calendarRepository = new \CalDav\Repository\CalendarRepository($config); $this->setDefaultHeaders([ 'Content-Type: application/xml; charset=utf-8', 'Depth: 0' ]); }

🔧 __construct

function __construct($baseUrl, $username, $password, $config ) { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; $this->calendarRepository = new \CalDav\Repository\CalendarRepository($config); $this->setDefaultHeaders([ 'Content-Type: application/xml; charset=utf-8', 'Depth: 0' ]); }

🔧 __construct

function __construct($baseUrl, $username, $password, $config ) { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; $this->calendarRepository = new \CalDav\Repository\CalendarRepository($config); $this->setDefaultHeaders([ 'Content-Type: application/xml; charset=utf-8', 'Depth: 0' ]); }

🔧 __construct

function __construct($baseUrl, $username, $password, $config ) { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; $this->calendarRepository = new \CalDav\Repository\CalendarRepository($config); $this->setDefaultHeaders([ 'Content-Type: application/xml; charset=utf-8', 'Depth: 0' ]); }

🔧 __construct

function __construct($baseUrl, $username, $password, $config ) { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; $this->calendarRepository = new \CalDav\Repository\CalendarRepository($config); $this->setDefaultHeaders([ 'Content-Type: application/xml; charset=utf-8', 'Depth: 0' ]); }

🔧 __construct

Constructor Initializes the calendar manager with server credentials
function __construct($baseUrl, $username, $password, $config ) { $this->baseUrl = rtrim($baseUrl, '/'); $this->username = $username; $this->password = $password; $this->calendarRepository = new \CalDav\Repository\CalendarRepository($config); $this->setDefaultHeaders([ 'Content-Type: application/xml; charset=utf-8', 'Depth: 0' ]); }

âš™ī¸ Parameters


🔧 listCalendars

List all calendars for a user Retrieves all calendars accessible to the specified user using PROPFIND request. The response includes calendar properties such as display name, description, and color.
function listCalendars($username): array { try { $calendarHomeUrl = "{$this->baseUrl}"; $this->initCurl($calendarHomeUrl, 'PROPFIND', ['Depth: 1']); // Build XML request for calendar properties $xmlRequest = $this->buildPropfindXml([ '{DAV:}displayname', '{DAV:}resourcetype', '{urn:ietf:params:xml:ns:caldav}calendar-description', '{http://apple.com/ns/ical/}calendar-color', '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array) Array of calendar information

âš ī¸ Throws


🔧 buildPropfindXml

Build PROPFIND XML request Creates an XML request for the PROPFIND method to retrieve calendar properties
function buildPropfindXml(array $properties): string { $xml = '<?xml version="1.0" encoding="utf-8" ?>'; $xml .= '<D:propfind xmlns:D="DAV:">'; $xml .= '<D:prop>'; foreach ($properties as $property) { $parts = explode('}', $property); $namespace = trim($parts[0], '{'); $name = $parts[1]; if ($namespace === 'DAV:') { $xml .= "<D:$name />"; // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(string) Formatted XML request

🔧 createCalendar

Create a new calendar Creates a new calendar for the specified user with the given properties
function createCalendar($username, array $calendarData): array { try { // Add default values for synctoken and components $calendarData['synctoken'] = 1; // Default synctoken for new calendars $calendarData['components'] = 'VEVENT'; // Default components support $calendar = Calendar::fromArray($calendarData, $username); // Save to database only try { $success = $this->calendarRepository->save($calendar); if ($success) { return ['success' => true, 'message' => 'Calendar created successfully', 'calendar' => $calendar->toArray()]; } return ['success' => false, 'message' => 'Failed to save calendar to database']; // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array) Result of the operation

🔧 setDirectoryAcl

Set ACL permissions on a directory
function setDirectoryAcl($username, $url): array { try { // Build ACL XML with full permissions including bind privilege $xml = '<?xml version="1.0" encoding="utf-8" ?>'; $xml .= '<acl xmlns="DAV:">'; // Owner privileges $xml .= '<ace>'; $xml .= '<principal><href>/principals/' . $username . '</href></principal>'; $xml .= '<grant>'; $xml .= '<privilege><read/></privilege>'; $xml .= '<privilege><write/></privilege>'; $xml .= '<privilege><bind/></privilege>'; // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array) Result of the operation

🔧 checkAclSupport

Check if ACL support is enabled on the server
function checkAclSupport(): array { try { $this->initCurl($this->baseUrl, 'OPTIONS'); $result = $this->executeRequest(); if ($result['httpCode'] !== 200) { return [ 'success' => false, 'enabled' => false, 'message' => 'Failed to check ACL support. Server returned: ' . $result['httpCode'] ]; // ... (truncated)

â†Šī¸ Returns

(array) ['success' => bool, 'message' => string, 'enabled' => bool]

🔧 directUpdateCalendarColor

Update calendar color directly via PROPPATCH Uses a direct PROPPATCH request to update the calendar color. This is a more reliable approach when standard methods fail.
function directUpdateCalendarColor(string $caldav_url, string $color, ?string $override_username = null, ?string $override_password = null): array { try { // Ensure URL ends with slash $caldav_url = rtrim($caldav_url, '/') . '/'; // Use provided credentials or fall back to instance credentials $username = $override_username ?? $this->username; $password = $override_password ?? $this->password; // Build XML for PROPPATCH request $xml = '<?xml version="1.0" encoding="utf-8" ?>'; $xml .= '<propertyupdate xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">'; $xml .= '<set><prop>'; $xml .= '<apple:calendar-color xmlns:apple="http://apple.com/ns/ical/">' . htmlspecialchars($color) . '</apple:calendar-color>'; // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(array) Result of the operation with 'success' and 'message' keys