nextcloud-pride-flags/lib/Settings/AppSettings.php

52 lines
1.8 KiB
PHP
Raw Normal View History

2024-08-05 18:31:55 +00:00
<?php
2024-07-28 15:57:30 +00:00
namespace OCA\PrideFlags\Settings;
use OCA\PrideFlags\AppConstants;
use OCP\IConfig;
class AppSettings {
public const FOLDER_VARIANT = 'folderVariant';
public const BUTTON_VARIANT = 'buttonVariant';
public function __construct(private IConfig $config) {
}
2024-08-08 21:16:22 +00:00
public function getStringSetting($userId, string $key, string $default = ''): string {
return $this->config->getUserValue(AppConstants::APP_ID, $userId, $key)
?: ($this->config->getAppValue(AppConstants::APP_ID, $userId, $key) ?: $default);
2024-07-28 15:57:30 +00:00
}
2024-08-08 21:16:22 +00:00
public function setStringSetting($userId, string $key, string $value): void {
$this->config->setUserValue(AppConstants::APP_ID, $userId, $key, $value);
2024-07-28 15:57:30 +00:00
}
public function setAppStringSetting(string $key, string $value): void {
$this->config->setAppValue(AppConstants::APP_ID, $key, $value);
}
2024-08-08 21:16:22 +00:00
public function getAll($userId): array {
2024-07-28 15:57:30 +00:00
return [
2024-08-08 21:16:22 +00:00
AppSettings::FOLDER_VARIANT => $this->getStringSetting($userId, AppSettings::FOLDER_VARIANT, 'pride'),
AppSettings::BUTTON_VARIANT => $this->getStringSetting($userId, AppSettings::BUTTON_VARIANT, 'trans'),
2024-07-28 15:57:30 +00:00
];
}
public function getGlobal(): array {
return [
AppSettings::FOLDER_VARIANT => $this->config->getAppValue(AppConstants::APP_ID, AppSettings::FOLDER_VARIANT, 'pride'),
AppSettings::BUTTON_VARIANT => $this->config->getAppValue(AppConstants::APP_ID, AppSettings::BUTTON_VARIANT, 'trans'),
];
}
2024-08-08 21:16:22 +00:00
public function set($userId, $folder, $button): void {
$this->setStringSetting($userId, AppSettings::FOLDER_VARIANT, $folder);
$this->setStringSetting($userId, AppSettings::BUTTON_VARIANT, $button);
2024-07-28 15:57:30 +00:00
}
public function setGlobal($folder, $button): void {
$this->setAppStringSetting(AppSettings::FOLDER_VARIANT, $folder);
$this->setAppStringSetting(AppSettings::BUTTON_VARIANT, $button);
}
2024-07-28 15:57:30 +00:00
}