<?php
/**
- * @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
+ * @copyright 2019, Georg Ehrke <oc.list@georgehrke.com>
*
* @author Georg Ehrke <oc.list@georgehrke.com>
*
/** @var string */
private $dbTableName;
+ /** @var string */
+ private $dbMetaDataTableName;
+
+ /** @var string */
+ private $dbForeignKeyName;
+
/** @var string */
private $cuType;
$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;
}
->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();
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);
}
/**
/**
* 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);
}
/**
* @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'] === '') {