Browse Source

Better settings Manager

pull/1/head
Václav Španinger 1 year ago
parent
commit
e95435a707
1 changed files with 11 additions and 4 deletions
  1. +11
    -4
      app/models/managers/SettingsManager.php

+ 11
- 4
app/models/managers/SettingsManager.php View File

@ -8,10 +8,15 @@ class SettingsManager{
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 (
'name' => $name,
'value' => $value,
'group' => $group,
);
try {
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)){
$this->create($name, $value);
$this->create($name, $value, $group);
} else {
try {
Db::edit ('settings', ['value' => $value], 'WHERE name = ?', array($name));
Db::edit ('settings', [
'value' => $value
], 'WHERE name = ?', array($name));
} catch(PDOException $error) {
echo $error->getMessage();
die();

Loading…
Cancel
Save