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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * @copyright 2017, Georg Ehrke <oc.list@georgehrke.com>
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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 CalendarImpl implements ICalendar {
  28. /** @var CalDavBackend */
  29. private $backend;
  30. /** @var Calendar */
  31. private $calendar;
  32. /** @var array */
  33. private $calendarInfo;
  34. /**
  35. * CalendarImpl constructor.
  36. *
  37. * @param Calendar $calendar
  38. * @param array $calendarInfo
  39. * @param CalDavBackend $backend
  40. */
  41. public function __construct(Calendar $calendar, array $calendarInfo,
  42. CalDavBackend $backend) {
  43. $this->calendar = $calendar;
  44. $this->calendarInfo = $calendarInfo;
  45. $this->backend = $backend;
  46. }
  47. /**
  48. * @return string defining the technical unique key
  49. * @since 13.0.0
  50. */
  51. public function getKey() {
  52. return $this->calendarInfo['id'];
  53. }
  54. /**
  55. * In comparison to getKey() this function returns a human readable (maybe translated) name
  56. * @return null|string
  57. * @since 13.0.0
  58. */
  59. public function getDisplayName() {
  60. return $this->calendarInfo['{DAV:}displayname'];
  61. }
  62. /**
  63. * Calendar color
  64. * @return null|string
  65. * @since 13.0.0
  66. */
  67. public function getDisplayColor() {
  68. return $this->calendarInfo['{http://apple.com/ns/ical/}calendar-color'];
  69. }
  70. /**
  71. * @param string $pattern which should match within the $searchProperties
  72. * @param array $searchProperties defines the properties within the query pattern should match
  73. * @param array $options - optional parameters:
  74. * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]]
  75. * @param integer|null $limit - limit number of search results
  76. * @param integer|null $offset - offset for paging of search results
  77. * @return array an array of events/journals/todos which are arrays of key-value-pairs
  78. * @since 13.0.0
  79. */
  80. public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null) {
  81. return $this->backend->search($this->calendarInfo, $pattern,
  82. $searchProperties, $options, $limit, $offset);
  83. }
  84. /**
  85. * @return integer build up using \OCP\Constants
  86. * @since 13.0.0
  87. */
  88. public function getPermissions() {
  89. $permissions = $this->calendar->getACL();
  90. $result = 0;
  91. foreach ($permissions as $permission) {
  92. switch($permission['privilege']) {
  93. case '{DAV:}read':
  94. $result |= Constants::PERMISSION_READ;
  95. break;
  96. case '{DAV:}write':
  97. $result |= Constants::PERMISSION_CREATE;
  98. $result |= Constants::PERMISSION_UPDATE;
  99. break;
  100. case '{DAV:}all':
  101. $result |= Constants::PERMISSION_ALL;
  102. break;
  103. }
  104. }
  105. return $result;
  106. }
  107. }