CachedSubscriptionImpl.php 2.4 KB

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