You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CalendarImpl.php 3.4KB

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