From f14a4f8fd73c71e76a9747ac51e657030f5bb835 Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Mon, 25 Sep 2023 14:47:02 +0200 Subject: feat(user status): automate user status for events and automatically set a user status to free or busy depending on their calendar transparency, event status and availability settings Signed-off-by: Anna Larch --- apps/user_status/lib/Db/UserStatusMapper.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'apps/user_status/lib/Db/UserStatusMapper.php') diff --git a/apps/user_status/lib/Db/UserStatusMapper.php b/apps/user_status/lib/Db/UserStatusMapper.php index 3621c1bfa96..c8ffcca5ad9 100644 --- a/apps/user_status/lib/Db/UserStatusMapper.php +++ b/apps/user_status/lib/Db/UserStatusMapper.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace OCA\UserStatus\Db; +use Sabre\CalDAV\Schedule\Plugin; use OCP\AppFramework\Db\QBMapper; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; @@ -210,4 +211,23 @@ class UserStatusMapper extends QBMapper { $qb->executeStatement(); } + + public function getAvailabilityFromPropertiesTable(string $userId): ?string { + $propertyPath = 'calendars/' . $userId . '/inbox'; + $propertyName = '{' . Plugin::NS_CALDAV . '}calendar-availability'; + + $query = $this->db->getQueryBuilder(); + $query->select('propertyvalue') + ->from('properties') + ->where($query->expr()->eq('userid', $query->createNamedParameter($userId))) + ->andWhere($query->expr()->eq('propertypath', $query->createNamedParameter($propertyPath))) + ->andWhere($query->expr()->eq('propertyname', $query->createNamedParameter($propertyName))) + ->setMaxResults(1); + + $result = $query->executeQuery(); + $property = $result->fetchOne(); + $result->closeCursor(); + + return ($property === false ? null : $property); + } } -- cgit v1.2.3