fedi-feed-router/app/Models/Setting.php

63 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2025-07-10 11:01:01 +02:00
<?php
namespace App\Models;
2025-08-05 21:15:17 +02:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2025-07-10 11:01:01 +02:00
use Illuminate\Database\Eloquent\Model;
2025-08-05 21:15:17 +02:00
/**
* @method static updateOrCreate(string[] $array, array $array1)
* @method static create(string[] $array)
* @method static where(string $string, string $key)
*/
2025-07-10 11:01:01 +02:00
class Setting extends Model
{
2025-08-05 21:15:17 +02:00
use HasFactory;
2025-07-10 11:01:01 +02:00
protected $fillable = ['key', 'value'];
public static function get(string $key, mixed $default = null): mixed
{
$setting = static::where('key', $key)->first();
2025-08-05 21:15:17 +02:00
2025-07-10 11:01:01 +02:00
return $setting ? $setting->value : $default;
}
public static function set(string $key, mixed $value): void
{
static::updateOrCreate(['key' => $key], ['value' => $value]);
}
public static function getBool(string $key, bool $default = false): bool
{
$value = static::get($key, $default);
2025-08-05 21:15:17 +02:00
2025-07-10 11:01:01 +02:00
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
public static function setBool(string $key, bool $value): void
{
static::set($key, $value ? '1' : '0');
}
public static function isArticleProcessingEnabled(): bool
{
return static::getBool('article_processing_enabled', true);
}
public static function setArticleProcessingEnabled(bool $enabled): void
{
static::setBool('article_processing_enabled', $enabled);
}
2025-07-10 14:57:10 +02:00
public static function isPublishingApprovalsEnabled(): bool
{
return static::getBool('enable_publishing_approvals', false);
}
public static function setPublishingApprovalsEnabled(bool $enabled): void
{
static::setBool('enable_publishing_approvals', $enabled);
}
2025-07-10 11:01:01 +02:00
}