Better settings Manager

This commit is contained in:
Václav Španinger 2020-12-09 12:36:57 +01:00
parent 74f6779c63
commit e95435a707

View File

@ -8,10 +8,15 @@ class SettingsManager{
return Db::loadOne("SELECT * FROM settings WHERE name = ?", array($settingName)); return Db::loadOne("SELECT * FROM settings WHERE name = ?", array($settingName));
} }
public static function create ($name, $value) { static function getSettingGroup($group) {
return Db::loadAll("SELECT * FROM settings WHERE group = ?", array($group));
}
public static function create ($name, $value, $group = '') {
$setting = array ( $setting = array (
'name' => $name, 'name' => $name,
'value' => $value, 'value' => $value,
'group' => $group,
); );
try { try {
Db::add ('settings', $setting); Db::add ('settings', $setting);
@ -21,12 +26,14 @@ class SettingsManager{
} }
} }
public static function update ($name, $value) { public static function update ($name, $value, $group = '') {
if ($this.getByName($name)){ if ($this.getByName($name)){
$this->create($name, $value); $this->create($name, $value, $group);
} else { } else {
try { try {
Db::edit ('settings', ['value' => $value], 'WHERE name = ?', array($name)); Db::edit ('settings', [
'value' => $value
], 'WHERE name = ?', array($name));
} catch(PDOException $error) { } catch(PDOException $error) {
echo $error->getMessage(); echo $error->getMessage();
die(); die();