CachedSubscriptionImpl.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2024 Daniel Kesselberg <mail@danielkesselberg.de>
  5. *
  6. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\CalDAV;
  25. use OCP\Calendar\ICalendar;
  26. use OCP\Constants;
  27. class CachedSubscriptionImpl implements ICalendar {
  28. private CalDavBackend $backend;
  29. private CachedSubscription $calendar;
  30. /** @var array<string, mixed> */
  31. private array $calendarInfo;
  32. public function __construct(
  33. CachedSubscription $calendar,
  34. array $calendarInfo,
  35. CalDavBackend $backend
  36. ) {
  37. $this->calendar = $calendar;
  38. $this->calendarInfo = $calendarInfo;
  39. $this->backend = $backend;
  40. }
  41. /**
  42. * @return string defining the technical unique key
  43. * @since 13.0.0
  44. */
  45. public function getKey(): string {
  46. return (string) $this->calendarInfo['id'];
  47. }
  48. /**
  49. * {@inheritDoc}
  50. */
  51. public function getUri(): string {
  52. return $this->calendarInfo['uri'];
  53. }
  54. /**
  55. * In comparison to getKey() this function returns a human readable (maybe translated) name
  56. * @since 13.0.0
  57. */
  58. public function getDisplayName(): ?string {
  59. return $this->calendarInfo['{DAV:}displayname'];
  60. }
  61. /**
  62. * Calendar color
  63. * @since 13.0.0
  64. */
  65. public function getDisplayColor(): ?string {
  66. return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color'];
  67. }
  68. /**
  69. * @param string $pattern which should match within the $searchProperties
  70. * @param array $searchProperties defines the properties within the query pattern should match
  71. * @param array $options - optional parameters:
  72. * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]]
  73. * @param int|null $limit - limit number of search results
  74. * @param int|null $offset - offset for paging of search results
  75. * @return array an array of events/journals/todos which are arrays of key-value-pairs
  76. * @since 13.0.0
  77. */
  78. public function search(string $pattern, array $searchProperties = [], array $options = [], $limit = null, $offset = null): array {
  79. return $this->backend->search($this->calendarInfo, $pattern, $searchProperties, $options, $limit, $offset);
  80. }
  81. /**
  82. * @return int build up using \OCP\Constants
  83. * @since 13.0.0
  84. */
  85. public function getPermissions(): int {
  86. $permissions = $this->calendar->getACL();
  87. $result = 0;
  88. foreach ($permissions as $permission) {
  89. switch ($permission['privilege']) {
  90. case '{DAV:}read':
  91. $result |= Constants::PERMISSION_READ;
  92. break;
  93. }
  94. }
  95. return $result;
  96. }
  97. public function isDeleted(): bool {
  98. return false;
  99. }
  100. public function getSource(): string {
  101. return $this->calendarInfo['source'];
  102. }
  103. }