diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2023-10-04 12:31:46 +0200 |
---|---|---|
committer | Richard Steinmetz <richard@steinmetz.cloud> | 2023-10-29 00:08:44 +0200 |
commit | 45ed9b10d566d473468c9b829e5fb65829812ee4 (patch) | |
tree | fb1d3c702dd1b523e69083455b2447045eed0783 /apps/dav/lib/Service/AbsenceService.php | |
parent | d56b1c28bab3daa3425d3ea552e34b0e607f08a3 (diff) | |
download | nextcloud-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/Service/AbsenceService.php')
-rw-r--r-- | apps/dav/lib/Service/AbsenceService.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/apps/dav/lib/Service/AbsenceService.php b/apps/dav/lib/Service/AbsenceService.php new file mode 100644 index 00000000000..228007b3af1 --- /dev/null +++ b/apps/dav/lib/Service/AbsenceService.php @@ -0,0 +1,74 @@ +<?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\Service; + +use OCA\DAV\Db\Absence; +use OCA\DAV\Db\AbsenceMapper; +use OCP\AppFramework\Db\DoesNotExistException; + +class AbsenceService { + public function __construct( + private AbsenceMapper $absenceMapper, + ) { + } + + /** + * @throws \OCP\DB\Exception + */ + public function createOrUpdateAbsence( + string $userId, + string $firstDay, + string $lastDay, + string $status, + string $message, + ): Absence { + try { + $absence = $this->absenceMapper->findByUserId($userId); + } catch (DoesNotExistException) { + $absence = new Absence(); + } + + $absence->setUserId($userId); + $absence->setFirstDay($firstDay); + $absence->setLastDay($lastDay); + $absence->setStatus($status); + $absence->setMessage($message); + + if ($absence->getId() === null) { + return $this->absenceMapper->insert($absence); + } + return $this->absenceMapper->update($absence); + } + + /** + * @throws \OCP\DB\Exception + */ + public function clearAbsence(string $userId): void { + $this->absenceMapper->deleteByUserId($userId); + } +} + |