1<?php
2
3namespace Sabre\CalDAV\Principal;
4
5use Sabre\DAVACL;
6use Sabre\DAV;
7
8/**
9 * ProxyWrite principal
10 *
11 * This class represents a principal group, hosted under the main principal.
12 * This is needed to implement 'Calendar delegation' support. This class is
13 * instantiated by User.
14 *
15 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
16 * @author Evert Pot (http://evertpot.com/)
17 * @license http://sabre.io/license/ Modified BSD License
18 */
19class ProxyWrite implements IProxyWrite {
20
21    /**
22     * Parent principal information
23     *
24     * @var array
25     */
26    protected $principalInfo;
27
28    /**
29     * Principal Backend
30     *
31     * @var DAVACL\PrincipalBackend\BackendInterface
32     */
33    protected $principalBackend;
34
35    /**
36     * Creates the object
37     *
38     * Note that you MUST supply the parent principal information.
39     *
40     * @param DAVACL\PrincipalBackend\BackendInterface $principalBackend
41     * @param array $principalInfo
42     */
43    function __construct(DAVACL\PrincipalBackend\BackendInterface $principalBackend, array $principalInfo) {
44
45        $this->principalInfo = $principalInfo;
46        $this->principalBackend = $principalBackend;
47
48    }
49
50    /**
51     * Returns this principals name.
52     *
53     * @return string
54     */
55    function getName() {
56
57        return 'calendar-proxy-write';
58
59    }
60
61    /**
62     * Returns the last modification time
63     *
64     * @return null
65     */
66    function getLastModified() {
67
68        return null;
69
70    }
71
72    /**
73     * Deletes the current node
74     *
75     * @throws DAV\Exception\Forbidden
76     * @return void
77     */
78    function delete() {
79
80        throw new DAV\Exception\Forbidden('Permission denied to delete node');
81
82    }
83
84    /**
85     * Renames the node
86     *
87     * @throws DAV\Exception\Forbidden
88     * @param string $name The new name
89     * @return void
90     */
91    function setName($name) {
92
93        throw new DAV\Exception\Forbidden('Permission denied to rename file');
94
95    }
96
97
98    /**
99     * Returns a list of alternative urls for a principal
100     *
101     * This can for example be an email address, or ldap url.
102     *
103     * @return array
104     */
105    function getAlternateUriSet() {
106
107        return [];
108
109    }
110
111    /**
112     * Returns the full principal url
113     *
114     * @return string
115     */
116    function getPrincipalUrl() {
117
118        return $this->principalInfo['uri'] . '/' . $this->getName();
119
120    }
121
122    /**
123     * Returns the list of group members
124     *
125     * If this principal is a group, this function should return
126     * all member principal uri's for the group.
127     *
128     * @return array
129     */
130    function getGroupMemberSet() {
131
132        return $this->principalBackend->getGroupMemberSet($this->getPrincipalUrl());
133
134    }
135
136    /**
137     * Returns the list of groups this principal is member of
138     *
139     * If this principal is a member of a (list of) groups, this function
140     * should return a list of principal uri's for it's members.
141     *
142     * @return array
143     */
144    function getGroupMembership() {
145
146        return $this->principalBackend->getGroupMembership($this->getPrincipalUrl());
147
148    }
149
150    /**
151     * Sets a list of group members
152     *
153     * If this principal is a group, this method sets all the group members.
154     * The list of members is always overwritten, never appended to.
155     *
156     * This method should throw an exception if the members could not be set.
157     *
158     * @param array $principals
159     * @return void
160     */
161    function setGroupMemberSet(array $principals) {
162
163        $this->principalBackend->setGroupMemberSet($this->getPrincipalUrl(), $principals);
164
165    }
166
167    /**
168     * Returns the displayname
169     *
170     * This should be a human readable name for the principal.
171     * If none is available, return the nodename.
172     *
173     * @return string
174     */
175    function getDisplayName() {
176
177        return $this->getName();
178
179    }
180
181}
182