CachedSubscriptionImpl.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\CalDAV;
  8. use OCP\Calendar\ICalendar;
  9. use OCP\Calendar\ICalendarIsShared;
  10. use OCP\Calendar\ICalendarIsWritable;
  11. use OCP\Constants;
  12. class CachedSubscriptionImpl implements ICalendar, ICalendarIsShared, ICalendarIsWritable {
  13. public function __construct(
  14. private CachedSubscription $calendar,
  15. /** @var array<string, mixed> */
  16. private array $calendarInfo,
  17. private CalDavBackend $backend,
  18. ) {
  19. }
  20. /**
  21. * @return string defining the technical unique key
  22. * @since 13.0.0
  23. */
  24. public function getKey(): string {
  25. return (string)$this->calendarInfo['id'];
  26. }
  27. /**
  28. * {@inheritDoc}
  29. */
  30. public function getUri(): string {
  31. return $this->calendarInfo['uri'];
  32. }
  33. /**
  34. * In comparison to getKey() this function returns a human readable (maybe translated) name
  35. * @since 13.0.0
  36. */
  37. public function getDisplayName(): ?string {
  38. return $this->calendarInfo['{DAV:}displayname'];
  39. }
  40. /**
  41. * Calendar color
  42. * @since 13.0.0
  43. */
  44. public function getDisplayColor(): ?string {
  45. return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color'];
  46. }
  47. /**
  48. * @param string $pattern which should match within the $searchProperties
  49. * @param array $searchProperties defines the properties within the query pattern should match
  50. * @param array $options - optional parameters:
  51. * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]]
  52. * @param int|null $limit - limit number of search results
  53. * @param int|null $offset - offset for paging of search results
  54. * @return array an array of events/journals/todos which are arrays of key-value-pairs
  55. * @since 13.0.0
  56. */
  57. public function search(string $pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null): array {
  58. return $this->backend->search($this->calendarInfo, $pattern, $searchProperties, $options, $limit, $offset);
  59. }
  60. /**
  61. * @return int build up using \OCP\Constants
  62. * @since 13.0.0
  63. */
  64. public function getPermissions(): int {
  65. $permissions = $this->calendar->getACL();
  66. $result = 0;
  67. foreach ($permissions as $permission) {
  68. switch ($permission['privilege']) {
  69. case '{DAV:}read':
  70. $result |= Constants::PERMISSION_READ;
  71. break;
  72. }
  73. }
  74. return $result;
  75. }
  76. public function isWritable(): bool {
  77. return false;
  78. }
  79. public function isDeleted(): bool {
  80. return false;
  81. }
  82. public function isShared(): bool {
  83. return true;
  84. }
  85. public function getSource(): string {
  86. return $this->calendarInfo['source'];
  87. }
  88. }