|DataResponse * * 200: Out-of-office data * 404: No out-of-office data was found */ #[NoAdminRequired] public function getCurrentOutOfOfficeData(string $userId): DataResponse { $user = $this->userManager->get($userId); if ($user === null) { return new DataResponse(null, Http::STATUS_NOT_FOUND); } try { $data = $this->absenceService->getCurrentAbsence($user); if ($data === null) { return new DataResponse(null, Http::STATUS_NOT_FOUND); } } catch (DoesNotExistException) { return new DataResponse(null, Http::STATUS_NOT_FOUND); } return new DataResponse($data->jsonSerialize()); } /** * Get the configured out-of-office data of a user. * * @param string $userId The user id to get out-of-office data for. * @return DataResponse|DataResponse * * 200: Out-of-office data * 404: No out-of-office data was found */ #[NoAdminRequired] public function getOutOfOffice(string $userId): DataResponse { try { $data = $this->absenceService->getAbsence($userId); if ($data === null) { return new DataResponse(null, Http::STATUS_NOT_FOUND); } } catch (DoesNotExistException) { return new DataResponse(null, Http::STATUS_NOT_FOUND); } return new DataResponse([ 'id' => $data->getId(), 'userId' => $data->getUserId(), 'firstDay' => $data->getFirstDay(), 'lastDay' => $data->getLastDay(), 'status' => $data->getStatus(), 'message' => $data->getMessage(), ]); } /** * Set out-of-office absence * * @param string $firstDay First day of the absence in format `YYYY-MM-DD` * @param string $lastDay Last day of the absence in format `YYYY-MM-DD` * @param string $status Short text that is set as user status during the absence * @param string $message Longer multiline message that is shown to others during the absence * @return DataResponse|DataResponse|DataResponse * * 200: Absence data * 400: When the first day is not before the last day * 401: When the user is not logged in */ #[NoAdminRequired] public function setOutOfOffice( string $firstDay, string $lastDay, string $status, string $message, ): DataResponse { $user = $this->userSession?->getUser(); if ($user === null) { return new DataResponse(null, Http::STATUS_UNAUTHORIZED); } $parsedFirstDay = new DateTimeImmutable($firstDay); $parsedLastDay = new DateTimeImmutable($lastDay); if ($parsedFirstDay->getTimestamp() > $parsedLastDay->getTimestamp()) { return new DataResponse(['error' => 'firstDay'], Http::STATUS_BAD_REQUEST); } $data = $this->absenceService->createOrUpdateAbsence( $user, $firstDay, $lastDay, $status, $message, ); $this->coordinator->clearCache($user->getUID()); return new DataResponse([ 'id' => $data->getId(), 'userId' => $data->getUserId(), 'firstDay' => $data->getFirstDay(), 'lastDay' => $data->getLastDay(), 'status' => $data->getStatus(), 'message' => $data->getMessage(), ]); } /** * Clear the out-of-office * * @return DataResponse * * 200: When the absence was cleared successfully * 401: When the user is not logged in */ #[NoAdminRequired] public function clearOutOfOffice(): DataResponse { $user = $this->userSession?->getUser(); if ($user === null) { return new DataResponse(null, Http::STATUS_UNAUTHORIZED); } $this->absenceService->clearAbsence($user); $this->coordinator->clearCache($user->getUID()); return new DataResponse(null); } }