PHP_SMART_HOME_V3/app/models/managers/SettingsManager.php

46 lines
1.1 KiB
PHP
Raw Normal View History

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 = '') {
2020-10-03 19:44:09 +00:00
$setting = array (
'name' => $name,
'value' => $value,
2020-12-09 13:30:41 +00:00
'type' => $type,
2020-10-03 19:44:09 +00:00
);
try {
Db::add ('settings', $setting);
} catch(PDOException $error) {
echo $error->getMessage();
die();
}
}
2020-12-09 13:30:41 +00:00
public static function update ($name, $value, $type = '') {
if (self::getByName($name)){
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
}
}
}
?>