big restructure
This commit is contained in:
35
lib/Repository/Settings/SettingRepository.php
Normal file
35
lib/Repository/Settings/SettingRepository.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Repository\Settings;
|
||||
|
||||
use MintyPHP\DB;
|
||||
|
||||
class SettingRepository
|
||||
{
|
||||
public static function find(string $key): ?array
|
||||
{
|
||||
$row = DB::selectOne('select `key`, `value`, `description`, `updated_at` from settings where `key` = ? limit 1', $key);
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
return $row['settings'] ?? $row;
|
||||
}
|
||||
|
||||
public static function getValue(string $key): ?string
|
||||
{
|
||||
$row = self::find($key);
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
return array_key_exists('value', $row) ? (string) $row['value'] : null;
|
||||
}
|
||||
|
||||
public static function set(string $key, ?string $value, ?string $description = null): bool
|
||||
{
|
||||
$query = 'insert into settings (`key`, `value`, `description`) values (?, ?, ?) '
|
||||
. 'on duplicate key update `value` = values(`value`), '
|
||||
. '`description` = ifnull(values(`description`), `description`)';
|
||||
$result = DB::update($query, $key, $value, $description);
|
||||
return $result !== false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user