Initial commit
This commit is contained in:
209
app/Services/SettingsService.php
Normal file
209
app/Services/SettingsService.php
Normal file
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\SystemSetting;
|
||||
|
||||
class SettingsService
|
||||
{
|
||||
/**
|
||||
* Check if a feature is enabled
|
||||
*
|
||||
* @param string $feature Feature key (e.g., 'qr_codes', 'tagging', 'expiration')
|
||||
* @return bool
|
||||
*/
|
||||
public function isFeatureEnabled(string $feature): bool
|
||||
{
|
||||
$key = "features.{$feature}_enabled";
|
||||
return SystemSetting::get($key, true); // Default to enabled
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rate limit for downloads
|
||||
*
|
||||
* @param bool $authenticated
|
||||
* @return int
|
||||
*/
|
||||
public function getDownloadRateLimit(bool $authenticated = false): int
|
||||
{
|
||||
$key = $authenticated ? 'security.rate_limit_authenticated' : 'security.rate_limit_guest';
|
||||
return SystemSetting::get($key, $authenticated ? 50 : 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get maximum file upload size in MB
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxFileSize(): int
|
||||
{
|
||||
return SystemSetting::get('security.max_file_size_mb', 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get allowed file types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllowedFileTypes(): array
|
||||
{
|
||||
return SystemSetting::get('security.allowed_file_types', [
|
||||
'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'jpg', 'jpeg', 'png'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default expiration days for documents
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getDefaultExpirationDays(): ?int
|
||||
{
|
||||
return SystemSetting::get('documents.default_expiration_days', null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expiration warning threshold in days
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getExpirationWarningDays(): int
|
||||
{
|
||||
return SystemSetting::get('documents.expiration_warning_days', 30);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if auto-archive on expiry is enabled globally
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAutoArchiveEnabled(): bool
|
||||
{
|
||||
return SystemSetting::get('documents.auto_archive_enabled', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get QR code default size
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getQRCodeSize(): int
|
||||
{
|
||||
return SystemSetting::get('advanced.qr_code_size', 300);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get QR code format
|
||||
*
|
||||
* @return string 'png' or 'svg'
|
||||
*/
|
||||
public function getQRCodeFormat(): string
|
||||
{
|
||||
return SystemSetting::get('advanced.qr_code_format', 'png');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default access level for new documents
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultAccessLevel(): string
|
||||
{
|
||||
return SystemSetting::get('documents.default_access_level', 'members');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if notifications are enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function areNotificationsEnabled(): bool
|
||||
{
|
||||
return SystemSetting::get('notifications.enabled', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notification recipients for expiration alerts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExpirationNotificationRecipients(): array
|
||||
{
|
||||
return SystemSetting::get('notifications.expiration_recipients', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get statistics default time range
|
||||
*
|
||||
* @return int Days
|
||||
*/
|
||||
public function getStatisticsTimeRange(): int
|
||||
{
|
||||
return SystemSetting::get('advanced.statistics_time_range', 30);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get top N items for statistics
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getStatisticsTopN(): int
|
||||
{
|
||||
return SystemSetting::get('advanced.statistics_top_n', 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get audit log retention period in days
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAuditLogRetentionDays(): int
|
||||
{
|
||||
return SystemSetting::get('advanced.audit_log_retention_days', 365);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get maximum versions to retain per document
|
||||
*
|
||||
* @return int|null Null = unlimited
|
||||
*/
|
||||
public function getMaxVersionsToRetain(): ?int
|
||||
{
|
||||
return SystemSetting::get('advanced.max_versions_retain', null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a setting value by key
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(string $key, $default = null)
|
||||
{
|
||||
return SystemSetting::get($key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a setting value
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param string $type
|
||||
* @return SystemSetting
|
||||
*/
|
||||
public function set(string $key, $value, string $type = 'string'): SystemSetting
|
||||
{
|
||||
return SystemSetting::set($key, $value, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all settings grouped
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getAllGrouped()
|
||||
{
|
||||
return SystemSetting::getAllGrouped();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user