diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-09-27 11:41:20 +0200 |
---|---|---|
committer | Richard Steinmetz <richard@steinmetz.cloud> | 2023-11-09 10:36:11 +0100 |
commit | ab1a1d688df76fb5c10b8bc431b928a2db1675bd (patch) | |
tree | 0147377303eccd1f6d22569fdf604d726ab8ca45 /apps/dav/lib/Db | |
parent | 1acc7c04684a05f024f4c83a8665d4732c2fc5f6 (diff) | |
download | nextcloud-server-ab1a1d688df76fb5c10b8bc431b928a2db1675bd.tar.gz nextcloud-server-ab1a1d688df76fb5c10b8bc431b928a2db1675bd.zip |
feat: Add out-of-office message API
[skipci]
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'apps/dav/lib/Db')
-rw-r--r-- | apps/dav/lib/Db/Absence.php | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/apps/dav/lib/Db/Absence.php b/apps/dav/lib/Db/Absence.php index f705b99ef30..e9ce1d2ea64 100644 --- a/apps/dav/lib/Db/Absence.php +++ b/apps/dav/lib/Db/Absence.php @@ -26,8 +26,13 @@ declare(strict_types=1); namespace OCA\DAV\Db; +use DateTimeImmutable; +use InvalidArgumentException; use JsonSerializable; +use OC\User\OutOfOfficeData; use OCP\AppFramework\Db\Entity; +use OCP\IUser; +use OCP\User\IOutOfOfficeData; /** * @method string getUserId() @@ -43,8 +48,13 @@ use OCP\AppFramework\Db\Entity; */ class Absence extends Entity implements JsonSerializable { protected string $userId = ''; + + /** Inclusive, formatted as YYYY-MM-DD */ protected string $firstDay = ''; + + /** Inclusive, formatted as YYYY-MM-DD */ protected string $lastDay = ''; + protected string $status = ''; protected string $message = ''; @@ -56,6 +66,24 @@ class Absence extends Entity implements JsonSerializable { $this->addType('message', 'string'); } + public function toOutOufOfficeData(IUser $user): IOutOfOfficeData { + if ($user->getUID() !== $this->getUserId()) { + throw new InvalidArgumentException("The user doesn't match the user id of this absence! Expected " . $this->getUserId() . ", got " . $user->getUID()); + } + + //$user = $userManager->get($this->getUserId()); + $startDate = new DateTimeImmutable($this->getFirstDay()); + $endDate = new DateTimeImmutable($this->getLastDay()); + return new OutOfOfficeData( + (string)$this->getId(), + $user, + $startDate->getTimestamp(), + $endDate->getTimestamp(), + $this->getStatus(), + $this->getMessage(), + ); + } + public function jsonSerialize(): array { return [ 'userId' => $this->userId, |