2020-10-03 19:44:09 +00:00
|
|
|
<?php
|
|
|
|
class SettingsManager{
|
|
|
|
static function getAllValues () {
|
|
|
|
return Db::loadAll ("SELECT * FROM settings");
|
|
|
|
}
|
|
|
|
|
2020-12-09 13:30:41 +00:00
|
|
|
static function getByName($settingName, $type = '') {
|
|
|
|
if ($type != '') return Db::loadOne("SELECT * FROM settings WHERE name = ? AND type = ?", array($settingName, $type));
|
2020-10-03 19:44:09 +00:00
|
|
|
return Db::loadOne("SELECT * FROM settings WHERE name = ?", array($settingName));
|
|
|
|
}
|
|
|
|
|
2020-12-09 13:30:41 +00:00
|
|
|
static function getSettingGroup($type) {
|
|
|
|
return Db::loadAll("SELECT * FROM settings WHERE type=?", array($type));
|
2020-12-09 11:36:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 13:30:41 +00:00
|
|
|
public static function create ($name, $value, $type = '') {
|
2021-02-15 13:18:44 +00:00
|
|
|
//if (!self::getByName($name)){
|
2020-12-23 14:57:12 +00:00
|
|
|
$setting = array (
|
|
|
|
'name' => $name,
|
|
|
|
'value' => $value,
|
|
|
|
'type' => $type,
|
|
|
|
);
|
|
|
|
try {
|
|
|
|
Db::add ('settings', $setting);
|
|
|
|
} catch(PDOException $error) {
|
|
|
|
echo $error->getMessage();
|
|
|
|
die();
|
|
|
|
}
|
2021-02-15 13:18:44 +00:00
|
|
|
//}
|
2020-10-03 19:44:09 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 13:30:41 +00:00
|
|
|
public static function update ($name, $value, $type = '') {
|
2020-12-23 14:57:12 +00:00
|
|
|
if (!self::getByName($name)){
|
2020-12-09 13:30:41 +00:00
|
|
|
self::create($name, $value, $type);
|
2020-12-09 11:28:31 +00:00
|
|
|
} else {
|
|
|
|
try {
|
2020-12-09 11:36:57 +00:00
|
|
|
Db::edit ('settings', [
|
|
|
|
'value' => $value
|
|
|
|
], 'WHERE name = ?', array($name));
|
2020-12-09 11:28:31 +00:00
|
|
|
} catch(PDOException $error) {
|
|
|
|
echo $error->getMessage();
|
|
|
|
die();
|
|
|
|
}
|
2020-10-03 19:44:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|