aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Settings/AvailabilitySettings.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/Settings/AvailabilitySettings.php')
-rw-r--r--apps/dav/lib/Settings/AvailabilitySettings.php27
1 files changed, 26 insertions, 1 deletions
diff --git a/apps/dav/lib/Settings/AvailabilitySettings.php b/apps/dav/lib/Settings/AvailabilitySettings.php
index 54df6b88d55..e2f2fe7cef6 100644
--- a/apps/dav/lib/Settings/AvailabilitySettings.php
+++ b/apps/dav/lib/Settings/AvailabilitySettings.php
@@ -6,6 +6,7 @@ declare(strict_types=1);
* @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
@@ -26,10 +27,13 @@ declare(strict_types=1);
namespace OCA\DAV\Settings;
use OCA\DAV\AppInfo\Application;
+use OCA\DAV\Db\AbsenceMapper;
+use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\Settings\ISettings;
+use Psr\Log\LoggerInterface;
class AvailabilitySettings implements ISettings {
protected IConfig $config;
@@ -38,7 +42,9 @@ class AvailabilitySettings implements ISettings {
public function __construct(IConfig $config,
IInitialState $initialState,
- ?string $userId) {
+ ?string $userId,
+ private LoggerInterface $logger,
+ private AbsenceMapper $absenceMapper) {
$this->config = $config;
$this->initialState = $initialState;
$this->userId = $userId;
@@ -54,6 +60,25 @@ class AvailabilitySettings implements ISettings {
'no'
)
);
+ $hideAbsenceSettings = $this->config->getAppValue(
+ Application::APP_ID,
+ 'hide_absence_settings',
+ 'yes',
+ ) === 'yes';
+ $this->initialState->provideInitialState('hide_absence_settings', $hideAbsenceSettings);
+ if (!$hideAbsenceSettings) {
+ try {
+ $absence = $this->absenceMapper->findByUserId($this->userId);
+ $this->initialState->provideInitialState('absence', $absence);
+ } catch (DoesNotExistException) {
+ // The user has not yet set up an absence period.
+ // Logging this error is not necessary.
+ } catch (\OCP\DB\Exception $e) {
+ $this->logger->error("Could not find absence data for user $this->userId: " . $e->getMessage(), [
+ 'exception' => $e,
+ ]);
+ }
+ }
return new TemplateResponse(Application::APP_ID, 'settings-personal-availability');
}