diff options
author | Georg Ehrke <developer@georgehrke.com> | 2019-07-26 15:50:16 +0300 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2019-08-01 11:08:56 +0300 |
commit | 54fb0f4f045ad1fa598c02b1d641b3695a9779e8 (patch) | |
tree | 971fe46130af357c1c3ddeeae2e59305bade5557 /apps/dav | |
parent | 9f345bd7862a11b005d94642c82b365055cc6f63 (diff) |
provide room / resource properties as principal properties
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav')
3 files changed, 57 insertions, 10 deletions
diff --git a/apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php b/apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php index 90d147f6741..bc96041d915 100644 --- a/apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php +++ b/apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php @@ -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> * @@ -51,6 +51,12 @@ abstract class AbstractPrincipalBackend implements BackendInterface { 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'] === '') { diff --git a/apps/dav/lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php b/apps/dav/lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php index f8f10e78f94..0f6e6e7b4fd 100644 --- a/apps/dav/lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php +++ b/apps/dav/lib/CalDAV/ResourceBooking/ResourcePrincipalBackend.php @@ -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'); } } diff --git a/apps/dav/lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php b/apps/dav/lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php index 3059ed80ea6..68a344aa0ca 100644 --- a/apps/dav/lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php +++ b/apps/dav/lib/CalDAV/ResourceBooking/RoomPrincipalBackend.php @@ -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'); } } |