53 '{DAV:}displayname' => [
54 'dbField' =>
'displayname',
60 '{http://sabredav.org/ns}email-address' => [
98 foreach ($this->fieldMap as
$key => $value) {
99 $fields[] = $value[
'dbField'];
101 $result = $this->pdo->query(
'SELECT ' . implode(
',', $fields) .
' FROM ' . $this->tableName);
109 if ($rowPrefix !== $prefixPath)
continue;
112 'uri' =>
$row[
'uri'],
114 foreach ($this->fieldMap as
$key => $value) {
115 if (
$row[$value[
'dbField']]) {
116 $principal[
$key] =
$row[$value[
'dbField']];
119 $principals[] = $principal;
142 foreach ($this->fieldMap as
$key => $value) {
143 $fields[] = $value[
'dbField'];
145 $stmt = $this->pdo->prepare(
'SELECT ' . implode(
',', $fields) .
' FROM ' . $this->tableName .
' WHERE uri = ?');
153 'uri' =>
$row[
'uri'],
155 foreach ($this->fieldMap as
$key => $value) {
156 if (
$row[$value[
'dbField']]) {
157 $principal[
$key] =
$row[$value[
'dbField']];
181 $propPatch->handle(array_keys($this->fieldMap),
function($properties) use (
$path) {
183 $query =
"UPDATE " . $this->tableName .
" SET ";
188 foreach ($properties as
$key => $value) {
190 $dbField = $this->fieldMap[
$key][
'dbField'];
196 $query .= $dbField .
' = :' . $dbField;
201 $query .=
" WHERE uri = :uri";
243 if (count($searchProperties) == 0)
return [];
245 $query =
'SELECT uri FROM ' . $this->tableName .
' WHERE ';
247 foreach ($searchProperties as $property => $value) {
249 case '{DAV:}displayname' :
250 $column =
"displayname";
252 case '{http://sabredav.org/ns}email-address' :
260 $query .=
'lower(' . $column .
') LIKE lower(?)';
261 $values[] =
'%' . $value .
'%';
268 while (
$row =
$stmt->fetch(\PDO::FETCH_ASSOC)) {
272 if ($rowPrefix !== $prefixPath)
continue;
274 $principals[] =
$row[
'uri'];
302 list($scheme, $value) = explode(
":", $uri, 2);
303 if (empty($value))
return null;
308 $query =
'SELECT uri FROM ' . $this->tableName .
' WHERE lower(email)=lower(?)';
310 $stmt->execute([$value]);
312 while (
$row =
$stmt->fetch(\PDO::FETCH_ASSOC)) {
315 if ($rowPrefix !== $principalPrefix)
continue;
337 if (!$principal)
throw new DAV\Exception(
'Principal not found');
339 $stmt = $this->pdo->prepare(
'SELECT principals.uri as uri FROM ' . $this->groupMembersTableName .
' AS groupmembers LEFT JOIN ' . $this->tableName .
' AS principals ON groupmembers.member_id = principals.id WHERE groupmembers.principal_id = ?');
340 $stmt->execute([$principal[
'id']]);
343 while (
$row =
$stmt->fetch(\PDO::FETCH_ASSOC)) {
359 if (!$principal)
throw new DAV\Exception(
'Principal not found');
361 $stmt = $this->pdo->prepare(
'SELECT principals.uri as uri FROM ' . $this->groupMembersTableName .
' AS groupmembers LEFT JOIN ' . $this->tableName .
' AS principals ON groupmembers.principal_id = principals.id WHERE groupmembers.member_id = ?');
362 $stmt->execute([$principal[
'id']]);
365 while (
$row =
$stmt->fetch(\PDO::FETCH_ASSOC)) {
384 $stmt = $this->pdo->prepare(
'SELECT id, uri FROM ' . $this->tableName .
' WHERE uri IN (? ' . str_repeat(
', ? ', count($members)) .
');');
385 $stmt->execute(array_merge([$principal], $members));
390 while (
$row =
$stmt->fetch(\PDO::FETCH_ASSOC)) {
391 if (
$row[
'uri'] == $principal) {
392 $principalId =
$row[
'id'];
394 $memberIds[] =
$row[
'id'];
397 if (!$principalId)
throw new DAV\Exception(
'Principal not found');
400 $stmt = $this->pdo->prepare(
'DELETE FROM ' . $this->groupMembersTableName .
' WHERE principal_id = ?;');
401 $stmt->execute([$principalId]);
403 foreach ($memberIds as $memberId) {
405 $stmt = $this->pdo->prepare(
'INSERT INTO ' . $this->groupMembersTableName .
' (principal_id, member_id) VALUES (?, ?);');
406 $stmt->execute([$principalId, $memberId]);
425 $stmt = $this->pdo->prepare(
'INSERT INTO ' . $this->tableName .
' (uri) VALUES (?)');
findByUri($uri, $principalPrefix)
Finds a principal by its URI.
This class represents a set of properties that are going to be updated.
Abstract Principal Backend.
getPrincipalsByPrefix($prefixPath)
Returns a list of principals based on a prefix.
Implement this interface to add support for creating new principals to your principal backend...
createPrincipal($path, MkCol $mkCol)
Creates a new principal.
searchPrincipals($prefixPath, array $searchProperties, $test='allof')
This method is used to search for principals matching a set of properties.
__construct(\PDO $pdo)
This is the users' primary email-address.
updatePrincipal($path, DAV\PropPatch $propPatch)
Updates one ore more webdav properties on a principal.
This class represents a MKCOL operation.
getGroupMemberSet($principal)
Returns the list of members for a group-principal.
getGroupMembership($principal)
Returns the list of groups a principal is a member of.
setGroupMemberSet($principal, array $members)
Updates the list of group members for a group principal.
static splitPath($path)
Returns the 'dirname' and 'basename' for a path.
getPrincipalByPath($path)
Returns a specific principal, specified by it's path.