2020-10-03 19:44:09 +00:00
|
|
|
<?php
|
|
|
|
class SettingsManager{
|
|
|
|
static function getAllValues () {
|
|
|
|
return Db::loadAll ("SELECT * FROM settings");
|
|
|
|
}
|
|
|
|
|
2020-12-09 11:42:26 +00:00
|
|
|
static function getByName($settingName, $group = '') {
|
|
|
|
if ($group != '') return Db::loadOne("SELECT * FROM settings WHERE name = ? AND group = ?", array($settingName, $group));
|
2020-10-03 19:44:09 +00:00
|
|
|
return Db::loadOne("SELECT * FROM settings WHERE name = ?", array($settingName));
|
|
|
|
}
|
|
|
|
|
2020-12-09 11:36:57 +00:00
|
|
|
static function getSettingGroup($group) {
|
|
|
|
return Db::loadAll("SELECT * FROM settings WHERE group = ?", array($group));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function create ($name, $value, $group = '') {
|
2020-10-03 19:44:09 +00:00
|
|
|
$setting = array (
|
|
|
|
'name' => $name,
|
|
|
|
'value' => $value,
|
2020-12-09 11:36:57 +00:00
|
|
|
'group' => $group,
|
2020-10-03 19:44:09 +00:00
|
|
|
);
|
|
|
|
try {
|
|
|
|
Db::add ('settings', $setting);
|
|
|
|
} catch(PDOException $error) {
|
|
|
|
echo $error->getMessage();
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-09 11:36:57 +00:00
|
|
|
public static function update ($name, $value, $group = '') {
|
2020-12-09 11:28:31 +00:00
|
|
|
if ($this.getByName($name)){
|
2020-12-09 11:36:57 +00:00
|
|
|
$this->create($name, $value, $group);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|