Collection.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV\Notifications;
  4. use Sabre\CalDAV;
  5. use Sabre\DAV;
  6. use Sabre\DAVACL;
  7. /**
  8. * This node represents a list of notifications.
  9. *
  10. * It provides no additional functionality, but you must implement this
  11. * interface to allow the Notifications plugin to mark the collection
  12. * as a notifications collection.
  13. *
  14. * This collection should only return Sabre\CalDAV\Notifications\INode nodes as
  15. * its children.
  16. *
  17. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  18. * @author Evert Pot (http://evertpot.com/)
  19. * @license http://sabre.io/license/ Modified BSD License
  20. */
  21. class Collection extends DAV\Collection implements ICollection, DAVACL\IACL
  22. {
  23. use DAVACL\ACLTrait;
  24. /**
  25. * The notification backend.
  26. *
  27. * @var CalDAV\Backend\NotificationSupport
  28. */
  29. protected $caldavBackend;
  30. /**
  31. * Principal uri.
  32. *
  33. * @var string
  34. */
  35. protected $principalUri;
  36. /**
  37. * Constructor.
  38. *
  39. * @param string $principalUri
  40. */
  41. public function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri)
  42. {
  43. $this->caldavBackend = $caldavBackend;
  44. $this->principalUri = $principalUri;
  45. }
  46. /**
  47. * Returns all notifications for a principal.
  48. *
  49. * @return array
  50. */
  51. public function getChildren()
  52. {
  53. $children = [];
  54. $notifications = $this->caldavBackend->getNotificationsForPrincipal($this->principalUri);
  55. foreach ($notifications as $notification) {
  56. $children[] = new Node(
  57. $this->caldavBackend,
  58. $this->principalUri,
  59. $notification
  60. );
  61. }
  62. return $children;
  63. }
  64. /**
  65. * Returns the name of this object.
  66. *
  67. * @return string
  68. */
  69. public function getName()
  70. {
  71. return 'notifications';
  72. }
  73. /**
  74. * Returns the owner principal.
  75. *
  76. * This must be a url to a principal, or null if there's no owner
  77. *
  78. * @return string|null
  79. */
  80. public function getOwner()
  81. {
  82. return $this->principalUri;
  83. }
  84. }