1
0

CalendarImpl.php 3.3 KB

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