Application.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Georg Ehrke <georg@owncloud.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  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, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\DAV\AppInfo;
  26. use OCA\DAV\CalDAV\BirthdayService;
  27. use OCA\DAV\CardDAV\ContactsManager;
  28. use OCA\DAV\CardDAV\SyncService;
  29. use OCA\DAV\HookManager;
  30. use \OCP\AppFramework\App;
  31. use OCP\Contacts\IManager;
  32. use Symfony\Component\EventDispatcher\GenericEvent;
  33. class Application extends App {
  34. /**
  35. * Application constructor.
  36. */
  37. public function __construct() {
  38. parent::__construct('dav');
  39. }
  40. /**
  41. * @param IManager $contactsManager
  42. * @param string $userID
  43. */
  44. public function setupContactsProvider(IManager $contactsManager, $userID) {
  45. /** @var ContactsManager $cm */
  46. $cm = $this->getContainer()->query(ContactsManager::class);
  47. $urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
  48. $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
  49. }
  50. public function registerHooks() {
  51. /** @var HookManager $hm */
  52. $hm = $this->getContainer()->query(HookManager::class);
  53. $hm->setup();
  54. $listener = function($event) {
  55. if ($event instanceof GenericEvent) {
  56. /** @var BirthdayService $b */
  57. $b = $this->getContainer()->query(BirthdayService::class);
  58. $b->onCardChanged(
  59. $event->getArgument('addressBookId'),
  60. $event->getArgument('cardUri'),
  61. $event->getArgument('cardData')
  62. );
  63. }
  64. };
  65. $dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
  66. $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener);
  67. $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener);
  68. $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) {
  69. if ($event instanceof GenericEvent) {
  70. /** @var BirthdayService $b */
  71. $b = $this->getContainer()->query(BirthdayService::class);
  72. $b->onCardDeleted(
  73. $event->getArgument('addressBookId'),
  74. $event->getArgument('cardUri')
  75. );
  76. }
  77. });
  78. }
  79. public function getSyncService() {
  80. return $this->getContainer()->query(SyncService::class);
  81. }
  82. }