| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\Package\CalDav\Clients; |
| 4 |
|
| 5 |
use Exception; |
| 6 |
use FluentBooking\Package\CalDav\ICal\XmlParser; |
| 7 |
use FluentBooking\Package\CalDav\Entities\Calendar; |
| 8 |
|
| 9 |
class NextCloud extends Client |
| 10 |
{ |
| 11 |
public function getCalendars() |
| 12 |
{ |
| 13 |
$url = $this->makeUrl("calendars/{$this->username}"); |
| 14 |
|
| 15 |
return parent::getCalendarsInfo($url); |
| 16 |
} |
| 17 |
|
| 18 |
public function getCalendar($calendarName) |
| 19 |
{ |
| 20 |
$url = $this->buildUrlFrom($calendarName); |
| 21 |
|
| 22 |
return parent::getCalendarInfo($url); |
| 23 |
} |
| 24 |
|
| 25 |
public function getEvents($calendarName, $dateRange = []) |
| 26 |
{ |
| 27 |
$url = $this->buildUrlFrom($calendarName); |
| 28 |
|
| 29 |
return parent::getEventsFrom($url, $dateRange); |
| 30 |
} |
| 31 |
|
| 32 |
public function getEvent($uid) |
| 33 |
{ |
| 34 |
$url = $this->buildUrlFrom($uid); |
| 35 |
|
| 36 |
return parent::getEventFrom($url); |
| 37 |
} |
| 38 |
|
| 39 |
public function addEvent($calendarName, $payload) |
| 40 |
{ |
| 41 |
$url = $this->buildUrlFrom($calendarName); |
| 42 |
|
| 43 |
return parent::addEventTo($url, $payload); |
| 44 |
} |
| 45 |
|
| 46 |
public function deleteEvent($url) |
| 47 |
{ |
| 48 |
$url = $this->buildUrlFrom($url); |
| 49 |
|
| 50 |
return parent::deleteEvent($url); |
| 51 |
} |
| 52 |
|
| 53 |
protected function getAuthCredential() |
| 54 |
{ |
| 55 |
return 'Basic ' . base64_encode( |
| 56 |
$this->username . ':' . $this->password |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
protected function buildUrlFrom($calendarName) |
| 61 |
{ |
| 62 |
if (str_contains($calendarName, 'remote.php/dav/calendars')) { |
| 63 |
$calendarName = str_replace('remote.php/dav/', '', $calendarName); |
| 64 |
$url = $this->makeUrl($calendarName); |
| 65 |
} else { |
| 66 |
$url = $this->makeUrl( |
| 67 |
"calendars/{$this->username}/{$calendarName}" |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
return $url; |
| 72 |
} |
| 73 |
} |
| 74 |
|