provide room / resource properties as principal properties
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
parent
9f345bd786
commit
54fb0f4f04
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
|
* @copyright 2019, Georg Ehrke <oc.list@georgehrke.com>
|
||||||
*
|
*
|
||||||
* @author Georg Ehrke <oc.list@georgehrke.com>
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
||||||
*
|
*
|
||||||
|
@ -50,6 +50,12 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $dbTableName;
|
private $dbTableName;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $dbMetaDataTableName;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $dbForeignKeyName;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $cuType;
|
private $cuType;
|
||||||
|
|
||||||
|
@ -74,7 +80,9 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
|
||||||
$this->groupManager = $groupManager;
|
$this->groupManager = $groupManager;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->principalPrefix = $principalPrefix;
|
$this->principalPrefix = $principalPrefix;
|
||||||
$this->dbTableName = 'calendar_' . $dbPrefix;
|
$this->dbTableName = 'calendar_' . $dbPrefix . 's';
|
||||||
|
$this->dbMetaDataTableName = $this->dbTableName . '_md';
|
||||||
|
$this->dbForeignKeyName = $dbPrefix . '_id';
|
||||||
$this->cuType = $cuType;
|
$this->cuType = $cuType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,10 +108,33 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
|
||||||
->from($this->dbTableName);
|
->from($this->dbTableName);
|
||||||
$stmt = $query->execute();
|
$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)) {
|
while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||||
|
$id = $row['id'];
|
||||||
|
|
||||||
|
if (isset($metaDataById[$id])) {
|
||||||
|
$principals[] = $this->rowToPrincipal($row, $metaDataById[$id]);
|
||||||
|
} else {
|
||||||
$principals[] = $this->rowToPrincipal($row);
|
$principals[] = $this->rowToPrincipal($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +169,19 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
|
||||||
return null;
|
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
|
* convert database row to principal
|
||||||
|
*
|
||||||
|
* @param String[] $row
|
||||||
|
* @param String[] $metadata
|
||||||
|
* @return Array
|
||||||
*/
|
*/
|
||||||
private function rowToPrincipal($row) {
|
private function rowToPrincipal(array $row, array $metadata=[]):array {
|
||||||
return [
|
return array_merge([
|
||||||
'uri' => $this->principalPrefix . '/' . $row['backend_id'] . '-' . $row['resource_id'],
|
'uri' => $this->principalPrefix . '/' . $row['backend_id'] . '-' . $row['resource_id'],
|
||||||
'{DAV:}displayname' => $row['displayname'],
|
'{DAV:}displayname' => $row['displayname'],
|
||||||
'{http://sabredav.org/ns}email-address' => $row['email'],
|
'{http://sabredav.org/ns}email-address' => $row['email'],
|
||||||
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->cuType,
|
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->cuType,
|
||||||
];
|
], $metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -353,7 +400,7 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
|
||||||
* @param $userGroups
|
* @param $userGroups
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function isAllowedToAccessResource($row, $userGroups) {
|
private function isAllowedToAccessResource(array $row, array $userGroups):bool {
|
||||||
if (!isset($row['group_restrictions']) ||
|
if (!isset($row['group_restrictions']) ||
|
||||||
$row['group_restrictions'] === null ||
|
$row['group_restrictions'] === null ||
|
||||||
$row['group_restrictions'] === '') {
|
$row['group_restrictions'] === '') {
|
||||||
|
|
|
@ -40,6 +40,6 @@ class ResourcePrincipalBackend extends AbstractPrincipalBackend {
|
||||||
IGroupManager $groupManager,
|
IGroupManager $groupManager,
|
||||||
ILogger $logger) {
|
ILogger $logger) {
|
||||||
parent::__construct($dbConnection, $userSession, $groupManager, $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,
|
IGroupManager $groupManager,
|
||||||
ILogger $logger) {
|
ILogger $logger) {
|
||||||
parent::__construct($dbConnection, $userSession, $groupManager, $logger,
|
parent::__construct($dbConnection, $userSession, $groupManager, $logger,
|
||||||
'principals/calendar-rooms', 'rooms', 'ROOM');
|
'principals/calendar-rooms', 'room', 'ROOM');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue