2025-07-10 11:01:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2026-03-08 14:18:28 +01:00
|
|
|
use Database\Factories\SettingFactory;
|
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
|
|
|
/**
|
2026-03-08 14:18:28 +01:00
|
|
|
* @method static updateOrCreate(array<string, string> $array, array<string, mixed> $array1)
|
|
|
|
|
* @method static create(array<string, string> $array)
|
2025-08-05 21:15:17 +02:00
|
|
|
* @method static where(string $string, string $key)
|
|
|
|
|
*/
|
2025-07-10 11:01:01 +02:00
|
|
|
class Setting extends Model
|
|
|
|
|
{
|
2026-03-08 14:18:28 +01:00
|
|
|
/** @use HasFactory<SettingFactory> */
|
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
|
|
|
|
|
{
|
2026-02-26 01:19:38 +01:00
|
|
|
return static::getBool('enable_publishing_approvals', true);
|
2025-07-10 14:57:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function setPublishingApprovalsEnabled(bool $enabled): void
|
|
|
|
|
{
|
|
|
|
|
static::setBool('enable_publishing_approvals', $enabled);
|
|
|
|
|
}
|
2026-03-08 11:25:50 +01:00
|
|
|
|
|
|
|
|
public static function getArticlePublishingInterval(): int
|
|
|
|
|
{
|
|
|
|
|
return (int) static::get('article_publishing_interval', 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function setArticlePublishingInterval(int $minutes): void
|
|
|
|
|
{
|
|
|
|
|
static::set('article_publishing_interval', (string) $minutes);
|
|
|
|
|
}
|
2025-07-10 11:01:01 +02:00
|
|
|
}
|