$query='SELECT uri FROM '.$this->tableName.' WHERE 1=1 ';
$values=[];
foreach($searchPropertiesas$property=>$value){
switch($property){
case'{DAV:}displayname':
$query.=' AND displayname LIKE ?';
$values[]='%'.$value.'%';
break;
case'{http://sabredav.org/ns}email-address':
$query.=' AND email LIKE ?';
$values[]='%'.$value.'%';
break;
default:
// Unsupported property
return[];
}
}
$stmt=$this->pdo->prepare($query);
$stmt->execute($values);
$principals=[];
while($row=$stmt->fetch(\PDO::FETCH_ASSOC)){
// Checking if the principal is in the prefix
list($rowPrefix)=URLUtil::splitPath($row['uri']);
if($rowPrefix!==$prefixPath)continue;
$principals[]=$row['uri'];
}
return$principals;
}
/**
* Returns the list of members for a group-principal
*
* @param string $principal
* @return array
*/
functiongetGroupMemberSet($principal){
$principal=$this->getPrincipalByPath($principal);
if(!$principal)thrownewDAV\Exception('Principal not found');
$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 = ?');
$stmt->execute([$principal['id']]);
$result=[];
while($row=$stmt->fetch(\PDO::FETCH_ASSOC)){
$result[]=$row['uri'];
}
return$result;
}
/**
* Returns the list of groups a principal is a member of
*
* @param string $principal
* @return array
*/
functiongetGroupMembership($principal){
$principal=$this->getPrincipalByPath($principal);
if(!$principal)thrownewDAV\Exception('Principal not found');
$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 = ?');
$stmt->execute([$principal['id']]);
$result=[];
while($row=$stmt->fetch(\PDO::FETCH_ASSOC)){
$result[]=$row['uri'];
}
return$result;
}
/**
* Updates the list of group members for a group principal.
*
* The principals should be passed as a list of uri's.