provide room / resource properties as principal properties
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
parent
9f345bd786
commit
54fb0f4f04
3 changed files with 57 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
|
||||
* @copyright 2019, Georg Ehrke <oc.list@georgehrke.com>
|
||||
*
|
||||
* @author Georg Ehrke <oc.list@georgehrke.com>
|
||||
*
|
||||
|
@ -50,6 +50,12 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
|
|||
/** @var string */
|
||||
private $dbTableName;
|
||||
|
||||
/** @var string */
|
||||
private $dbMetaDataTableName;
|
||||
|
||||
/** @var string */
|
||||
private $dbForeignKeyName;
|
||||
|
||||
/** @var string */
|
||||
private $cuType;
|
||||
|
||||
|
@ -74,7 +80,9 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
|
|||
$this->groupManager = $groupManager;
|
||||
$this->logger = $logger;
|
||||
$this->principalPrefix = $principalPrefix;
|
||||
$this->dbTableName = 'calendar_' . $dbPrefix;
|
||||
$this->dbTableName = 'calendar_' . $dbPrefix . 's';
|
||||
$this->dbMetaDataTableName = $this->dbTableName . '_md';
|
||||
$this->dbForeignKeyName = $dbPrefix . '_id';
|
||||
$this->cuType = $cuType;
|
||||
}
|
||||
|
||||
|
@ -100,8 +108,31 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
|
|||
->from($this->dbTableName);
|
||||
$stmt = $query->execute();
|
||||
|
||||
$metaDataQuery = $this->db->getQueryBuilder();
|
||||
$metaDataQuery->select([$this->dbForeignKeyName, 'key', 'value'])
|
||||
->from($this->dbMetaDataTableName);
|
||||
$metaDataStmt = $metaDataQuery->execute();
|
||||
$metaDataRows = $metaDataStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
$metaDataById = [];
|
||||
foreach($metaDataRows as $metaDataRow) {
|
||||
if (!isset($metaDataById[$metaDataRow[$this->dbForeignKeyName]])) {
|
||||
$metaDataById[$metaDataRow[$this->dbForeignKeyName]] = [];
|
||||
}
|
||||
|
||||
$metaDataById[$metaDataRow[$this->dbForeignKeyName]][$metaDataRow['key']] =
|
||||
$metaDataRow['value'];
|
||||
}
|
||||
|
||||
while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$principals[] = $this->rowToPrincipal($row);
|
||||
$id = $row['id'];
|
||||
|
||||
if (isset($metaDataById[$id])) {
|
||||
$principals[] = $this->rowToPrincipal($row, $metaDataById[$id]);
|
||||
} else {
|
||||
$principals[] = $this->rowToPrincipal($row);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
|
@ -138,7 +169,19 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
|
|||
return null;
|
||||
}
|
||||
|
||||
return $this->rowToPrincipal($row);
|
||||
$metaDataQuery = $this->db->getQueryBuilder();
|
||||
$metaDataQuery->select(['key', 'value'])
|
||||
->from($this->dbMetaDataTableName)
|
||||
->where($metaDataQuery->expr()->eq($this->dbForeignKeyName, $metaDataQuery->createNamedParameter($row['id'])));
|
||||
$metaDataStmt = $metaDataQuery->execute();
|
||||
$metaDataRows = $metaDataStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$metadata = [];
|
||||
|
||||
foreach($metaDataRows as $metaDataRow) {
|
||||
$metadata[$metaDataRow['key']] = $metaDataRow['value'];
|
||||
}
|
||||
|
||||
return $this->rowToPrincipal($row, $metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -338,14 +381,18 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
|
|||
|
||||
/**
|
||||
* convert database row to principal
|
||||
*
|
||||
* @param String[] $row
|
||||
* @param String[] $metadata
|
||||
* @return Array
|
||||
*/
|
||||
private function rowToPrincipal($row) {
|
||||
return [
|
||||
private function rowToPrincipal(array $row, array $metadata=[]):array {
|
||||
return array_merge([
|
||||
'uri' => $this->principalPrefix . '/' . $row['backend_id'] . '-' . $row['resource_id'],
|
||||
'{DAV:}displayname' => $row['displayname'],
|
||||
'{http://sabredav.org/ns}email-address' => $row['email'],
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->cuType,
|
||||
];
|
||||
], $metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -353,7 +400,7 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
|
|||
* @param $userGroups
|
||||
* @return bool
|
||||
*/
|
||||
private function isAllowedToAccessResource($row, $userGroups) {
|
||||
private function isAllowedToAccessResource(array $row, array $userGroups):bool {
|
||||
if (!isset($row['group_restrictions']) ||
|
||||
$row['group_restrictions'] === null ||
|
||||
$row['group_restrictions'] === '') {
|
||||
|
|
|
@ -40,6 +40,6 @@ class ResourcePrincipalBackend extends AbstractPrincipalBackend {
|
|||
IGroupManager $groupManager,
|
||||
ILogger $logger) {
|
||||
parent::__construct($dbConnection, $userSession, $groupManager, $logger,
|
||||
'principals/calendar-resources', 'resources', 'RESOURCE');
|
||||
'principals/calendar-resources', 'resource', 'RESOURCE');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,6 @@ class RoomPrincipalBackend extends AbstractPrincipalBackend {
|
|||
IGroupManager $groupManager,
|
||||
ILogger $logger) {
|
||||
parent::__construct($dbConnection, $userSession, $groupManager, $logger,
|
||||
'principals/calendar-rooms', 'rooms', 'ROOM');
|
||||
'principals/calendar-rooms', 'room', 'ROOM');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue