summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Db/AbsenceMapper.php
diff options
context:
space:
mode:
authorRichard Steinmetz <richard@steinmetz.cloud>2023-10-04 12:31:46 +0200
committerRichard Steinmetz <richard@steinmetz.cloud>2023-10-29 00:08:44 +0200
commit45ed9b10d566d473468c9b829e5fb65829812ee4 (patch)
treefb1d3c702dd1b523e69083455b2447045eed0783 /apps/dav/lib/Db/AbsenceMapper.php
parentd56b1c28bab3daa3425d3ea552e34b0e607f08a3 (diff)
downloadnextcloud-server-45ed9b10d566d473468c9b829e5fb65829812ee4.tar.gz
nextcloud-server-45ed9b10d566d473468c9b829e5fb65829812ee4.zip
feat(dav): implement personal absence settings backend
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'apps/dav/lib/Db/AbsenceMapper.php')
-rw-r--r--apps/dav/lib/Db/AbsenceMapper.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/apps/dav/lib/Db/AbsenceMapper.php b/apps/dav/lib/Db/AbsenceMapper.php
new file mode 100644
index 00000000000..6e1133f779c
--- /dev/null
+++ b/apps/dav/lib/Db/AbsenceMapper.php
@@ -0,0 +1,81 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Richard Steinmetz <richard@steinmetz.cloud>
+ *
+ * @author Richard Steinmetz <richard@steinmetz.cloud>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\Db;
+
+use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\AppFramework\Db\MultipleObjectsReturnedException;
+use OCP\AppFramework\Db\QBMapper;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IDBConnection;
+
+/**
+ * @template-extends QBMapper<Absence>
+ */
+class AbsenceMapper extends QBMapper {
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'dav_absence', Absence::class);
+ }
+
+ /**
+ * @throws DoesNotExistException
+ * @throws \OCP\DB\Exception
+ */
+ public function findByUserId(string $userId): Absence {
+ $qb = $this->db->getQueryBuilder();
+ $qb->select('*')
+ ->from($this->getTableName())
+ ->where($qb->expr()->eq(
+ 'user_id',
+ $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR),
+ IQueryBuilder::PARAM_STR),
+ );
+ try {
+ return $this->findEntity($qb);
+ } catch (MultipleObjectsReturnedException $e) {
+ // Won't happen as there is a unique index on user_id
+ throw new \RuntimeException(
+ 'The impossible has happened! The query returned multiple absence settings for one user.',
+ 0,
+ $e,
+ );
+ }
+ }
+
+ /**
+ * @throws \OCP\DB\Exception
+ */
+ public function deleteByUserId(string $userId): void {
+ $qb = $this->db->getQueryBuilder();
+ $qb->delete($this->getTableName())
+ ->where($qb->expr()->eq(
+ 'user_id',
+ $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR),
+ IQueryBuilder::PARAM_STR),
+ );
+ $qb->executeStatement();
+ }
+}