4 class Sabre_DAVACL_PrincipalBackend_Std implements Sabre_DAVACL_IPrincipalBackend
12 public $prefix = 'principals/users';
15 * @var Sabre_DAV_Auth_Backend_AbstractBasic $authBackend;
17 protected $authBackend;
19 public function __construct(&$authBackend)
22 $this->authBackend = &$authBackend;
28 * @var Sabre_DAVACL_IPrincipalBackend|null
30 private static $intstance = null;
34 * @return Sabre_DAVACL_IPrincipalBackend
36 public static function &getInstance() {
37 if (is_null(self::$intstance)) {
38 $authBackend = Sabre_DAV_Auth_Backend_Std::getInstance();
39 self::$intstance = new Sabre_DAVACL_PrincipalBackend_Std($authBackend);
41 return self::$intstance;
45 * Returns a list of principals based on a prefix.
47 * This prefix will often contain something like 'principals'. You are only
48 * expected to return principals that are in this base path.
50 * You are expected to return at least a 'uri' for every user, you can
51 * return any additional properties if you wish so. Common properties are:
53 * {http://sabredav.org/ns}email-address - This is a custom SabreDAV
54 * field that's actualy injected in a number of other properties. If
55 * you have an email address, use this property.
57 * @param string $prefixPath
60 public function getPrincipalsByPrefix($prefixPath)
63 // This backend only support principals in one collection
64 if ($prefixPath !== $this->prefix) return array();
68 $r = q("SELECT `nickname` FROM `user` WHERE `nickname` = '%s'", escape_tags($this->authBackend->getCurrentUser()) );
71 'uri' => $this->prefix . '/' . strtolower($t['nickname']),
72 '{DAV:}displayname' => $t['nickname'],
81 * Returns a specific principal, specified by it's path.
82 * The returned structure should be the exact same as from
83 * getPrincipalsByPrefix.
88 public function getPrincipalByPath($path)
91 list($prefixPath, $userName) = Sabre_DAV_URLUtil::splitPath($path);
93 // This backend only support principals in one collection
94 if ($prefixPath !== $this->prefix) return null;
96 $r = q("SELECT `nickname` FROM `user` WHERE `nickname` = '%s'", escape_tags($userName) );
97 if (count($r) == 0) return array();
100 'uri' => $this->prefix . '/' . strtolower($r[0]['nickname']),
101 '{DAV:}displayname' => $r[0]['nickname'],
107 function getGroupMemberSet($principal)
112 function getGroupMembership($principal)
119 * Updates the list of group members for a group principal.
121 * The principals should be passed as a list of uri's.
123 * @param string $principal
124 * @param array $members
125 * @throws Sabre_DAV_Exception
128 public function setGroupMemberSet($principal, array $members)
130 throw new Sabre_DAV_Exception('Operation not supported');
134 * Updates one ore more webdav properties on a principal.
136 * The list of mutations is supplied as an array. Each key in the array is
137 * a propertyname, such as {DAV:}displayname.
139 * Each value is the actual value to be updated. If a value is null, it
142 * This method should be atomic. It must either completely succeed, or
143 * completely fail. Success and failure can simply be returned as 'true' or
146 * It is also possible to return detailed failure information. In that case
147 * an array such as this should be returned:
151 * '{DAV:}prop1' => null,
154 * '{DAV:}prop2' => null,
157 * '{DAV:}prop3' => null,
160 * '{DAV:}prop4' => null,
164 * In this previous example prop1 was successfully updated or deleted, and
165 * prop2 was succesfully created.
167 * prop3 failed to update due to '403 Forbidden' and because of this prop4
168 * also could not be updated with '424 Failed dependency'.
170 * This last example was actually incorrect. While 200 and 201 could appear
171 * in 1 response, if there's any error (403) the other properties should
172 * always fail with 423 (failed dependency).
174 * But anyway, if you don't want to scratch your head over this, just
175 * return true or false.
177 * @param string $path
178 * @param array $mutations
181 function updatePrincipal($path, $mutations)
183 // TODO: Implement updatePrincipal() method.
187 * This method is used to search for principals matching a set of
190 * This search is specifically used by RFC3744's principal-property-search
191 * REPORT. You should at least allow searching on
192 * http://sabredav.org/ns}email-address.
194 * The actual search should be a unicode-non-case-sensitive search. The
195 * keys in searchProperties are the WebDAV property names, while the values
196 * are the property values to search on.
198 * If multiple properties are being searched on, the search should be
201 * This method should simply return an array with full principal uri's.
203 * If somebody attempted to search on a property the backend does not
204 * support, you should simply return 0 results.
206 * You can also just return 0 results if you choose to not support
207 * searching at all, but keep in mind that this may stop certain features
210 * @param string $prefixPath
211 * @param array $searchProperties
214 function searchPrincipals($prefixPath, array $searchProperties)
216 // TODO: Implement searchPrincipals() method.