CalendarManager.php 2.2 KB

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