Files

159 lines
4.5 KiB
PHP
Raw Permalink Normal View History

2026-05-26 08:14:29 +02:00
<?php
2026-06-03 11:18:20 +02:00
declare(strict_types=1);
2026-05-26 08:14:29 +02:00
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
2026-06-08 20:10:33 +02:00
use Illuminate\Support\Facades\File;
2026-06-03 11:18:20 +02:00
use Illuminate\Support\Facades\Schema;
2026-06-08 20:10:33 +02:00
use Illuminate\Support\Facades\Storage;
2026-05-26 08:14:29 +02:00
class AppSetting extends Model
{
protected $table = 'app_settings';
protected $fillable = [
2026-06-03 11:18:20 +02:00
'logo', 'logo_small', 'logo_path', 'logo_small_path',
'nome_applicazione', 'nome_organizzazione',
'footer_text', 'app_version', 'dashboard_welcome', 'show_version',
'backup_path', 'backup_retention_days', 'backup_include_files',
'backup_include_env', 'backup_auto_enabled', 'backup_auto_frequency', 'backup_auto_hour',
'documenti_storage_disk', 'documenti_storage_path',
2026-05-26 08:14:29 +02:00
];
2026-06-01 22:55:50 +02:00
protected function casts(): array
{
return [
'backup_retention_days' => 'integer',
'backup_include_files' => 'boolean',
'backup_include_env' => 'boolean',
'backup_auto_enabled' => 'boolean',
'backup_auto_hour' => 'integer',
2026-06-03 11:18:20 +02:00
'show_version' => 'boolean',
2026-06-01 22:55:50 +02:00
];
}
2026-06-03 11:18:20 +02:00
public static function getSetting(string $key, mixed $default = null): mixed
2026-05-26 08:14:29 +02:00
{
2026-06-03 11:18:20 +02:00
if (!Schema::hasTable('app_settings')) {
return $default;
}
2026-05-26 08:14:29 +02:00
$setting = self::first();
return $setting?->{$key} ?? $default;
}
public static function getLogo(): ?string
{
return self::getSetting('logo');
}
public static function getLogoSmall(): ?string
{
return self::getSetting('logo_small');
}
public static function getAppName(): string
{
return self::getSetting('nome_applicazione', 'Glastree');
}
public static function getOrgName(): string
{
return self::getSetting('nome_organizzazione', 'Parrocchia');
}
public static function getFooterText(): string
{
$footer = self::getSetting('footer_text');
if ($footer) {
return $footer;
}
$appName = self::getAppName();
$year = date('Y');
return "© {$year} {$appName}";
}
public static function getAppVersion(): ?string
{
return self::getSetting('app_version');
}
public static function getDashboardWelcome(): ?string
{
return self::getSetting('dashboard_welcome');
}
public static function shouldShowVersion(): bool
{
return (bool) self::getSetting('show_version', false);
}
2026-05-28 09:34:28 +02:00
public static function getDocumentiStorageDisk(): string
{
return self::getSetting('documenti_storage_disk', 'local');
}
public static function getDocumentiStoragePath(): string
{
return self::getSetting('documenti_storage_path', 'documenti');
}
public static function getDocumentiStorageAbsolutePath(): string
{
$disk = self::getDocumentiStorageDisk();
$path = self::getDocumentiStoragePath();
return storage_path('app/' . ($disk === 'local' ? 'private/' : '') . $path);
}
2026-05-26 08:14:29 +02:00
public function getLogoUrlInstance(): ?string
{
2026-06-08 20:10:33 +02:00
if ($this->logo && Storage::disk('public')->exists($this->logo)) {
return Storage::disk('public')->url($this->logo);
2026-05-26 08:14:29 +02:00
}
return null;
}
public function getLogoSmallUrlInstance(): ?string
{
2026-06-08 20:10:33 +02:00
if ($this->logo_small && Storage::disk('public')->exists($this->logo_small)) {
return Storage::disk('public')->url($this->logo_small);
2026-05-26 08:14:29 +02:00
}
return null;
}
public function getLogoPath(): ?string
{
2026-06-08 20:10:33 +02:00
if ($this->logo_path && Storage::disk('public')->exists($this->logo_path)) {
return Storage::disk('public')->url($this->logo_path);
2026-05-26 08:14:29 +02:00
}
2026-06-08 20:10:33 +02:00
if ($this->logo && Storage::disk('public')->exists($this->logo)) {
return Storage::disk('public')->url($this->logo);
2026-05-26 08:14:29 +02:00
}
return null;
}
public function getLogoSmallPath(): ?string
{
2026-06-08 20:10:33 +02:00
if ($this->logo_small_path && Storage::disk('public')->exists($this->logo_small_path)) {
return Storage::disk('public')->url($this->logo_small_path);
2026-05-26 08:14:29 +02:00
}
2026-06-08 20:10:33 +02:00
if ($this->logo_small && Storage::disk('public')->exists($this->logo_small)) {
return Storage::disk('public')->url($this->logo_small);
2026-05-26 08:14:29 +02:00
}
return null;
}
public static function getLogoUrl(): ?string
{
$setting = self::first();
return $setting?->getLogoPath();
}
public static function getLogoSmallUrl(): ?string
{
$setting = self::first();
return $setting?->getLogoSmallPath();
}
}