1<?php
2
3declare(strict_types=1);
4
5namespace Sabre\CalDAV\Notifications;
6
7use Sabre\CalDAV;
8use Sabre\CalDAV\Xml\Notification\NotificationInterface;
9use Sabre\DAV;
10use Sabre\DAVACL;
11
12/**
13 * This node represents a single notification.
14 *
15 * The signature is mostly identical to that of Sabre\DAV\IFile, but the get() method
16 * MUST return an xml document that matches the requirements of the
17 * 'caldav-notifications.txt' spec.
18 *
19 * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
20 * @author Evert Pot (http://evertpot.com/)
21 * @license http://sabre.io/license/ Modified BSD License
22 */
23class Node extends DAV\File implements INode, DAVACL\IACL
24{
25    use DAVACL\ACLTrait;
26
27    /**
28     * The notification backend.
29     *
30     * @var CalDAV\Backend\NotificationSupport
31     */
32    protected $caldavBackend;
33
34    /**
35     * The actual notification.
36     *
37     * @var NotificationInterface
38     */
39    protected $notification;
40
41    /**
42     * Owner principal of the notification.
43     *
44     * @var string
45     */
46    protected $principalUri;
47
48    /**
49     * Constructor.
50     *
51     * @param string $principalUri
52     */
53    public function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri, NotificationInterface $notification)
54    {
55        $this->caldavBackend = $caldavBackend;
56        $this->principalUri = $principalUri;
57        $this->notification = $notification;
58    }
59
60    /**
61     * Returns the path name for this notification.
62     *
63     * @return string
64     */
65    public function getName()
66    {
67        return $this->notification->getId().'.xml';
68    }
69
70    /**
71     * Returns the etag for the notification.
72     *
73     * The etag must be surrounded by litteral double-quotes.
74     *
75     * @return string
76     */
77    public function getETag()
78    {
79        return $this->notification->getETag();
80    }
81
82    /**
83     * This method must return an xml element, using the
84     * Sabre\CalDAV\Xml\Notification\NotificationInterface classes.
85     *
86     * @return NotificationInterface
87     */
88    public function getNotificationType()
89    {
90        return $this->notification;
91    }
92
93    /**
94     * Deletes this notification.
95     */
96    public function delete()
97    {
98        $this->caldavBackend->deleteNotification($this->getOwner(), $this->notification);
99    }
100
101    /**
102     * Returns the owner principal.
103     *
104     * This must be a url to a principal, or null if there's no owner
105     *
106     * @return string|null
107     */
108    public function getOwner()
109    {
110        return $this->principalUri;
111    }
112}
113