feat: allow global settings as fallback when user has not defined any
This commit is contained in:
30
lib/Settings/AdminSection.php
Normal file
30
lib/Settings/AdminSection.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\PrideFlags\Settings;
|
||||
|
||||
use OCA\PrideFlags\AppConstants;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\Settings\IIConSection;
|
||||
|
||||
class AdminSection implements IIconSection {
|
||||
public function __construct(private IL10N $l10n, private IURLGenerator $urlGenerator) {}
|
||||
|
||||
public function getID(): string {
|
||||
return AppConstants::APP_ID;
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return 'Pride Flags';
|
||||
}
|
||||
|
||||
public function getPriority(): int {
|
||||
return 100;
|
||||
}
|
||||
|
||||
public function getIcon(): string {
|
||||
return $this->urlGenerator->imagePath('core', 'actions/settings-dark.svg');
|
||||
}
|
||||
}
|
25
lib/Settings/AdminSettings.php
Normal file
25
lib/Settings/AdminSettings.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\PrideFlags\Settings;
|
||||
|
||||
use OCA\PrideFlags\AppConstants;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\Settings\ISettings;
|
||||
use OCP\Util;
|
||||
|
||||
class AdminSettings implements ISettings {
|
||||
public function getForm(): TemplateResponse {
|
||||
Util::addScript(AppConstants::APP_ID, 'pride-settings-global');
|
||||
return new TemplateResponse(AppConstants::APP_ID, 'server-settings', []);
|
||||
}
|
||||
|
||||
public function getSection(): string {
|
||||
return AppConstants::APP_ID;
|
||||
}
|
||||
|
||||
public function getPriority(): int {
|
||||
return 50;
|
||||
}
|
||||
}
|
@ -13,13 +13,18 @@ class AppSettings {
|
||||
}
|
||||
|
||||
public function getStringSetting($userId, string $key, string $default = ''): string {
|
||||
return $this->config->getUserValue(AppConstants::APP_ID, $userId, $key) ?: $default;
|
||||
return $this->config->getUserValue(AppConstants::APP_ID, $userId, $key)
|
||||
?: ($this->config->getAppValue(AppConstants::APP_ID, $userId, $key) ?: $default);
|
||||
}
|
||||
|
||||
public function setStringSetting($userId, string $key, string $value): void {
|
||||
$this->config->setUserValue(AppConstants::APP_ID, $userId, $key, $value);
|
||||
}
|
||||
|
||||
public function setAppStringSetting(string $key, string $value): void {
|
||||
$this->config->setAppValue(AppConstants::APP_ID, $key, $value);
|
||||
}
|
||||
|
||||
public function getAll($userId): array {
|
||||
return [
|
||||
AppSettings::FOLDER_VARIANT => $this->getStringSetting($userId, AppSettings::FOLDER_VARIANT, 'pride'),
|
||||
@ -27,8 +32,20 @@ class AppSettings {
|
||||
];
|
||||
}
|
||||
|
||||
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'),
|
||||
];
|
||||
}
|
||||
|
||||
public function set($userId, $folder, $button): void {
|
||||
$this->setStringSetting($userId, AppSettings::FOLDER_VARIANT, $folder);
|
||||
$this->setStringSetting($userId, AppSettings::BUTTON_VARIANT, $button);
|
||||
}
|
||||
|
||||
public function setGlobal($folder, $button): void {
|
||||
$this->setAppStringSetting(AppSettings::FOLDER_VARIANT, $folder);
|
||||
$this->setAppStringSetting(AppSettings::BUTTON_VARIANT, $button);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user