1
0

CalendarManager.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\Calendar\IManager;
  25. use OCP\IConfig;
  26. use OCP\IL10N;
  27. class CalendarManager {
  28. /** @var CalDavBackend */
  29. private $backend;
  30. /** @var IL10N */
  31. private $l10n;
  32. /** @var IConfig */
  33. private $config;
  34. /**
  35. * CalendarManager constructor.
  36. *
  37. * @param CalDavBackend $backend
  38. * @param IL10N $l10n
  39. * @param IConfig $config
  40. */
  41. public function __construct(CalDavBackend $backend, IL10N $l10n, IConfig $config) {
  42. $this->backend = $backend;
  43. $this->l10n = $l10n;
  44. $this->config = $config;
  45. }
  46. /**
  47. * @param IManager $cm
  48. * @param string $userId
  49. */
  50. public function setupCalendarProvider(IManager $cm, $userId) {
  51. $calendars = $this->backend->getCalendarsForUser("principals/users/$userId");
  52. $this->register($cm, $calendars);
  53. }
  54. /**
  55. * @param IManager $cm
  56. * @param array $calendars
  57. */
  58. private function register(IManager $cm, array $calendars) {
  59. foreach($calendars as $calendarInfo) {
  60. $calendar = new Calendar($this->backend, $calendarInfo, $this->l10n, $this->config);
  61. $cm->registerCalendar(new CalendarImpl(
  62. $calendar,
  63. $calendarInfo,
  64. $this->backend
  65. ));
  66. }
  67. }
  68. }