2020-10-03 19:44:09 +00:00
|
|
|
<?php
|
|
|
|
class SettingsManager{
|
|
|
|
static function getAllValues () {
|
|
|
|
return Db::loadAll ("SELECT * FROM settings");
|
|
|
|
}
|
|
|
|
|
|
|
|
static function getByName($settingName) {
|
|
|
|
return Db::loadOne("SELECT * FROM settings WHERE name = ?", array($settingName));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function create ($name, $value) {
|
|
|
|
$setting = array (
|
|
|
|
'name' => $name,
|
|
|
|
'value' => $value,
|
|
|
|
);
|
|
|
|
try {
|
|
|
|
Db::add ('settings', $setting);
|
|
|
|
} catch(PDOException $error) {
|
|
|
|
echo $error->getMessage();
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function update ($name, $value) {
|
2020-12-09 11:28:31 +00:00
|
|
|
if ($this.getByName($name)){
|
|
|
|
$this->create($name, $value);
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
Db::edit ('settings', ['value' => $value], 'WHERE name = ?', array($name));
|
|
|
|
} catch(PDOException $error) {
|
|
|
|
echo $error->getMessage();
|
|
|
|
die();
|
|
|
|
}
|
2020-10-03 19:44:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|