CachedSubscriptionImpl.php 2.5 KB

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